18 Concepts library [concepts]

18.7 Callable concepts [concepts.callable]

18.7.1 General [concepts.callable.general]

The concepts in subclause [concepts.callable] describe the requirements on function objects ([function.objects]) and their arguments.

18.7.2 Concept invocable [concept.invocable]

The invocable concept specifies a relationship between a callable type ([func.def]) F and a set of argument types Args... which can be evaluated by the library function invoke ([func.invoke]).
template<class F, class... Args> concept invocable = requires(F&& f, Args&&... args) { invoke(std::forward<F>(f), std::forward<Args>(args)...); // not required to be equality-preserving };
[Example
:
A function that generates random numbers can model invocable, since the invoke function call expression is not required to be equality-preserving ([concepts.equality]).
— end example
]

18.7.3 Concept regular_­invocable [concept.regularinvocable]

template<class F, class... Args> concept regular_­invocable = invocable<F, Args...>;
The invoke function call expression shall be equality-preserving ([concepts.equality]) and shall not modify the function object or the arguments.
[Note
:
This requirement supersedes the annotation in the definition of invocable.
— end note
]
[Example
:
A random number generator does not model regular_­invocable.
— end example
]
[Note
:
The distinction between invocable and regular_­invocable is purely semantic.
— end note
]

18.7.4 Concept predicate [concept.predicate]

template<class F, class... Args> concept predicate = regular_­invocable<F, Args...> && boolean-testable<invoke_result_t<F, Args...>>;

18.7.5 Concept relation [concept.relation]

template<class R, class T, class U> concept relation = predicate<R, T, T> && predicate<R, U, U> && predicate<R, T, U> && predicate<R, U, T>;

18.7.6 Concept equivalence_­relation [concept.equiv]

template<class R, class T, class U> concept equivalence_­relation = relation<R, T, U>;
A relation models equivalence_­relation only if it imposes an equivalence relation on its arguments.

18.7.7 Concept strict_­weak_­order [concept.strictweakorder]

template<class R, class T, class U> concept strict_­weak_­order = relation<R, T, U>;
A relation models strict_­weak_­order only if it imposes a strict weak ordering on its arguments.
The term strict refers to the requirement of an irreflexive relation (!comp(x, x) for all x), and the term weak to requirements that are not as strong as those for a total ordering, but stronger than those for a partial ordering.
If we define equiv(a, b) as !comp(a, b) && !comp(b, a), then the requirements are that comp and equiv both be transitive relations:
  • comp(a, b) && comp(b, c) implies comp(a, c)
  • equiv(a, b) && equiv(b, c) implies equiv(a, c)
[Note
:
Under these conditions, it can be shown that
  • equiv is an equivalence relation,
  • comp induces a well-defined relation on the equivalence classes determined by equiv, and
  • the induced relation is a strict total ordering.
— end note
]