libstdc++
Collaboration diagram for Negators:

Classes

class  std::binary_negate< _Predicate >
 
class  std::unary_negate< _Predicate >
 

Functions

template<typename _Predicate >
constexpr unary_negate< _Predicate > std::not1 (const _Predicate &__pred)
 
template<typename _Predicate >
constexpr binary_negate< _Predicate > std::not2 (const _Predicate &__pred)
 

Detailed Description

The function templates not1 and not2 are function object adaptors, which each take a predicate functor and wrap it in an instance of unary_negate or binary_negate, respectively. Those classes are functors whose operator() evaluates the wrapped predicate function and then returns the negation of the result.

For example, given a vector of integers and a trivial predicate,

struct IntGreaterThanThree
: public std::unary_function<int, bool>
{
bool operator() (int x) const { return x > 3; }
};
std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
constexpr unary_negate< _Predicate > not1(const _Predicate &__pred)
One of the negation functors.

The call to find_if will locate the first index (i) of v for which !(v[i] > 3) is true.

The not1/unary_negate combination works on predicates taking a single argument. The not2/binary_negate combination works on predicates taking two arguments.

Deprecated:
Deprecated in C++17, no longer in the standard since C++20. Use not_fn instead.

Function Documentation

◆ not1()

template<typename _Predicate >
constexpr unary_negate< _Predicate > std::not1 ( const _Predicate &  __pred)
inlineconstexpr

One of the negation functors.

Definition at line 1043 of file stl_function.h.

◆ not2()

template<typename _Predicate >
constexpr binary_negate< _Predicate > std::not2 ( const _Predicate &  __pred)
inlineconstexpr

One of the negation functors.

Definition at line 1072 of file stl_function.h.