C++ named requirements: Predicate

From cppreference.com
< cpp‎ | named req
C++ named requirements

The Predicate requirements describe a callable that returns a BooleanTestable

Predicate

  • std::find_if Take sequence of elements, and a predicate. Return first element in the sequence, for which predicate returns value equal to true

Description of algorithm facilities, given above, is crude and intended to explain Predicate

In other words, if an algorithm takes a Predicate pred and an iterator first, it should be able to test the object of the type pointed to by the iterator first using the given predicate via a construct like if (pred( *first) ) { /*...*/ }

The function object pred shall not apply any non-constant function through the dereferenced iterator and must accept a const argument, with the same behavior regardless of whether the argument is const or non-const

Requirements

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 insufficent requirements strengthened

See also

(C++20)
specifies that a callable type is a Boolean predicate
(concept)