tmp/tmp_tym8hxd/{from.md → to.md}
RENAMED
|
@@ -1,16 +1,16 @@
|
|
| 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 |
-
parameter of type `X`, `X&`, `const X&`, `volatile X&`, or
|
| 6 |
`const volatile X&`.[^4]
|
| 7 |
|
| 8 |
[*Note 1*: An overloaded assignment operator must be declared to have
|
| 9 |
only one parameter; see [[over.ass]]. — *end note*]
|
| 10 |
|
| 11 |
-
[*Note 2*: More than one form of copy assignment operator
|
| 12 |
declared for a class. — *end note*]
|
| 13 |
|
| 14 |
[*Note 3*:
|
| 15 |
|
| 16 |
If a class `X` only has a copy assignment operator with a parameter of
|
|
@@ -36,12 +36,12 @@ void f() {
|
|
| 36 |
— *end note*]
|
| 37 |
|
| 38 |
If the class definition does not explicitly declare a copy assignment
|
| 39 |
operator, one is declared *implicitly*. If the class definition declares
|
| 40 |
a move constructor or move assignment operator, the implicitly declared
|
| 41 |
-
copy assignment operator is defined as deleted; otherwise, it is
|
| 42 |
-
|
| 43 |
has a user-declared copy constructor or a user-declared destructor
|
| 44 |
[[depr.impldec]]. The implicitly-declared copy assignment operator for a
|
| 45 |
class `X` will have the form
|
| 46 |
|
| 47 |
``` cpp
|
|
@@ -63,17 +63,18 @@ the form
|
|
| 63 |
``` cpp
|
| 64 |
X& X::operator=(X&)
|
| 65 |
```
|
| 66 |
|
| 67 |
A user-declared move assignment operator `X::operator=` is a non-static
|
| 68 |
-
non-template member function of class `X` with exactly one
|
| 69 |
-
type `X&&`, `const X&&`, `volatile X&&`, or
|
|
|
|
| 70 |
|
| 71 |
[*Note 4*: An overloaded assignment operator must be declared to have
|
| 72 |
only one parameter; see [[over.ass]]. — *end note*]
|
| 73 |
|
| 74 |
-
[*Note 5*: More than one form of move assignment operator
|
| 75 |
declared for a class. — *end note*]
|
| 76 |
|
| 77 |
If the definition of a class `X` does not explicitly declare a move
|
| 78 |
assignment operator, one will be implicitly declared as defaulted if and
|
| 79 |
only if
|
|
@@ -114,14 +115,12 @@ have the form
|
|
| 114 |
``` cpp
|
| 115 |
X& X::operator=(X&&)
|
| 116 |
```
|
| 117 |
|
| 118 |
The implicitly-declared copy/move assignment operator for class `X` has
|
| 119 |
-
the return type `X&`
|
| 120 |
-
operator is
|
| 121 |
-
implicitly-declared copy/move assignment operator is an inline public
|
| 122 |
-
member of its class.
|
| 123 |
|
| 124 |
A defaulted copy/move assignment operator for class `X` is defined as
|
| 125 |
deleted if `X` has:
|
| 126 |
|
| 127 |
- a variant member with a non-trivial corresponding assignment operator
|
|
@@ -135,23 +134,23 @@ deleted if `X` has:
|
|
| 135 |
corresponding assignment operator, results in an ambiguity or a
|
| 136 |
function that is deleted or inaccessible from the defaulted assignment
|
| 137 |
operator.
|
| 138 |
|
| 139 |
[*Note 6*: A defaulted move assignment operator that is defined as
|
| 140 |
-
deleted is ignored by overload resolution
|
| 141 |
-
[[over.over]]
|
| 142 |
|
| 143 |
Because a copy/move assignment operator is implicitly declared for a
|
| 144 |
class if not declared by the user, a base class copy/move assignment
|
| 145 |
operator is always hidden by the corresponding assignment operator of a
|
| 146 |
-
derived class [[over.ass]].
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
|
| 154 |
A copy/move assignment operator for class `X` is trivial if it is not
|
| 155 |
user-provided and if:
|
| 156 |
|
| 157 |
- class `X` has no virtual functions [[class.virtual]] and no virtual
|
|
@@ -162,31 +161,19 @@ user-provided and if:
|
|
| 162 |
thereof), the assignment operator selected to copy/move that member is
|
| 163 |
trivial;
|
| 164 |
|
| 165 |
otherwise the copy/move assignment operator is *non-trivial*.
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
[[basic.def.odr]] (e.g., when it is selected by overload resolution to
|
| 170 |
-
assign to an object of its class type), when it is needed for constant
|
| 171 |
-
evaluation [[expr.const]], or when it is explicitly defaulted after its
|
| 172 |
-
first declaration. The implicitly-defined copy/move assignment operator
|
| 173 |
-
is `constexpr` if
|
| 174 |
-
|
| 175 |
-
- `X` is a literal type, and
|
| 176 |
-
- the assignment operator selected to copy/move each direct base class
|
| 177 |
-
subobject is a constexpr function, and
|
| 178 |
-
- for each non-static data member of `X` that is of class type (or array
|
| 179 |
-
thereof), the assignment operator selected to copy/move that member is
|
| 180 |
-
a constexpr function.
|
| 181 |
|
| 182 |
Before the defaulted copy/move assignment operator for a class is
|
| 183 |
implicitly defined, all non-user-provided copy/move assignment operators
|
| 184 |
for its direct base classes and its non-static data members are
|
| 185 |
implicitly defined.
|
| 186 |
|
| 187 |
-
[*Note
|
| 188 |
implied exception specification [[except.spec]]. — *end note*]
|
| 189 |
|
| 190 |
The implicitly-defined copy/move assignment operator for a non-union
|
| 191 |
class `X` performs memberwise copy/move assignment of its subobjects.
|
| 192 |
The direct base classes of `X` are assigned first, in the order of their
|
|
@@ -224,12 +211,17 @@ It is unspecified whether the virtual base class subobject `V` is
|
|
| 224 |
assigned twice by the implicitly-defined copy/move assignment operator
|
| 225 |
for `C`.
|
| 226 |
|
| 227 |
— *end example*]
|
| 228 |
|
| 229 |
-
The implicitly-defined copy assignment operator for a union `X`
|
| 230 |
-
the object representation [[
|
| 231 |
-
destination of the assignment are not the same object,
|
| 232 |
-
object nested within [[intro.object]] the object that is
|
| 233 |
-
the copy, a corresponding object o nested within the
|
| 234 |
-
created, and the lifetime of o begins before the copy is
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
|
|
|
| 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&`.[^4]
|
| 7 |
|
| 8 |
[*Note 1*: An overloaded assignment operator must be declared to have
|
| 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 3*:
|
| 15 |
|
| 16 |
If a class `X` only has a copy assignment operator with a parameter of
|
|
|
|
| 36 |
— *end note*]
|
| 37 |
|
| 38 |
If the class definition does not explicitly declare a copy assignment
|
| 39 |
operator, one is declared *implicitly*. If the class definition declares
|
| 40 |
a move constructor or move assignment operator, the implicitly declared
|
| 41 |
+
copy assignment operator is defined as deleted; otherwise, it is
|
| 42 |
+
defaulted [[dcl.fct.def]]. The latter case is deprecated if the class
|
| 43 |
has a user-declared copy constructor or a user-declared destructor
|
| 44 |
[[depr.impldec]]. The implicitly-declared copy assignment operator for a
|
| 45 |
class `X` will have the form
|
| 46 |
|
| 47 |
``` cpp
|
|
|
|
| 63 |
``` cpp
|
| 64 |
X& X::operator=(X&)
|
| 65 |
```
|
| 66 |
|
| 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 4*: An overloaded assignment operator must be declared to have
|
| 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
|
|
|
|
| 115 |
``` cpp
|
| 116 |
X& X::operator=(X&&)
|
| 117 |
```
|
| 118 |
|
| 119 |
The implicitly-declared copy/move assignment operator for class `X` has
|
| 120 |
+
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 variant member with a non-trivial corresponding assignment operator
|
|
|
|
| 134 |
corresponding assignment operator, results in an ambiguity or a
|
| 135 |
function that is deleted or inaccessible from the defaulted assignment
|
| 136 |
operator.
|
| 137 |
|
| 138 |
[*Note 6*: A defaulted move assignment operator that is defined as
|
| 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.ass]].
|
| 146 |
+
|
| 147 |
+
[*Note 7*: A *using-declaration* in a derived class `C` that names an
|
| 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
|
|
|
|
| 161 |
thereof), the assignment operator selected to copy/move that member is
|
| 162 |
trivial;
|
| 163 |
|
| 164 |
otherwise the copy/move assignment operator is *non-trivial*.
|
| 165 |
|
| 166 |
+
An implicitly-defined [[dcl.fct.def.default]] copy/move assignment
|
| 167 |
+
operator is `constexpr`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 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 8*: An implicitly-declared copy/move assignment operator has an
|
| 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
|
|
|
|
| 211 |
assigned twice by the implicitly-defined copy/move assignment operator
|
| 212 |
for `C`.
|
| 213 |
|
| 214 |
— *end example*]
|
| 215 |
|
| 216 |
+
The implicitly-defined copy/move assignment operator for a union `X`
|
| 217 |
+
copies the object representation [[term.object.representation]] of `X`.
|
| 218 |
+
If the source and destination of the assignment are not the same object,
|
| 219 |
+
then for each object nested within [[intro.object]] the object that is
|
| 220 |
+
the source of the copy, a corresponding object o nested within the
|
| 221 |
+
destination is created, and the lifetime of o begins before the copy is
|
| 222 |
+
performed.
|
| 223 |
+
|
| 224 |
+
The implicitly-defined copy/move assignment operator for a class returns
|
| 225 |
+
the object for which the assignment operator is invoked, that is, the
|
| 226 |
+
object assigned to.
|
| 227 |
|