By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

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

P: 63

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

Expand|Select|Wrap|Line Numbers
  1. std::list<double> List;
  2. std::for_each( 
  3.   List.begin(), 
  4.   List.end(), 
  5.   std::bind2nd( std::assign<double>(), 0.0 )
  6. );
but obviously there is no such thing as std::assign<T>

any tips?
Nov 29 '10 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 9,197
Nothing prevents you from coding your own assing<T> adapable functor.

Or you could write an iterator for your List and use transform<>.
Nov 29 '10 #2

Expert Mod 5K+
P: 8,916
You can just use std::fill
Nov 29 '10 #3

P: 63
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
Expand|Select|Wrap|Line Numbers
  1. transform( 
  2.   List.begin(), 
  3.   List.end(), 
  4.   std::bind2nd( std::assign<double>(), 0.0 )
  5. );
wouldnt i?

ahh std::fill didnt see that.

thanks to you both.
Nov 30 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.