From Jason Turner

[cmp.categories]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpiwmvm26l/{from.md → to.md} +322 -0
tmp/tmpiwmvm26l/{from.md → to.md} RENAMED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Comparison category types <a id="cmp.categories">[[cmp.categories]]</a>
2
+
3
+ #### Preamble <a id="cmp.categories.pre">[[cmp.categories.pre]]</a>
4
+
5
+ The types `partial_ordering`, `weak_ordering`, and `strong_ordering` are
6
+ collectively termed the *comparison category types*. Each is specified
7
+ in terms of an exposition-only data member named `value` whose value
8
+ typically corresponds to that of an enumerator from one of the following
9
+ exposition-only enumerations:
10
+
11
+ ``` cpp
12
+ enum class eq { equal = 0, equivalent = equal,
13
+ nonequal = 1, nonequivalent = nonequal }; // exposition only
14
+ enum class ord { less = -1, greater = 1 }; // exposition only
15
+ enum class ncmp { unordered = -127 }; // exposition only
16
+ ```
17
+
18
+ [*Note 1*: The type `strong_ordering` corresponds to the term total
19
+ ordering in mathematics. — *end note*]
20
+
21
+ The relational and equality operators for the comparison category types
22
+ are specified with an anonymous parameter of unspecified type. This type
23
+ shall be selected by the implementation such that these parameters can
24
+ accept literal `0` as a corresponding argument.
25
+
26
+ [*Example 1*:
27
+
28
+ `nullptr_t`
29
+
30
+ meets this requirement.
31
+
32
+ — *end example*]
33
+
34
+ In this context, the behavior of a program that supplies an argument
35
+ other than a literal `0` is undefined.
36
+
37
+ For the purposes of subclause [[cmp.categories]], *substitutability* is
38
+ the property that `f(a) == f(b)` is `true` whenever `a == b` is `true`,
39
+ where `f` denotes a function that reads only comparison-salient state
40
+ that is accessible via the argument’s public const members.
41
+
42
+ #### Class `partial_ordering` <a id="cmp.partialord">[[cmp.partialord]]</a>
43
+
44
+ The `partial_ordering` type is typically used as the result type of a
45
+ three-way comparison operator [[expr.spaceship]] that (a) admits all of
46
+ the six two-way comparison operators ([[expr.rel]], [[expr.eq]]), (b)
47
+ does not imply substitutability, and (c) permits two values to be
48
+ incomparable. [^34]
49
+
50
+ ``` cpp
51
+ namespace std {
52
+ class partial_ordering {
53
+ int value; // exposition only
54
+ bool is_ordered; // exposition only
55
+
56
+ // exposition-only constructors
57
+ constexpr explicit
58
+ partial_ordering(eq v) noexcept : value(int(v)), is_ordered(true) {} // exposition only
59
+ constexpr explicit
60
+ partial_ordering(ord v) noexcept : value(int(v)), is_ordered(true) {} // exposition only
61
+ constexpr explicit
62
+ partial_ordering(ncmp v) noexcept : value(int(v)), is_ordered(false) {} // exposition only
63
+
64
+ public:
65
+ // valid values
66
+ static const partial_ordering less;
67
+ static const partial_ordering equivalent;
68
+ static const partial_ordering greater;
69
+ static const partial_ordering unordered;
70
+
71
+ // comparisons
72
+ friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
73
+ friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;
74
+ friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
75
+ friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
76
+ friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
77
+ friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
78
+ friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
79
+ friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
80
+ friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
81
+ friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
82
+ friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
83
+ friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
84
+ };
85
+
86
+ // valid values' definitions
87
+ inline constexpr partial_ordering partial_ordering::less(ord::less);
88
+ inline constexpr partial_ordering partial_ordering::equivalent(eq::equivalent);
89
+ inline constexpr partial_ordering partial_ordering::greater(ord::greater);
90
+ inline constexpr partial_ordering partial_ordering::unordered(ncmp::unordered);
91
+ }
92
+ ```
93
+
94
+ ``` cpp
95
+ constexpr bool operator==(partial_ordering v, unspecified) noexcept;
96
+ constexpr bool operator< (partial_ordering v, unspecified) noexcept;
97
+ constexpr bool operator> (partial_ordering v, unspecified) noexcept;
98
+ constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
99
+ constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
100
+ ```
101
+
102
+ *Returns:* For `operator`, `v.is_ordered && v.value 0`.
103
+
104
+ ``` cpp
105
+ constexpr bool operator< (unspecified, partial_ordering v) noexcept;
106
+ constexpr bool operator> (unspecified, partial_ordering v) noexcept;
107
+ constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
108
+ constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
109
+ ```
110
+
111
+ *Returns:* For `operator`, `v.is_ordered && 0 v.value`.
112
+
113
+ ``` cpp
114
+ constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
115
+ ```
116
+
117
+ *Returns:* `v`.
118
+
119
+ ``` cpp
120
+ constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
121
+ ```
122
+
123
+ *Returns:*
124
+ `v < 0 ? partial_ordering::greater : v > 0 ? partial_ordering::less : v`.
125
+
126
+ #### Class `weak_ordering` <a id="cmp.weakord">[[cmp.weakord]]</a>
127
+
128
+ The `weak_ordering` type is typically used as the result type of a
129
+ three-way comparison operator [[expr.spaceship]] that (a) admits all of
130
+ the six two-way comparison operators ([[expr.rel]], [[expr.eq]]), and
131
+ (b) does not imply substitutability.
132
+
133
+ ``` cpp
134
+ namespace std {
135
+ class weak_ordering {
136
+ int value; // exposition only
137
+
138
+ // exposition-only constructors
139
+ constexpr explicit weak_ordering(eq v) noexcept : value(int(v)) {} // exposition only
140
+ constexpr explicit weak_ordering(ord v) noexcept : value(int(v)) {} // exposition only
141
+
142
+ public:
143
+ // valid values
144
+ static const weak_ordering less;
145
+ static const weak_ordering equivalent;
146
+ static const weak_ordering greater;
147
+
148
+ // conversions
149
+ constexpr operator partial_ordering() const noexcept;
150
+
151
+ // comparisons
152
+ friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;
153
+ friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
154
+ friend constexpr bool operator< (weak_ordering v, unspecified) noexcept;
155
+ friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;
156
+ friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
157
+ friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
158
+ friend constexpr bool operator< (unspecified, weak_ordering v) noexcept;
159
+ friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;
160
+ friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
161
+ friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
162
+ friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
163
+ friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
164
+ };
165
+
166
+ // valid values' definitions
167
+ inline constexpr weak_ordering weak_ordering::less(ord::less);
168
+ inline constexpr weak_ordering weak_ordering::equivalent(eq::equivalent);
169
+ inline constexpr weak_ordering weak_ordering::greater(ord::greater);
170
+ }
171
+ ```
172
+
173
+ ``` cpp
174
+ constexpr operator partial_ordering() const noexcept;
175
+ ```
176
+
177
+ *Returns:*
178
+
179
+ ``` cpp
180
+ value == 0 ? partial_ordering::equivalent :
181
+ value < 0 ? partial_ordering::less :
182
+ partial_ordering::greater
183
+ ```
184
+
185
+ ``` cpp
186
+ constexpr bool operator==(weak_ordering v, unspecified) noexcept;
187
+ constexpr bool operator< (weak_ordering v, unspecified) noexcept;
188
+ constexpr bool operator> (weak_ordering v, unspecified) noexcept;
189
+ constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
190
+ constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
191
+ ```
192
+
193
+ *Returns:* `v.value 0` for `operator`.
194
+
195
+ ``` cpp
196
+ constexpr bool operator< (unspecified, weak_ordering v) noexcept;
197
+ constexpr bool operator> (unspecified, weak_ordering v) noexcept;
198
+ constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
199
+ constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
200
+ ```
201
+
202
+ *Returns:* `0 v.value` for `operator`.
203
+
204
+ ``` cpp
205
+ constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
206
+ ```
207
+
208
+ *Returns:* `v`.
209
+
210
+ ``` cpp
211
+ constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
212
+ ```
213
+
214
+ *Returns:*
215
+ `v < 0 ? weak_ordering::greater : v > 0 ? weak_ordering::less : v`.
216
+
217
+ #### Class `strong_ordering` <a id="cmp.strongord">[[cmp.strongord]]</a>
218
+
219
+ The `strong_ordering` type is typically used as the result type of a
220
+ three-way comparison operator [[expr.spaceship]] that (a) admits all of
221
+ the six two-way comparison operators ([[expr.rel]], [[expr.eq]]), and
222
+ (b) does imply substitutability.
223
+
224
+ ``` cpp
225
+ namespace std {
226
+ class strong_ordering {
227
+ int value; // exposition only
228
+
229
+ // exposition-only constructors
230
+ constexpr explicit strong_ordering(eq v) noexcept : value(int(v)) {} // exposition only
231
+ constexpr explicit strong_ordering(ord v) noexcept : value(int(v)) {} // exposition only
232
+
233
+ public:
234
+ // valid values
235
+ static const strong_ordering less;
236
+ static const strong_ordering equal;
237
+ static const strong_ordering equivalent;
238
+ static const strong_ordering greater;
239
+
240
+ // conversions
241
+ constexpr operator partial_ordering() const noexcept;
242
+ constexpr operator weak_ordering() const noexcept;
243
+
244
+ // comparisons
245
+ friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;
246
+ friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;
247
+ friend constexpr bool operator< (strong_ordering v, unspecified) noexcept;
248
+ friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;
249
+ friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
250
+ friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
251
+ friend constexpr bool operator< (unspecified, strong_ordering v) noexcept;
252
+ friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;
253
+ friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
254
+ friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
255
+ friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
256
+ friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
257
+ };
258
+
259
+ // valid values' definitions
260
+ inline constexpr strong_ordering strong_ordering::less(ord::less);
261
+ inline constexpr strong_ordering strong_ordering::equal(eq::equal);
262
+ inline constexpr strong_ordering strong_ordering::equivalent(eq::equivalent);
263
+ inline constexpr strong_ordering strong_ordering::greater(ord::greater);
264
+ }
265
+ ```
266
+
267
+ ``` cpp
268
+ constexpr operator partial_ordering() const noexcept;
269
+ ```
270
+
271
+ *Returns:*
272
+
273
+ ``` cpp
274
+ value == 0 ? partial_ordering::equivalent :
275
+ value < 0 ? partial_ordering::less :
276
+ partial_ordering::greater
277
+ ```
278
+
279
+ ``` cpp
280
+ constexpr operator weak_ordering() const noexcept;
281
+ ```
282
+
283
+ *Returns:*
284
+
285
+ ``` cpp
286
+ value == 0 ? weak_ordering::equivalent :
287
+ value < 0 ? weak_ordering::less :
288
+ weak_ordering::greater
289
+ ```
290
+
291
+ ``` cpp
292
+ constexpr bool operator==(strong_ordering v, unspecified) noexcept;
293
+ constexpr bool operator< (strong_ordering v, unspecified) noexcept;
294
+ constexpr bool operator> (strong_ordering v, unspecified) noexcept;
295
+ constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
296
+ constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
297
+ ```
298
+
299
+ *Returns:* `v.value 0` for `operator`.
300
+
301
+ ``` cpp
302
+ constexpr bool operator< (unspecified, strong_ordering v) noexcept;
303
+ constexpr bool operator> (unspecified, strong_ordering v) noexcept;
304
+ constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
305
+ constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
306
+ ```
307
+
308
+ *Returns:* `0 v.value` for `operator`.
309
+
310
+ ``` cpp
311
+ constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
312
+ ```
313
+
314
+ *Returns:* `v`.
315
+
316
+ ``` cpp
317
+ constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
318
+ ```
319
+
320
+ *Returns:*
321
+ `v < 0 ? strong_ordering::greater : v > 0 ? strong_ordering::less : v`.
322
+