Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove std::move to support copy elision #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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