That Someone is me. So let me clear my stand.
I never said that in Box box(Range(0.0,1.0),Range(0.0,2.0))
, the compiler can avoid copying Range objects altogether by constructing them inside box to begin with. What I said was:
Yes it can, In particular this kind of copy elision context falls under the copy elision criterion specified in 12.8/p31.3 Copying and moving class objects [class.copy] of the standard:
(31.3) -- when a temporary class object that has not been bound to a reference
(12.2) would be copied/moved to a class object with the same type
(ignoring cv-qualification), the copy/move operation can be omitted by
constructing the temporary object directly into the target of the
omitted copy/move.
The Yes it can, part goes for the temporary objects passed in the constructor (That can be elide per standard as mentioned above). I never said that the parameters can be elided all the way to the Box
constructor's initializer list.
After all, that case doesn't qualify for any of the criteria where copy elision can be applied as per standard.
I also said that even if a certain context is qualified as a context where copy elision can be applied, the compiler is not obligated to follow. If you rely on that effects then your program is not considered portable.
std::move
for efficiency. – Socinus