4 Jul
2003
4 Jul
'03
4:57 p.m.
In our last exciting episode "Matt Hurd" wrote:
Not sure how to force a for_each with a lambda to invoke the random function object successively. In the for_each version below get_long is called just once. Not sure how to use var, std_function, bind or something else to overcome this. I'm sure the answer is straight forward... anyone?
for_each(v.begin(),v.end(), _1 = gen_long() );
Here, gen_long() is invoked and the resulting value is stored in the lambda functor, which is passed to for_each. You need to delay the call of gen_long with bind: for_each(v.begin(), v.end(), _1 = bind(gen_long)); Jaakko