From Jason Turner

[class.compare.default]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpc2erl7wh/{from.md → to.md} +100 -0
tmp/tmpc2erl7wh/{from.md → to.md} RENAMED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Defaulted comparison operator functions <a id="class.compare.default">[[class.compare.default]]</a>
2
+
3
+ A defaulted comparison operator function [[over.binary]] for some class
4
+ `C` shall be a non-template function that is
5
+
6
+ - a non-static const non-volatile member of `C` having one parameter of
7
+ type `const C&` and either no *ref-qualifier* or the *ref-qualifier*
8
+ `&`, or
9
+ - a friend of `C` having either two parameters of type `const C&` or two
10
+ parameters of type `C`.
11
+
12
+ A comparison operator function for class `C` that is defaulted on its
13
+ first declaration and is not defined as deleted is *implicitly defined*
14
+ when it is odr-used or needed for constant evaluation. Name lookups in
15
+ the defaulted definition of a comparison operator function are performed
16
+ from a context equivalent to its *function-body*. A definition of a
17
+ comparison operator as defaulted that appears in a class shall be the
18
+ first declaration of that function.
19
+
20
+ A defaulted `<=>` or `==` operator function for class `C` is defined as
21
+ deleted if any non-static data member of `C` is of reference type or `C`
22
+ has variant members [[class.union.anon]].
23
+
24
+ A binary operator expression `a @ b` is *usable* if either
25
+
26
+ - `a` or `b` is of class or enumeration type and overload resolution
27
+ [[over.match]] as applied to `a @ b` results in a usable candidate, or
28
+ - neither `a` nor `b` is of class or enumeration type and `a @ b` is a
29
+ valid expression.
30
+
31
+ A defaulted comparison function is *constexpr-compatible* if it
32
+ satisfies the requirements for a constexpr function [[dcl.constexpr]]
33
+ and no overload resolution performed when determining whether to delete
34
+ the function results in a usable candidate that is a non-constexpr
35
+ function.
36
+
37
+ [*Note 1*:
38
+
39
+ This includes the overload resolutions performed:
40
+
41
+ - for an `operator<=>` whose return type is not `auto`, when determining
42
+ whether a synthesized three-way comparison is defined,
43
+ - for an `operator<=>` whose return type is `auto` or for an
44
+ `operator==`, for a comparison between an element of the expanded list
45
+ of subobjects and itself, or
46
+ - for a secondary comparison operator `@`, for the expression `x @ y`.
47
+
48
+ — *end note*]
49
+
50
+ If the *member-specification* does not explicitly declare any member or
51
+ friend named `operator==`, an `==` operator function is declared
52
+ implicitly for each three-way comparison operator function defined as
53
+ defaulted in the *member-specification*, with the same access and
54
+ *function-definition* and in the same class scope as the respective
55
+ three-way comparison operator function, except that the return type is
56
+ replaced with `bool` and the *declarator-id* is replaced with
57
+ `operator==`.
58
+
59
+ [*Note 2*: Such an implicitly-declared `==` operator for a class `X` is
60
+ defined as defaulted in the definition of `X` and has the same
61
+ *parameter-declaration-clause* and trailing *requires-clause* as the
62
+ respective three-way comparison operator. It is declared with `friend`,
63
+ `virtual`, `constexpr`, or `consteval` if the three-way comparison
64
+ operator function is so declared. If the three-way comparison operator
65
+ function has no *noexcept-specifier*, the implicitly-declared `==`
66
+ operator function has an implicit exception specification
67
+ [[except.spec]] that may differ from the implicit exception
68
+ specification of the three-way comparison operator
69
+ function. — *end note*]
70
+
71
+ [*Example 1*:
72
+
73
+ ``` cpp
74
+ template<typename T> struct X {
75
+ friend constexpr std::partial_ordering operator<=>(X, X) requires (sizeof(T) != 1) = default;
76
+ // implicitly declares: friend constexpr bool operator==(X, X) requires (sizeof(T) != 1) = default;
77
+
78
+ [[nodiscard]] virtual std::strong_ordering operator<=>(const X&) const = default;
79
+ // implicitly declares: [[nodiscard]] virtual bool operator==(const X&) const = default;
80
+ };
81
+ ```
82
+
83
+ — *end example*]
84
+
85
+ [*Note 3*: The `==` operator function is declared implicitly even if
86
+ the defaulted three-way comparison operator function is defined as
87
+ deleted. — *end note*]
88
+
89
+ The direct base class subobjects of `C`, in the order of their
90
+ declaration in the *base-specifier-list* of `C`, followed by the
91
+ non-static data members of `C`, in the order of their declaration in the
92
+ *member-specification* of `C`, form a list of subobjects. In that list,
93
+ any subobject of array type is recursively expanded to the sequence of
94
+ its elements, in the order of increasing subscript. Let `xᵢ` be an
95
+ lvalue denoting the iᵗʰ element in the expanded list of subobjects for
96
+ an object `x` (of length n), where `xᵢ` is formed by a sequence of
97
+ derived-to-base conversions [[over.best.ics]], class member access
98
+ expressions [[expr.ref]], and array subscript expressions [[expr.sub]]
99
+ applied to `x`.
100
+