Skip to content

Remove std::move to support copy elision#67

Open
mkindahl wants to merge 1 commit intoadjust:masterfrom
mkindahl:support-copy-elision
Open

Remove std::move to support copy elision#67
mkindahl wants to merge 1 commit intoadjust:masterfrom
mkindahl:support-copy-elision

Conversation

@mkindahl
Copy link

According to the standard, copy elision is allowed (before C++17) or required (since C++17) in the following situation:

In the initialization of an object, when the source object is a nameless temporary and is of the same class type (ignoring cv-qualification) as the target object. When the nameless temporary is the operand of a return statement, this variant of copy elision is known as RVO, "return value optimization".

Unfortunately, using std::move() will block this optimization when initializing an object, so it should not be used. Removing it allows the target object to be constructed in-place rather than being copied using the copy constructor.

According to the standard, copy elision is allowed (before C++17) or
required (since C++17) in the following situation:

In the initialization of an object, when the source object is a
nameless temporary and is of the same class type (ignoring
cv-qualification) as the target object. When the nameless temporary is
the operand of a return statement, this variant of copy elision is
known as RVO, "return value optimization".

Unfortunately, using std::move() will block this optimization when
initializing an object, so it should not be used. Removing it allows
the target object to be constructed in-place rather than being copied
using the copy constructor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant