From Jason Turner

[expr.spaceship]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpjhyw7zht/{from.md → to.md} +69 -0
tmp/tmpjhyw7zht/{from.md → to.md} RENAMED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Three-way comparison operator <a id="expr.spaceship">[[expr.spaceship]]</a>
2
+
3
+ The three-way comparison operator groups left-to-right.
4
+
5
+ ``` bnf
6
+ compare-expression:
7
+ shift-expression
8
+ compare-expression '<=>' shift-expression
9
+ ```
10
+
11
+ The expression `p <=> q` is a prvalue indicating whether `p` is less
12
+ than, equal to, greater than, or incomparable with `q`.
13
+
14
+ If one of the operands is of type `bool` and the other is not, the
15
+ program is ill-formed.
16
+
17
+ If both operands have arithmetic types, or one operand has integral type
18
+ and the other operand has unscoped enumeration type, the usual
19
+ arithmetic conversions [[expr.arith.conv]] are applied to the operands.
20
+ Then:
21
+
22
+ - If a narrowing conversion [[dcl.init.list]] is required, other than
23
+ from an integral type to a floating-point type, the program is
24
+ ill-formed.
25
+ - Otherwise, if the operands have integral type, the result is of type
26
+ `std::strong_ordering`. The result is `std::strong_ordering::equal` if
27
+ both operands are arithmetically equal, `std::strong_ordering::less`
28
+ if the first operand is arithmetically less than the second operand,
29
+ and `std::strong_ordering::greater` otherwise.
30
+ - Otherwise, the operands have floating-point type, and the result is of
31
+ type `std::partial_ordering`. The expression `a <=> b` yields
32
+ `std::partial_ordering::less` if `a` is less than `b`,
33
+ `std::partial_ordering::greater` if `a` is greater than `b`,
34
+ `std::partial_ordering::equivalent` if `a` is equivalent to `b`, and
35
+ `std::partial_ordering::unordered` otherwise.
36
+
37
+ If both operands have the same enumeration type `E`, the operator yields
38
+ the result of converting the operands to the underlying type of `E` and
39
+ applying `<=>` to the converted operands.
40
+
41
+ If at least one of the operands is of pointer type and the other operand
42
+ is of pointer or array type, array-to-pointer conversions
43
+ [[conv.array]], pointer conversions [[conv.ptr]], and qualification
44
+ conversions [[conv.qual]] are performed on both operands to bring them
45
+ to their composite pointer type [[expr.type]]. After the conversions,
46
+ the operands shall have the same type.
47
+
48
+ [*Note 1*: If both of the operands are arrays, array-to-pointer
49
+ conversions [[conv.array]] are not applied. — *end note*]
50
+
51
+ If the composite pointer type is an object pointer type, `p <=> q` is of
52
+ type `std::strong_ordering`. If two pointer operands `p` and `q` compare
53
+ equal [[expr.eq]], `p <=> q` yields `std::strong_ordering::equal`; if
54
+ `p` and `q` compare unequal, `p <=> q` yields
55
+ `std::strong_ordering::less` if `q` compares greater than `p` and
56
+ `std::strong_ordering::greater` if `p` compares greater than `q`
57
+ [[expr.rel]]. Otherwise, the result is unspecified.
58
+
59
+ Otherwise, the program is ill-formed.
60
+
61
+ The three comparison category types [[cmp.categories]] (the types
62
+ `std::strong_ordering`, `std::weak_ordering`, and
63
+ `std::partial_ordering`) are not predefined; if the header `<compare>`
64
+ is not imported or included prior to a use of such a class type – even
65
+ an implicit use in which the type is not named (e.g., via the `auto`
66
+ specifier [[dcl.spec.auto]] in a defaulted three-way comparison
67
+ [[class.spaceship]] or use of the built-in operator) – the program is
68
+ ill-formed.
69
+