Boost logo

Boost Users :

From: Scott Lamb (slamb_at_[hidden])
Date: 2004-05-27 01:23:37


On 26 May 2004, at 11:48 PM, Vesselin Kostadinov wrote:
> //using the right combination of for_each, bind, ref, mem_fn, etc:
> // std::for_each(foos.begin(), foos.end(),
> // boost::bind(???????),
> // _1, boost::ref(param));
> }
>

Hmm, I don't know if you could do that directly. If you added a
function to foo like such:

     void call_func_ptr(int &x) { this->func_ptr(x); }

then you could do:

     std::for_each(foos.begin(), foos.end(),
boost::bind(&foo::call_func_ptr, _1, boost::ref(param));

You definitely want the _1 as a parameter to boost::bind, not
std::for_each. Every argument (including the "this" pointer) should be
mentioned in the bind, even if only to provide the placeholder.

Scott


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