C ++ 03 Solution (no increase):
Write another functor as:
struct TwoArgFunctor
{
int arg1, arg2;
TwoArgFunctor(int a, int b) :arg1(a), arg2(b) {}
template<typename Functor>
bool operator()(Functor fun)
{
return fun(arg1, arg2);
}
};
Then use it like:
std::for_each(funktors.begin(),funktors.end(), TwoArgFunctor(arg1,arg2));
C ++ 11 Solution:
std::for_each(funktors.begin(),funktors.end(),
[&] (Funktor f) -> bool { return f(arg1,arg2); });
Nawaz source
share