Namespaces
Variants

C++ named requirements: Predicate

From cppreference.com
 
 
C++ named requirements
 

Certain standard library functions take a Predicate parameter, called with elements of a corresponding iterator.

Given Predicate pred and corresponding iterator it, let elem designate the object *it, it is required that:

  • pred is a FunctionObject
  • pred does not apply a non-constant function on its argument
  • pred returns a BooleanTestable value
  • pred(elem) is valid and equal to pred(*it), regardless of whether elem is const or not, regardless of whether elem is an lvalue or xvalue(since C++11)

The most straight-forward way of achieving that last requirement is for pred to take its parameter by const lvalue reference. pred may take its parameter by value only if construction doesn't modify the source object; namely, if pred's parameter and *it both have type T, then T must not have move semantics.

Standard library

The following standard library functions take a Predicate parameter.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 3031 C++98 requirements on const values were insufficient requirements strengthened

See also

BinaryPredicate
(C++20)
specifies that a callable type is a Boolean predicate
(concept) [edit]