unary_negate is generally used as a type. The function not1 (also defined in header <functional>) can be used to directly construct an object of this type.
unary_negate is constructed using an unary function object as argument. A copy of this object is used by its member operator() to return true whenever the original object would return false, and false whenever the object would return true, inverting its behavior.
This class is derived from unary_function and is defined as:
| 1 2 3 4 5 6 7 8 9 10 |
|
unary_negate class is specifically designed to negate function objects (predicates) derived from unary_function (it requires an argument_type member).
Members
- constructor
- Constructs an object with the opposite behavior than the object passed as its argument.
- operator()
- Member function returning the opposite of the function object with which the object was constructed.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Output:
There are 2 elements with even values. |
See also
| not1 | Return negation of unary function object (function template) |
| binary_negate | Generate negation of binary function object class (class template) |
| unary_function | Unary function object base class (class template) |
