
17 Jul
2008
17 Jul
'08
12:52 p.m.
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