There are several problems with using A::is_odd(int) as a unary predicate, especially when you need to use it with std::not1() :
A::is_odd(int) call to A::is_odd(int) takes two arguments: an implicit object (" this ") and a visible int argument.- It is not a function object that defines
argument_type and result_type .
Proper use of this member function as a unary predicate requires two steps:
- Adaptation of a member function pointer is a suitable function object, for example, using one of the functions
std::mem_*fun . - Binding the first argument to a suitable object with a compiler other than C ++ 11, possibly using
std::bind1st() .
Using the C ++ 11 compiler is much simpler because std::bind() will take care of all of these. Assuming it is used from member A :
... std::not1(std::bind(&A::is_odd, this, std::placeholders::_1)) ...
The same thing with the pre-C ++ 11 compiler is somewhat more complicated. Usage in std::remove_if() will look something like this:
v2.erase( std::remove_if(v2.begin(), v2.end(), std::not1(std::bind1st(std::mem_fun(&A::is_odd), this))), v2.end());
Dietmar KΓΌhl
source share