tmp/tmpac_if3nh/{from.md → to.md}
RENAMED
|
@@ -1,57 +1,60 @@
|
|
| 1 |
### Copy/move elision <a id="class.copy.elision">[[class.copy.elision]]</a>
|
| 2 |
|
| 3 |
When certain criteria are met, an implementation is allowed to omit the
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
object have side effects. In such cases, the
|
| 7 |
-
source and target of the omitted
|
| 8 |
-
different ways of referring to the same
|
| 9 |
-
of the selected constructor is an rvalue
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
when the two objects would have been
|
| 13 |
-
optimization.
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
- in a *throw-expression* [[expr.throw]], when the operand is the name
|
| 28 |
-
of a non-volatile object with automatic storage duration (other than
|
| 29 |
-
function
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
- in a coroutine [[dcl.fct.def.coroutine]], a copy of a coroutine
|
| 34 |
parameter can be omitted and references to that copy replaced with
|
| 35 |
references to the corresponding parameter if the meaning of the
|
| 36 |
program will be unchanged except for the execution of a constructor
|
| 37 |
-
and destructor for the parameter copy object
|
| 38 |
-
- when the *exception-declaration* of
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
the object
|
| 45 |
-
cannot be a move from the exception object because it is always an
|
| 46 |
-
lvalue. — *end note*]
|
| 47 |
|
| 48 |
Copy elision is not permitted where an expression is evaluated in a
|
| 49 |
context requiring a constant expression [[expr.const]] and in constant
|
| 50 |
initialization [[basic.start.static]].
|
| 51 |
|
| 52 |
-
[*Note
|
| 53 |
expression is evaluated in another context. — *end note*]
|
| 54 |
|
| 55 |
[*Example 1*:
|
| 56 |
|
| 57 |
``` cpp
|
|
|
|
| 1 |
### Copy/move elision <a id="class.copy.elision">[[class.copy.elision]]</a>
|
| 2 |
|
| 3 |
When certain criteria are met, an implementation is allowed to omit the
|
| 4 |
+
creation of a class object from a source object of the same type
|
| 5 |
+
(ignoring cv-qualification), even if the selected constructor and/or the
|
| 6 |
+
destructor for the object have side effects. In such cases, the
|
| 7 |
+
implementation treats the source and target of the omitted
|
| 8 |
+
initialization as simply two different ways of referring to the same
|
| 9 |
+
object. If the first parameter of the selected constructor is an rvalue
|
| 10 |
+
reference to the object’s type, the destruction of that object occurs
|
| 11 |
+
when the target would have been destroyed; otherwise, the destruction
|
| 12 |
+
occurs at the later of the times when the two objects would have been
|
| 13 |
+
destroyed without the optimization.
|
| 14 |
|
| 15 |
+
[*Note 1*: Because only one object is destroyed instead of two, and the
|
| 16 |
+
creation of one object is omitted, there is still one object destroyed
|
| 17 |
+
for each one constructed. — *end note*]
|
| 18 |
|
| 19 |
+
This elision of object creation, called *copy elision*, is permitted in
|
| 20 |
+
the following circumstances (which may be combined to eliminate multiple
|
| 21 |
+
copies):
|
| 22 |
+
|
| 23 |
+
- in a `return` statement [[stmt.return]] in a function with a class
|
| 24 |
+
return type, when the *expression* is the name of a non-volatile
|
| 25 |
+
object o with automatic storage duration (other than a function
|
| 26 |
+
parameter or a variable introduced by the *exception-declaration* of a
|
| 27 |
+
*handler* [[except.handle]]), the copy-initialization of the result
|
| 28 |
+
object can be omitted by constructing o directly into the function
|
| 29 |
+
call’s result object;
|
| 30 |
- in a *throw-expression* [[expr.throw]], when the operand is the name
|
| 31 |
+
of a non-volatile object o with automatic storage duration (other than
|
| 32 |
+
a function parameter or a variable introduced by the
|
| 33 |
+
*exception-declaration* of a *handler*) that belongs to a scope that
|
| 34 |
+
does not contain the innermost enclosing *compound-statement*
|
| 35 |
+
associated with a *try-block* (if there is one), the
|
| 36 |
+
copy-initialization of the exception object can be omitted by
|
| 37 |
+
constructing o directly into the exception object;
|
| 38 |
- in a coroutine [[dcl.fct.def.coroutine]], a copy of a coroutine
|
| 39 |
parameter can be omitted and references to that copy replaced with
|
| 40 |
references to the corresponding parameter if the meaning of the
|
| 41 |
program will be unchanged except for the execution of a constructor
|
| 42 |
+
and destructor for the parameter copy object;
|
| 43 |
+
- when the *exception-declaration* of a *handler* [[except.handle]]
|
| 44 |
+
declares an object o, the copy-initialization of o can be omitted by
|
| 45 |
+
treating the *exception-declaration* as an alias for the exception
|
| 46 |
+
object if the meaning of the program will be unchanged except for the
|
| 47 |
+
execution of constructors and destructors for the object declared by
|
| 48 |
+
the *exception-declaration*. \[*Note 2*: There cannot be a move from
|
| 49 |
+
the exception object because it is always an lvalue. — *end note*]
|
|
|
|
|
|
|
| 50 |
|
| 51 |
Copy elision is not permitted where an expression is evaluated in a
|
| 52 |
context requiring a constant expression [[expr.const]] and in constant
|
| 53 |
initialization [[basic.start.static]].
|
| 54 |
|
| 55 |
+
[*Note 3*: It is possible that copy elision is performed if the same
|
| 56 |
expression is evaluated in another context. — *end note*]
|
| 57 |
|
| 58 |
[*Example 1*:
|
| 59 |
|
| 60 |
``` cpp
|