tmp/tmppas_mfyo/{from.md → to.md}
RENAMED
|
@@ -1,23 +1,20 @@
|
|
| 1 |
### Copy/move assignment operator <a id="class.copy.assign">[[class.copy.assign]]</a>
|
| 2 |
|
| 3 |
A user-declared *copy* assignment operator `X::operator=` is a
|
| 4 |
non-static non-template member function of class `X` with exactly one
|
| 5 |
non-object parameter of type `X`, `X&`, `const X&`, `volatile X&`, or
|
| 6 |
-
`const volatile X&`.[^
|
| 7 |
|
| 8 |
-
[*Note 1*:
|
| 9 |
-
only one parameter; see [[over.ass]]. — *end note*]
|
| 10 |
-
|
| 11 |
-
[*Note 2*: More than one form of copy assignment operator can be
|
| 12 |
declared for a class. — *end note*]
|
| 13 |
|
| 14 |
-
[*Note
|
| 15 |
|
| 16 |
-
If a class `X` only has a copy assignment operator with a
|
| 17 |
-
type `X&`, an expression of type const `X` cannot be
|
| 18 |
-
object of type `X`.
|
| 19 |
|
| 20 |
[*Example 1*:
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
struct X {
|
|
@@ -49,15 +46,16 @@ X& X::operator=(const X&)
|
|
| 49 |
```
|
| 50 |
|
| 51 |
if
|
| 52 |
|
| 53 |
- each direct base class `B` of `X` has a copy assignment operator whose
|
| 54 |
-
parameter is of type `const B&`, `const volatile B&`, or
|
|
|
|
| 55 |
- for all the non-static data members of `X` that are of a class type
|
| 56 |
`M` (or array thereof), each such class type has a copy assignment
|
| 57 |
-
operator whose parameter is of type `const M&`,
|
| 58 |
-
or `M`.[^
|
| 59 |
|
| 60 |
Otherwise, the implicitly-declared copy assignment operator will have
|
| 61 |
the form
|
| 62 |
|
| 63 |
``` cpp
|
|
@@ -67,14 +65,11 @@ X& X::operator=(X&)
|
|
| 67 |
A user-declared move assignment operator `X::operator=` is a non-static
|
| 68 |
non-template member function of class `X` with exactly one non-object
|
| 69 |
parameter of type `X&&`, `const X&&`, `volatile X&&`, or
|
| 70 |
`const volatile X&&`.
|
| 71 |
|
| 72 |
-
[*Note
|
| 73 |
-
only one parameter; see [[over.ass]]. — *end note*]
|
| 74 |
-
|
| 75 |
-
[*Note 5*: More than one form of move assignment operator can be
|
| 76 |
declared for a class. — *end note*]
|
| 77 |
|
| 78 |
If the definition of a class `X` does not explicitly declare a move
|
| 79 |
assignment operator, one will be implicitly declared as defaulted if and
|
| 80 |
only if
|
|
@@ -121,39 +116,37 @@ the return type `X&`. An implicitly-declared copy/move assignment
|
|
| 121 |
operator is an inline public member of its class.
|
| 122 |
|
| 123 |
A defaulted copy/move assignment operator for class `X` is defined as
|
| 124 |
deleted if `X` has:
|
| 125 |
|
| 126 |
-
- a
|
| 127 |
-
|
| 128 |
-
- a non-static data member of `const` non-class type (or array thereof),
|
| 129 |
-
or
|
| 130 |
- a non-static data member of reference type, or
|
| 131 |
-
- a direct non-static data member of class type `M` (or
|
| 132 |
-
or a direct base class `M` that cannot
|
| 133 |
-
overload resolution [[over.match]], as applied
|
| 134 |
-
corresponding assignment operator,
|
| 135 |
-
|
| 136 |
-
|
| 137 |
|
| 138 |
-
[*Note
|
| 139 |
deleted is ignored by overload resolution
|
| 140 |
[[over.match]], [[over.over]]. — *end note*]
|
| 141 |
|
| 142 |
Because a copy/move assignment operator is implicitly declared for a
|
| 143 |
class if not declared by the user, a base class copy/move assignment
|
| 144 |
operator is always hidden by the corresponding assignment operator of a
|
| 145 |
-
derived class [[over.
|
| 146 |
|
| 147 |
-
[*Note
|
| 148 |
assignment operator from a base class never suppresses the implicit
|
| 149 |
declaration of an assignment operator of `C`, even if the base class
|
| 150 |
assignment operator would be a copy or move assignment operator if
|
| 151 |
declared as a member of `C`. — *end note*]
|
| 152 |
|
| 153 |
A copy/move assignment operator for class `X` is trivial if it is not
|
| 154 |
-
user-provided and if
|
| 155 |
|
| 156 |
- class `X` has no virtual functions [[class.virtual]] and no virtual
|
| 157 |
base classes [[class.mi]], and
|
| 158 |
- the assignment operator selected to copy/move each direct base class
|
| 159 |
subobject is trivial, and
|
|
@@ -169,11 +162,11 @@ operator is `constexpr`.
|
|
| 169 |
Before the defaulted copy/move assignment operator for a class is
|
| 170 |
implicitly defined, all non-user-provided copy/move assignment operators
|
| 171 |
for its direct base classes and its non-static data members are
|
| 172 |
implicitly defined.
|
| 173 |
|
| 174 |
-
[*Note
|
| 175 |
implied exception specification [[except.spec]]. — *end note*]
|
| 176 |
|
| 177 |
The implicitly-defined copy/move assignment operator for a non-union
|
| 178 |
class `X` performs memberwise copy/move assignment of its subobjects.
|
| 179 |
The direct base classes of `X` are assigned first, in the order of their
|
|
|
|
| 1 |
### Copy/move assignment operator <a id="class.copy.assign">[[class.copy.assign]]</a>
|
| 2 |
|
| 3 |
A user-declared *copy* assignment operator `X::operator=` is a
|
| 4 |
non-static non-template member function of class `X` with exactly one
|
| 5 |
non-object parameter of type `X`, `X&`, `const X&`, `volatile X&`, or
|
| 6 |
+
`const volatile X&`.[^3]
|
| 7 |
|
| 8 |
+
[*Note 1*: More than one form of copy assignment operator can be
|
|
|
|
|
|
|
|
|
|
| 9 |
declared for a class. — *end note*]
|
| 10 |
|
| 11 |
+
[*Note 2*:
|
| 12 |
|
| 13 |
+
If a class `X` only has a copy assignment operator with a non-object
|
| 14 |
+
parameter of type `X&`, an expression of type const `X` cannot be
|
| 15 |
+
assigned to an object of type `X`.
|
| 16 |
|
| 17 |
[*Example 1*:
|
| 18 |
|
| 19 |
``` cpp
|
| 20 |
struct X {
|
|
|
|
| 46 |
```
|
| 47 |
|
| 48 |
if
|
| 49 |
|
| 50 |
- each direct base class `B` of `X` has a copy assignment operator whose
|
| 51 |
+
non-object parameter is of type `const B&`, `const volatile B&`, or
|
| 52 |
+
`B`, and
|
| 53 |
- for all the non-static data members of `X` that are of a class type
|
| 54 |
`M` (or array thereof), each such class type has a copy assignment
|
| 55 |
+
operator whose non-object parameter is of type `const M&`,
|
| 56 |
+
`const volatile M&`, or `M`.[^4]
|
| 57 |
|
| 58 |
Otherwise, the implicitly-declared copy assignment operator will have
|
| 59 |
the form
|
| 60 |
|
| 61 |
``` cpp
|
|
|
|
| 65 |
A user-declared move assignment operator `X::operator=` is a non-static
|
| 66 |
non-template member function of class `X` with exactly one non-object
|
| 67 |
parameter of type `X&&`, `const X&&`, `volatile X&&`, or
|
| 68 |
`const volatile X&&`.
|
| 69 |
|
| 70 |
+
[*Note 3*: More than one form of move assignment operator can be
|
|
|
|
|
|
|
|
|
|
| 71 |
declared for a class. — *end note*]
|
| 72 |
|
| 73 |
If the definition of a class `X` does not explicitly declare a move
|
| 74 |
assignment operator, one will be implicitly declared as defaulted if and
|
| 75 |
only if
|
|
|
|
| 116 |
operator is an inline public member of its class.
|
| 117 |
|
| 118 |
A defaulted copy/move assignment operator for class `X` is defined as
|
| 119 |
deleted if `X` has:
|
| 120 |
|
| 121 |
+
- a non-static data member of `const` non-class type (or possibly
|
| 122 |
+
multidimensional array thereof), or
|
|
|
|
|
|
|
| 123 |
- a non-static data member of reference type, or
|
| 124 |
+
- a direct non-static data member of class type `M` (or possibly
|
| 125 |
+
multidimensional array thereof) or a direct base class `M` that cannot
|
| 126 |
+
be copied/moved because overload resolution [[over.match]], as applied
|
| 127 |
+
to find `M`’s corresponding assignment operator, either does not
|
| 128 |
+
result in a usable candidate [[over.match.general]] or, in the case of
|
| 129 |
+
a variant member, selects a non-trivial function.
|
| 130 |
|
| 131 |
+
[*Note 4*: A defaulted move assignment operator that is defined as
|
| 132 |
deleted is ignored by overload resolution
|
| 133 |
[[over.match]], [[over.over]]. — *end note*]
|
| 134 |
|
| 135 |
Because a copy/move assignment operator is implicitly declared for a
|
| 136 |
class if not declared by the user, a base class copy/move assignment
|
| 137 |
operator is always hidden by the corresponding assignment operator of a
|
| 138 |
+
derived class [[over.assign]].
|
| 139 |
|
| 140 |
+
[*Note 5*: A *using-declaration* in a derived class `C` that names an
|
| 141 |
assignment operator from a base class never suppresses the implicit
|
| 142 |
declaration of an assignment operator of `C`, even if the base class
|
| 143 |
assignment operator would be a copy or move assignment operator if
|
| 144 |
declared as a member of `C`. — *end note*]
|
| 145 |
|
| 146 |
A copy/move assignment operator for class `X` is trivial if it is not
|
| 147 |
+
user-provided and if
|
| 148 |
|
| 149 |
- class `X` has no virtual functions [[class.virtual]] and no virtual
|
| 150 |
base classes [[class.mi]], and
|
| 151 |
- the assignment operator selected to copy/move each direct base class
|
| 152 |
subobject is trivial, and
|
|
|
|
| 162 |
Before the defaulted copy/move assignment operator for a class is
|
| 163 |
implicitly defined, all non-user-provided copy/move assignment operators
|
| 164 |
for its direct base classes and its non-static data members are
|
| 165 |
implicitly defined.
|
| 166 |
|
| 167 |
+
[*Note 6*: An implicitly-declared copy/move assignment operator has an
|
| 168 |
implied exception specification [[except.spec]]. — *end note*]
|
| 169 |
|
| 170 |
The implicitly-defined copy/move assignment operator for a non-union
|
| 171 |
class `X` performs memberwise copy/move assignment of its subobjects.
|
| 172 |
The direct base classes of `X` are assigned first, in the order of their
|