
Yes it does compile, but it doesn't do anything. I'm looking for it to print out the numbers. I need the callback to be called. --- Aaron Wright From: Igor R <boost.lists@gmail.com> To: boost-users@lists.boost.org Date: 04/30/2013 10:04 AM Subject: Re: [Boost-users] [phoenix] - std::for_each - How to call member variable that is a boost::function? Sent by: "Boost-users" <boost-users-bounces@lists.boost.org>
namespace bp = boost::phoenix; namespace bpa = bp::arg_names;
struct Foo { boost::function< void() > callback;
Foo(boost::function< void() > const& callback) : callback(callback) { } };
main() { std::list< Foo > foos;
foos.push_back(Foo(std::cout << bp::val(1) << '\n')); foos.push_back(Foo(std::cout << bp::val(2) << '\n')); foos.push_back(Foo(std::cout << bp::val(3) << '\n'));
std::for_each( foos.begin(), foos.end(), bp::bind(&Foo::callback, bpa::arg1)); }
If I wrap the bind(...) in another bind(...) it'll work, but is that the right way? I'm not binding anything, I just want the callback called.
FWIW, the following code compiles in MSVC10 with boost 1.53 (basically, your code in form of sscce): #include <boost/phoenix.hpp> #include <iostream> #include <boost/function.hpp> #include <list> namespace bp = boost::phoenix; namespace bpa = bp::arg_names; struct Foo { boost::function< void() > callback; Foo(boost::function< void() > const& callback) : callback(callback) { } }; int main() { std::list< Foo > foos; foos.push_back(Foo(std::cout << bp::val(1) << '\n')); foos.push_back(Foo(std::cout << bp::val(2) << '\n')); foos.push_back(Foo(std::cout << bp::val(3) << '\n')); std::for_each( foos.begin(), foos.end(), bp::bind(&Foo::callback, bpa::arg1)); } _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users