|
Boost Users : |
From: Vladimir Prus (yg-boost-users_at_[hidden])
Date: 2003-04-23 05:21:14
Hi Russell,
Russell Hind wrote:
> I have a std::list of boost::function0<void> I would like to call all
> items using a for_each statement. Is there a standard function object
> that I can pass into the for_each call that will call operator() on each
> element?
Yes, std::mem_fun_ref. Complete example tested with g++ 3.2 is at the end.
HTH,
Volodya
#include <boost/function.hpp>
using namespace boost;
#include <vector>
#include <functional>
#include <iostream>
#include <algorithm>
using namespace std;
void foo()
{
cout << "foo\n";
}
int main()
{
vector<function0<void> > v;
v.push_back(foo);
for_each(v.begin(), v.end(), mem_fun_ref(&function0<void>::operator()));
return 0;
}
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