Use of a member pointer to a member function in for_each - is it possible?
Hi,
I am struggling to find the proper combination of ataptors/binders to use a
member pointer to a member function in a for_each. Is this possible at all?
Any help is appreciated.
Here is the code:
#include <iostream>
#include <algorithm>
#include <vector>
#include
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
participants (2)
-
Scott Lamb
-
Vesselin Kostadinov