How passing arguments using std::mem_fun
Use std::bind
via std::bind1st
and std::bind2nd
std::for_each(list.begin(), list.end(),
std::bind2nd(std::mem_fun(&Interface::do_something),1) // because 1st is this
);
Unfortunately, the standard does not help for the two arguments version and you need to write your own:
struct MyFunctor
{
void (Interface::*func)(int,int);
int a;
int b;
MyFunctor(void (Interface::*f)(int,int), int a, int b): func(f), a(a), b(b) {}
void operator()(Interface* i){ (i->*func)(a,b);}
};
std::for_each(list.begin(), list.end(),
MyFunctor(&Interface::do_func, 1, 2)
);
Lambda version
The original answer was good back in 2012 when Lambda's had just been added to the standard and few compilers were C++11 compliant yet. Now 8 years later most compilers are C++11 compliant and we can use this to make these things much simpler.
// Binding 1 parameter
std::for_each(list.begin(), list.end(),
[](auto act){act->do_something(1);})
// Binding 2 parameters
std::for_each(list.begin(), list.end(),
[](auto act){act->do_func(1, 2);})