From Jason Turner

[class.spaceship]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp8kml2_85/{from.md → to.md} +71 -0
tmp/tmp8kml2_85/{from.md → to.md} RENAMED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Three-way comparison <a id="class.spaceship">[[class.spaceship]]</a>
2
+
3
+ The *synthesized three-way comparison* of type `R` [[cmp.categories]] of
4
+ glvalues `a` and `b` of the same type is defined as follows:
5
+
6
+ - If `a <=> b` is usable [[class.compare.default]],
7
+ `static_cast<R>(a <=> b)`.
8
+ - Otherwise, if overload resolution for `a <=> b` is performed and finds
9
+ at least one viable candidate, the synthesized three-way comparison is
10
+ not defined.
11
+ - Otherwise, if `R` is not a comparison category type, or either the
12
+ expression `a == b` or the expression `a < b` is not usable, the
13
+ synthesized three-way comparison is not defined.
14
+ - Otherwise, if `R` is `strong_ordering`, then
15
+ ``` cpp
16
+ a == b ? strong_ordering::equal :
17
+ a < b ? strong_ordering::less :
18
+ strong_ordering::greater
19
+ ```
20
+ - Otherwise, if `R` is `weak_ordering`, then
21
+ ``` cpp
22
+ a == b ? weak_ordering::equivalent :
23
+ a < b ? weak_ordering::less :
24
+ weak_ordering::greater
25
+ ```
26
+ - Otherwise (when `R` is `partial_ordering`),
27
+ ``` cpp
28
+ a == b ? partial_ordering::equivalent :
29
+ a < b ? partial_ordering::less :
30
+ b < a ? partial_ordering::greater :
31
+ partial_ordering::unordered
32
+ ```
33
+
34
+ [*Note 1*: A synthesized three-way comparison may be ill-formed if
35
+ overload resolution finds usable candidates that do not otherwise meet
36
+ the requirements implied by the defined expression. — *end note*]
37
+
38
+ Let `R` be the declared return type of a defaulted three-way comparison
39
+ operator function, and let `xᵢ` be the elements of the expanded list of
40
+ subobjects for an object `x` of type `C`.
41
+
42
+ - If `R` is `auto`, then let cvᵢ~`Rᵢ` be the type of the expression
43
+ `xᵢ`` <=> ``xᵢ`. The operator function is defined as deleted if that
44
+ expression is not usable or if `Rᵢ` is not a comparison category type
45
+ [[cmp.categories.pre]] for any i. The return type is deduced as the
46
+ common comparison type (see below) of `R₀`, `R₁`, …, `R_n-1`.
47
+ - Otherwise, `R` shall not contain a placeholder type. If the
48
+ synthesized three-way comparison of type `R` between any objects `xᵢ`
49
+ and `xᵢ` is not defined, the operator function is defined as deleted.
50
+
51
+ The return value `V` of type `R` of the defaulted three-way comparison
52
+ operator function with parameters `x` and `y` of the same type is
53
+ determined by comparing corresponding elements `xᵢ` and `yᵢ` in the
54
+ expanded lists of subobjects for `x` and `y` (in increasing index order)
55
+ until the first index i where the synthesized three-way comparison of
56
+ type `R` between `xᵢ` and `yᵢ` yields a result value `vᵢ` where
57
+ `vᵢ` `!=` 0, contextually converted to `bool`, yields `true`; `V` is a
58
+ copy of `vᵢ`. If no such index exists, `V` is
59
+ `static_cast<R>(std::strong_ordering::equal)`.
60
+
61
+ The *common comparison type* `U` of a possibly-empty list of n
62
+ comparison category types `T₀`, `T₁`, …, `T_n-1` is defined as follows:
63
+
64
+ - If at least one `Tᵢ` is `std::partial_ordering`, `U` is
65
+ `std::partial_ordering` [[cmp.partialord]].
66
+ - Otherwise, if at least one `Tᵢ` is `std::weak_ordering`, `U` is
67
+ `std::weak_ordering` [[cmp.weakord]].
68
+ - Otherwise, `U` is `std::strong_ordering` [[cmp.strongord]].
69
+ \[*Note 2*: In particular, this is the result when n is
70
+ 0. — *end note*]
71
+