tmp/tmplva1x6nm/{from.md → to.md}
RENAMED
|
@@ -1,19 +1,37 @@
|
|
| 1 |
### Defaulted comparison operator functions <a id="class.compare.default">[[class.compare.default]]</a>
|
| 2 |
|
| 3 |
-
A defaulted comparison operator function [[over.binary]]
|
| 4 |
-
|
| 5 |
|
| 6 |
-
- a non-static member or friend of `C`
|
|
|
|
|
|
|
| 7 |
- either has two parameters of type `const C&` or two parameters of type
|
| 8 |
`C`, where the implicit object parameter (if any) is considered to be
|
| 9 |
the first parameter.
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
A defaulted `<=>` or `==` operator function for class `C` is defined as
|
| 17 |
deleted if any non-static data member of `C` is of reference type or `C`
|
| 18 |
has variant members [[class.union.anon]].
|
| 19 |
|
|
@@ -43,11 +61,11 @@ function has no *noexcept-specifier*, the implicitly-declared `==`
|
|
| 43 |
operator function has an implicit exception specification
|
| 44 |
[[except.spec]] that can differ from the implicit exception
|
| 45 |
specification of the three-way comparison operator
|
| 46 |
function. — *end note*]
|
| 47 |
|
| 48 |
-
[*Example
|
| 49 |
|
| 50 |
``` cpp
|
| 51 |
template<typename T> struct X {
|
| 52 |
friend constexpr std::partial_ordering operator<=>(X, X) requires (sizeof(T) != 1) = default;
|
| 53 |
// implicitly declares: friend constexpr bool operator==(X, X) requires (sizeof(T) != 1) = default;
|
|
|
|
| 1 |
### Defaulted comparison operator functions <a id="class.compare.default">[[class.compare.default]]</a>
|
| 2 |
|
| 3 |
+
A defaulted comparison operator function [[over.binary]] shall be a
|
| 4 |
+
non-template function that
|
| 5 |
|
| 6 |
+
- is a non-static member or friend of some class `C`,
|
| 7 |
+
- is defined as defaulted in `C` or in a context where `C` is complete,
|
| 8 |
+
and
|
| 9 |
- either has two parameters of type `const C&` or two parameters of type
|
| 10 |
`C`, where the implicit object parameter (if any) is considered to be
|
| 11 |
the first parameter.
|
| 12 |
|
| 13 |
+
Such a comparison operator function is termed a defaulted comparison
|
| 14 |
+
operator function for class `C`. Name lookups and access checks in the
|
| 15 |
+
implicit definition [[dcl.fct.def.default]] of a comparison operator
|
| 16 |
+
function are performed from a context equivalent to its *function-body*.
|
| 17 |
+
A definition of a comparison operator as defaulted that appears in a
|
| 18 |
+
class shall be the first declaration of that function.
|
| 19 |
+
|
| 20 |
+
[*Example 1*:
|
| 21 |
+
|
| 22 |
+
``` cpp
|
| 23 |
+
struct S;
|
| 24 |
+
bool operator==(S, S) = default; // error: S is not complete
|
| 25 |
+
struct S {
|
| 26 |
+
friend bool operator==(S, const S&) = default; // error: parameters of different types
|
| 27 |
+
};
|
| 28 |
+
enum E { };
|
| 29 |
+
bool operator==(E, E) = default; // error: not a member or friend of a class
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
— *end example*]
|
| 33 |
|
| 34 |
A defaulted `<=>` or `==` operator function for class `C` is defined as
|
| 35 |
deleted if any non-static data member of `C` is of reference type or `C`
|
| 36 |
has variant members [[class.union.anon]].
|
| 37 |
|
|
|
|
| 61 |
operator function has an implicit exception specification
|
| 62 |
[[except.spec]] that can differ from the implicit exception
|
| 63 |
specification of the three-way comparison operator
|
| 64 |
function. — *end note*]
|
| 65 |
|
| 66 |
+
[*Example 2*:
|
| 67 |
|
| 68 |
``` cpp
|
| 69 |
template<typename T> struct X {
|
| 70 |
friend constexpr std::partial_ordering operator<=>(X, X) requires (sizeof(T) != 1) = default;
|
| 71 |
// implicitly declares: friend constexpr bool operator==(X, X) requires (sizeof(T) != 1) = default;
|