From Jason Turner

[concepts.compare]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpq8pxwfd6/{from.md → to.md} +208 -0
tmp/tmpq8pxwfd6/{from.md → to.md} RENAMED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Comparison concepts <a id="concepts.compare">[[concepts.compare]]</a>
2
+
3
+ ### General <a id="concepts.compare.general">[[concepts.compare.general]]</a>
4
+
5
+ Subclause [[concepts.compare]] describes concepts that establish
6
+ relationships and orderings on values of possibly differing object
7
+ types.
8
+
9
+ ### Boolean testability <a id="concept.booleantestable">[[concept.booleantestable]]</a>
10
+
11
+ The exposition-only `boolean-testable` concept specifies the
12
+ requirements on expressions that are convertible to `bool` and for which
13
+ the logical operators  ([[expr.log.and]], [[expr.log.or]],
14
+ [[expr.unary.op]]) have the conventional semantics.
15
+
16
+ ``` cpp
17
+ template<class T>
18
+ concept boolean-testable-impl = convertible_to<T, bool>; // exposition only
19
+ ```
20
+
21
+ Let `e` be an expression such that `decltype((e))` is `T`. `T` models
22
+ `boolean-testable-impl` only if:
23
+
24
+ - either `remove_cvref_t<T>` is not a class type, or name lookup for the
25
+ names `operator&&` and `operator||` within the scope of
26
+ `remove_cvref_t<T>` as if by class member access lookup
27
+ [[class.member.lookup]] results in an empty declaration set; and
28
+ - name lookup for the names `operator&&` and `operator||` in the
29
+ associated namespaces and entities of `T` [[basic.lookup.argdep]]
30
+ finds no disqualifying declaration (defined below).
31
+
32
+ A *disqualifying parameter* is a function parameter whose declared type
33
+ `P`
34
+
35
+ - is not dependent on a template parameter, and there exists an implicit
36
+ conversion sequence [[over.best.ics]] from `e` to `P`; or
37
+ - is dependent on one or more template parameters, and either
38
+ - `P` contains no template parameter that participates in template
39
+ argument deduction [[temp.deduct.type]], or
40
+ - template argument deduction using the rules for deducing template
41
+ arguments in a function call [[temp.deduct.call]] and `e` as the
42
+ argument succeeds.
43
+
44
+ A *key parameter* of a function template `D` is a function parameter of
45
+ type cv `X` or reference thereto, where `X` names a specialization of a
46
+ class template that is a member of the same namespace as `D`, and `X`
47
+ contains at least one template parameter that participates in template
48
+ argument deduction.
49
+
50
+ [*Example 1*:
51
+
52
+ In
53
+
54
+ ``` cpp
55
+ namespace Z {
56
+ template<class> struct C {};
57
+ template<class T>
58
+ void operator&&(C<T> x, T y);
59
+ template<class T>
60
+ void operator||(C<type_identity_t<T>> x, T y);
61
+ }
62
+ ```
63
+
64
+ the declaration of `Z::operator&&` contains one key parameter, `C<T> x`,
65
+ and the declaration of `Z::operator||` contains no key parameters.
66
+
67
+ — *end example*]
68
+
69
+ A *disqualifying declaration* is
70
+
71
+ - a (non-template) function declaration that contains at least one
72
+ disqualifying parameter; or
73
+ - a function template declaration that contains at least one
74
+ disqualifying parameter, where
75
+ - at least one disqualifying parameter is a key parameter; or
76
+ - the declaration contains no key parameters; or
77
+ - the declaration declares a function template that is not visible in
78
+ its namespace [[namespace.memdef]].
79
+
80
+ [*Note 1*: The intention is to ensure that given two types `T1` and
81
+ `T2` that each model `boolean-testable-impl`, the `&&` and `||`
82
+ operators within the expressions `declval<T1>() && declval<T2>()` and
83
+ `declval<T1>() || declval<T2>()` resolve to the corresponding built-in
84
+ operators. — *end note*]
85
+
86
+ ``` cpp
87
+ template<class T>
88
+ concept boolean-testable = // exposition only
89
+ boolean-testable-impl<T> && requires (T&& t) {
90
+ { !std::forward<T>(t) } -> boolean-testable-impl;
91
+ };
92
+ ```
93
+
94
+ Let `e` be an expression such that `decltype((e))` is `T`. `T` models
95
+ `boolean-testable` only if `bool(e) == !bool(!e)`.
96
+
97
+ [*Example 2*: The types `bool`, `true_type` [[meta.type.synop]],
98
+ `int*`, and `bitset<N>::reference` [[template.bitset]] model
99
+ *`boolean-testable`*. — *end example*]
100
+
101
+ ### Concept <a id="concept.equalitycomparable">[[concept.equalitycomparable]]</a>
102
+
103
+ ``` cpp
104
+ template<class T, class U>
105
+ concept weakly-equality-comparable-with = // exposition only
106
+ requires(const remove_reference_t<T>& t,
107
+ const remove_reference_t<U>& u) {
108
+ { t == u } -> boolean-testable;
109
+ { t != u } -> boolean-testable;
110
+ { u == t } -> boolean-testable;
111
+ { u != t } -> boolean-testable;
112
+ };
113
+ ```
114
+
115
+ Given types `T` and `U`, let `t` and `u` be lvalues of types
116
+ `const remove_reference_t<T>` and `const remove_reference_t<U>`
117
+ respectively. `T` and `U` model
118
+ *`weakly-equality-comparable-with`*`<T, U>` only if
119
+
120
+ - `t == u`, `u == t`, `t != u`, and `u != t` have the same domain.
121
+ - `bool(u == t) == bool(t == u)`.
122
+ - `bool(t != u) == !bool(t == u)`.
123
+ - `bool(u != t) == bool(t != u)`.
124
+
125
+ ``` cpp
126
+ template<class T>
127
+ concept equality_comparable = weakly-equality-comparable-with<T, T>;
128
+ ```
129
+
130
+ Let `a` and `b` be objects of type `T`. `T` models `equality_comparable`
131
+ only if `bool(a == b)` is `true` when `a` is equal to `b`
132
+ [[concepts.equality]], and `false` otherwise.
133
+
134
+ [*Note 1*: The requirement that the expression `a == b` is
135
+ equality-preserving implies that `==` is transitive and
136
+ symmetric. — *end note*]
137
+
138
+ ``` cpp
139
+ template<class T, class U>
140
+ concept equality_comparable_with =
141
+ equality_comparable<T> && equality_comparable<U> &&
142
+ common_reference_with<const remove_reference_t<T>&, const remove_reference_t<U>&> &&
143
+ equality_comparable<
144
+ common_reference_t<
145
+ const remove_reference_t<T>&,
146
+ const remove_reference_t<U>&>> &&
147
+ weakly-equality-comparable-with<T, U>;
148
+ ```
149
+
150
+ Given types `T` and `U`, let `t` be an lvalue of type
151
+ `const remove_reference_t<T>`, `u` be an lvalue of type
152
+ `const remove_reference_t<U>`, and `C` be:
153
+
154
+ ``` cpp
155
+ common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>
156
+ ```
157
+
158
+ `T` and `U` model `equality_comparable_with<T, U>` only if
159
+ `bool(t == u) == bool(C(t) == C(u))`.
160
+
161
+ ### Concept <a id="concept.totallyordered">[[concept.totallyordered]]</a>
162
+
163
+ ``` cpp
164
+ template<class T>
165
+ concept totally_ordered =
166
+ equality_comparable<T> && partially-ordered-with<T, T>;
167
+ ```
168
+
169
+ Given a type `T`, let `a`, `b`, and `c` be lvalues of type
170
+ `const remove_reference_t<T>`. `T` models `totally_ordered` only if
171
+
172
+ - Exactly one of `bool(a < b)`, `bool(a > b)`, or `bool(a == b)` is
173
+ `true`.
174
+ - If `bool(a < b)` and `bool(b < c)`, then `bool(a < c)`.
175
+ - `bool(a <= b) == !bool(b < a)`.
176
+ - `bool(a >= b) == !bool(a < b)`.
177
+
178
+ ``` cpp
179
+ template<class T, class U>
180
+ concept totally_ordered_with =
181
+ totally_ordered<T> && totally_ordered<U> &&
182
+ equality_comparable_with<T, U> &&
183
+ totally_ordered<
184
+ common_reference_t<
185
+ const remove_reference_t<T>&,
186
+ const remove_reference_t<U>&>> &&
187
+ partially-ordered-with<T, U>;
188
+ ```
189
+
190
+ Given types `T` and `U`, let `t` be an lvalue of type
191
+ `const remove_reference_t<T>`, `u` be an lvalue of type
192
+ `const remove_reference_t<U>`, and `C` be:
193
+
194
+ ``` cpp
195
+ common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>
196
+ ```
197
+
198
+ `T` and `U` model `totally_ordered_with<T, U>` only if
199
+
200
+ - `bool(t < u) == bool(C(t) < C(u)).`
201
+ - `bool(t > u) == bool(C(t) > C(u)).`
202
+ - `bool(t <= u) == bool(C(t) <= C(u)).`
203
+ - `bool(t >= u) == bool(C(t) >= C(u)).`
204
+ - `bool(u < t) == bool(C(u) < C(t)).`
205
+ - `bool(u > t) == bool(C(u) > C(t)).`
206
+ - `bool(u <= t) == bool(C(u) <= C(t)).`
207
+ - `bool(u >= t) == bool(C(u) >= C(t)).`
208
+