Init
This commit is contained in:
180
cppdraft/concepts/callable.md
Normal file
180
cppdraft/concepts/callable.md
Normal file
@@ -0,0 +1,180 @@
|
||||
[concepts.callable]
|
||||
|
||||
# 18 Concepts library [[concepts]](./#concepts)
|
||||
|
||||
## 18.7 Callable concepts [concepts.callable]
|
||||
|
||||
### [18.7.1](#general) General [[concepts.callable.general]](concepts.callable.general)
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1209)
|
||||
|
||||
The concepts in [concepts.callable] describe the requirements on function
|
||||
objects ([[function.objects]](function.objects "22.10 Function objects")) and their arguments[.](#general-1.sentence-1)
|
||||
|
||||
### [18.7.2](#concept.invocable) Concept invocable [[concept.invocable]](concept.invocable)
|
||||
|
||||
[1](#concept.invocable-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1215)
|
||||
|
||||
The [invocable](#concept:invocable "18.7.2 Concept invocable [concept.invocable]") concept specifies a relationship between a callable
|
||||
type ([[func.def]](func.def "22.10.3 Definitions")) F and a set of argument types Args... which
|
||||
can be evaluated by the library function invoke ([[func.invoke]](func.invoke "22.10.5 invoke functions"))[.](#concept.invocable-1.sentence-1)
|
||||
|
||||
[ð](#concept:invocable)
|
||||
|
||||
`template<class F, class... Args>
|
||||
concept [invocable](#concept:invocable "18.7.2 Concept invocable [concept.invocable]") = requires(F&& f, Args&&... args) {
|
||||
invoke(std::forward<F>(f), std::forward<Args>(args)...); // not required to be equality-preserving
|
||||
};
|
||||
`
|
||||
|
||||
[2](#concept.invocable-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1228)
|
||||
|
||||
[*Example [1](#concept.invocable-example-1)*:
|
||||
|
||||
A function that generates random numbers can model [invocable](#concept:invocable "18.7.2 Concept invocable [concept.invocable]"),
|
||||
since the invoke function call expression is not required to be
|
||||
equality-preserving ([[concepts.equality]](concepts.equality "18.2 Equality preservation"))[.](#concept.invocable-2.sentence-1)
|
||||
|
||||
â *end example*]
|
||||
|
||||
### [18.7.3](#concept.regularinvocable) Concept regular_invocable [[concept.regularinvocable]](concept.regularinvocable)
|
||||
|
||||
[ð](#concept:regular_invocable)
|
||||
|
||||
`template<class F, class... Args>
|
||||
concept [regular_invocable](#concept:regular_invocable "18.7.3 Concept regular_invocable [concept.regularinvocable]") = [invocable](#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<F, Args...>;
|
||||
`
|
||||
|
||||
[1](#concept.regularinvocable-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1244)
|
||||
|
||||
The invoke function call expression shall be
|
||||
equality-preserving ([[concepts.equality]](concepts.equality "18.2 Equality preservation")) and
|
||||
shall not modify the function object or the arguments[.](#concept.regularinvocable-1.sentence-1)
|
||||
|
||||
[*Note [1](#concept.regularinvocable-note-1)*:
|
||||
|
||||
This requirement supersedes the annotation in the definition of[invocable](#concept:invocable "18.7.2 Concept invocable [concept.invocable]")[.](#concept.regularinvocable-1.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#concept.regularinvocable-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1253)
|
||||
|
||||
[*Example [1](#concept.regularinvocable-example-1)*:
|
||||
|
||||
A random number generator does not model [regular_invocable](#concept:regular_invocable "18.7.3 Concept regular_invocable [concept.regularinvocable]")[.](#concept.regularinvocable-2.sentence-1)
|
||||
|
||||
â *end example*]
|
||||
|
||||
[3](#concept.regularinvocable-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1258)
|
||||
|
||||
[*Note [2](#concept.regularinvocable-note-2)*:
|
||||
|
||||
The distinction between [invocable](#concept:invocable "18.7.2 Concept invocable [concept.invocable]") and [regular_invocable](#concept:regular_invocable "18.7.3 Concept regular_invocable [concept.regularinvocable]") is purely semantic[.](#concept.regularinvocable-3.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
### [18.7.4](#concept.predicate) Concept predicate [[concept.predicate]](concept.predicate)
|
||||
|
||||
[ð](#concept:predicate)
|
||||
|
||||
`template<class F, class... Args>
|
||||
concept [predicate](#concept:predicate "18.7.4 Concept predicate [concept.predicate]") =
|
||||
[regular_invocable](#concept:regular_invocable "18.7.3 Concept regular_invocable [concept.regularinvocable]")<F, Args...> && [boolean-testable](concept.booleantestable#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]")<invoke_result_t<F, Args...>>;
|
||||
`
|
||||
|
||||
### [18.7.5](#concept.relation) Concept relation [[concept.relation]](concept.relation)
|
||||
|
||||
[ð](#concept:relation)
|
||||
|
||||
`template<class R, class T, class U>
|
||||
concept [relation](#concept:relation "18.7.5 Concept relation [concept.relation]") =
|
||||
[predicate](#concept:predicate "18.7.4 Concept predicate [concept.predicate]")<R, T, T> && [predicate](#concept:predicate "18.7.4 Concept predicate [concept.predicate]")<R, U, U> &&
|
||||
[predicate](#concept:predicate "18.7.4 Concept predicate [concept.predicate]")<R, T, U> && [predicate](#concept:predicate "18.7.4 Concept predicate [concept.predicate]")<R, U, T>;
|
||||
`
|
||||
|
||||
### [18.7.6](#concept.equiv) Concept equivalence_relation [[concept.equiv]](concept.equiv)
|
||||
|
||||
[ð](#concept:equivalence_relation)
|
||||
|
||||
`template<class R, class T, class U>
|
||||
concept [equivalence_relation](#concept:equivalence_relation "18.7.6 Concept equivalence_relation [concept.equiv]") = [relation](#concept:relation "18.7.5 Concept relation [concept.relation]")<R, T, U>;
|
||||
`
|
||||
|
||||
[1](#concept.equiv-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1290)
|
||||
|
||||
A [relation](#concept:relation "18.7.5 Concept relation [concept.relation]") models [equivalence_relation](#concept:equivalence_relation "18.7.6 Concept equivalence_relation [concept.equiv]") only if
|
||||
it imposes an equivalence relation on its arguments[.](#concept.equiv-1.sentence-1)
|
||||
|
||||
### [18.7.7](#concept.strictweakorder) Concept strict_weak_order [[concept.strictweakorder]](concept.strictweakorder)
|
||||
|
||||
[ð](#concept:strict_weak_order)
|
||||
|
||||
`template<class R, class T, class U>
|
||||
concept [strict_weak_order](#concept:strict_weak_order "18.7.7 Concept strict_weak_order [concept.strictweakorder]") = [relation](#concept:relation "18.7.5 Concept relation [concept.relation]")<R, T, U>;
|
||||
`
|
||||
|
||||
[1](#concept.strictweakorder-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1303)
|
||||
|
||||
A [relation](#concept:relation "18.7.5 Concept relation [concept.relation]") models [strict_weak_order](#concept:strict_weak_order "18.7.7 Concept strict_weak_order [concept.strictweakorder]") only if
|
||||
it imposes a [*strict weak ordering*](#def:strict_weak_ordering) on its arguments[.](#concept.strictweakorder-1.sentence-1)
|
||||
|
||||
[2](#concept.strictweakorder-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1307)
|
||||
|
||||
The term[*strict*](#def:strict) refers to the
|
||||
requirement of an irreflexive relation (!comp(x, x) for all x),
|
||||
and the term[*weak*](#def:weak) to requirements that are not as strong as
|
||||
those for a total ordering,
|
||||
but stronger than those for a partial
|
||||
ordering[.](#concept.strictweakorder-2.sentence-1)
|
||||
|
||||
If we defineequiv(a, b) as!comp(a, b) && !comp(b, a),
|
||||
then the requirements are thatcomp andequiv both be transitive relations:
|
||||
|
||||
- [(2.1)](#concept.strictweakorder-2.1)
|
||||
|
||||
comp(a, b) && comp(b, c) impliescomp(a, c)
|
||||
|
||||
- [(2.2)](#concept.strictweakorder-2.2)
|
||||
|
||||
equiv(a, b) && equiv(b, c) impliesequiv(a, c)
|
||||
|
||||
[3](#concept.strictweakorder-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1338)
|
||||
|
||||
[*Note [1](#concept.strictweakorder-note-1)*:
|
||||
|
||||
Under these conditions, it can be shown that
|
||||
|
||||
- [(3.1)](#concept.strictweakorder-3.1)
|
||||
|
||||
equiv is an equivalence relation,
|
||||
|
||||
- [(3.2)](#concept.strictweakorder-3.2)
|
||||
|
||||
comp induces a well-defined relation on the equivalence
|
||||
classes determined byequiv, and
|
||||
|
||||
- [(3.3)](#concept.strictweakorder-3.3)
|
||||
|
||||
the induced relation is a strict total ordering[.](#concept.strictweakorder-3.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
Reference in New Issue
Block a user