|
|
|
|
| |
| Categories: functors, adaptors | Component type: type |
Description
Unary_negate is a functors adaptor: it is an AdaptablePredicate that represents the logical negation of some other AdaptablePredicate. That is: if f is an object of class unary_negate<AdaptablePredicate>, then there exists an object pred of class AdaptablePredicate such that f(x) always returns the same value as !pred(x). [1] There is rarely any reason to construct a unary_negate directly; it is almost always easier to use the helper function not1.
Example
Finds the first element in a list that does not lie in the range from 1 to 10.
List<int> L;
...
List<int>::iterator in_range =
find_if(L.begin(), L.end(),
not1(compose2(logical_and<bool>(),
bind2nd(greater_equal<int>(), 1),
bind2nd(less_equal<int>(), 10))));
assert(in_range == L.end() || !(*in_range >= 1 && *in_range <= 10));
Definition
Defined in the standard header functional, and in the nonstandard backward-compatibility header function.h.
Template parameters
| Parameter | Description | Default |
AdaptablePredicate | The type of the function object that this unary_negate is the logical negation of. | |
Model of
AdaptablePredicate
Type requirements
AdaptablePredicate must be a model of AdaptablePredicate.
Public base classes
unary_function<AdaptablePredicate::argument_type, bool>
Members
| Member | Where defined | Description |
argument_type | AdaptableUnaryFunction | The type of the argument: AdaptablePredicate::argument_type |
result_type | AdaptableUnaryFunction | The type of the result: bool |
bool operator()(argument_type) | UnaryFunction | Function call operator. |
unary_negate(const AdaptablePredicate& pred)
| unary_negate | See below. |
template <class AdaptablePredicate>
unary_negate<AdaptablePredicate>
not1(const AdaptablePredicate& pred);
| unary_negate | See below. |
New members
These members are not defined in the AdaptablePredicate requirements, but are specific to unary_negate.
| Member | Description |
unary_negate(const AdaptablePredicate& pred)
| The constructor. Creates a unary_negate<AdaptablePredicate> whose underlying predicate is pred. |
template <class AdaptablePredicate>
unary_negate<AdaptablePredicate>
not1(const AdaptablePredicate& pred);
| If p is of type AdaptablePredicate then not1(p) is equivalent to unary_negate<AdaptablePredicate>(p), but more convenient. This is a global function, not a member function. |
Notes
[1] Strictly speaking, unary_negate is redundant. It can be constructed using the function object logical_not and the adaptor unary_compose.
See also
The functors, AdaptablePredicate, Predicate, binary_negate, unary_compose, binary_compose