I see std::plus<T>, but where is std::assign<T>

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jabbah
    New Member
    • Nov 2007
    • 63

    #1

    I see std::plus<T>, but where is std::assign<T>

    hi,

    i find a std::plus<T> but what if i just want to assign all elements in my container a certain value. Im thinking of something along the lines of

    Code:
    std::list<double> List;
    std::for_each( 
      List.begin(), 
      List.end(), 
      std::bind2nd( std::assign<double>(), 0.0 )
    );
    but obviously there is no such thing as std::assign<T>

    any tips?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Nothing prevents you from coding your own assing<T> adapable functor.

    Or you could write an iterator for your List and use transform<>.
    Last edited by weaknessforcats; Nov 29 '10, 04:14 PM. Reason: fix typo

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      You can just use std::fill

      Comment

      • jabbah
        New Member
        • Nov 2007
        • 63

        #4
        yes, i could write my own. i was just wondering why there is none and whether i should take that as an indicator to look for another "stl way" of proceeding.

        using transform, i would end up with
        Code:
        transform( 
          List.begin(), 
          List.end(), 
          std::bind2nd( std::assign<double>(), 0.0 )
        );
        wouldnt i?

        ahh std::fill didnt see that.

        thanks to you both.

        Comment

        Working...