|
Boost Users : |
From: Jaakko Jarvi (jajarvi_at_[hidden])
Date: 2003-07-04 11:57:26
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net