Calling
std::count_if(vec.begin(), vec.end(), std::bind2nd(std::ptr_fun(foo), 17))
works fine with
bool foo(int, int),
but I can’t make it work with
bool foo(const int &, const int &)
Is there a way to make that work or do I have to write my own adaptor function?
The second argument is a number, and cannot be converted to
const int &.You can use
boost::bindto do the trick:EDIT:
As of my first response, yes, you cannot use a variable instead of the number. I think the problem is
bind2ndandptr_funnot being properly defined to dereference the type in the case it is a reference whenptr_funbuilds the internalOperationobject, so ither go with boost or write your own functor class.