Question Details

No question body available.

Tags

c++ c++11 return-value-optimization

Answers (2)

September 2, 2025 Score: 14 Rep: 339 Quality: High Completeness: 90%

In C++17 this is no longer an "Optimization", but part of the "Language Semantics".

Or, more generally, in C++14 a temporary object is first created and then moved to dl. But in C++17, according to the principle of guaranteed copy elision , the object is created directly in dl. So, in the end, neither a copy nor a move is performed.

Resources:

September 9, 2025 Score: 1 Rep: 280,958 Quality: Medium Completeness: 80%

added "guaranteed elision". With guaranteed elision, prvalues are not materialized until needed. When used to construct an object, they directly construct the object.

In , prvalues are temporary objects, and in certain circumstances the move construction is permitted to be skipped and you can merge to objects into one lifetime.

The difference is here:

struct Data { Data() { std::cout