Boost logo

Boost Users :

From: Michiel Helvensteijn (m.helvensteijn_at_[hidden])
Date: 2008-07-17 08:52:02


Igor R wrote:

> std::vector<boost::function<void(void)> > functors;
> using namespace boost::lambda;
> std::for_each (functors.begin(), functor.end(), _1);
>
> The above compiles, but...does nothing. How can I enforce calling of
> operator () ?

You're just taking the expression (of function type) each time and doing
nothing with it. You need to make the call. The following does NOT seem to
work, and I'm not sure why:

for_each (functors.begin(), functors.end(), _1());

But the following does work:

void call(function<void ()> f) { f(); }
...
for_each (functors.begin(), functors.end(), call);

There may be a better way, but this might do until you find it.

-- 
Michiel Helvensteijn

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