$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
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