Boost logo

Boost :

From: Maxim Yegorushkin (e-maxim_at_[hidden])
Date: 2005-06-22 02:02:01


On Wed, 22 Jun 2005 06:30:43 +0400, Falcon <boost_at_[hidden]>
wrote:

> Sorry if this has been asked before (I couldn't find anything, or else I
> wasn't using the right searches)... How does one create a lambda
> function that invokes its parameter? For example, for use with
> std::for_each:
>
> std::vector<boost::function0<void> > Methods;
> std::for_each(Methods.begin(), Methods.end(), *???*)

Probably like this:

#include <vector>
#include <algorithm>

#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/bind/apply.hpp>

int main()
{
     std::vector<boost::function0<void> > Methods;
     std::for_each(Methods.begin(), Methods.end(),
boost::bind(boost::apply<void>(), _1));
}

-- 
Maxim Yegorushkin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk