You can use std::not1 . Unfortunately, std::not1 requires a function object argument with nested types argument_type and result_type . That is, it cannot be used directly. Instead, you must combine use with std::ptr_fun when using a std::ptr_fun with a normal function:
v2.erase( std::remove_if(v2.begin(), v2.end(), std::not1(std::ptr_fun(is_odd))), v2.end() );
At the last committee meeting, std::not_fn was moved from the TS 2 Fundamentals Library to a working draft. That is, there is hope that with C ++ 17 there is a better suggestion for a common negator.
In general, the fun stops when you need to use any of the functions std::*_fun . As others have pointed out, it is advisable to use a lambda instead:
v2.erase( std::remove_if(v2.begin(), v2.end(), [](auto&& x){ return !::is_odd(x); }), v2.end() );
Using a lambda function or function object with an inline function call operator also has the advantage that the compiler has an easier time pasting the code.
Obviously, if you need to use C ++ before C ++ 11, then the std::not1 / std::ptr_fun is the easiest to use immediately, using a lambda function is not even possible. In this case, you may need to create a simple function object to support the attachment:
struct not_odd { template <typename T> bool operator()(T const& value) const { return !::odd(value); } };
source share