
David Abrahams escribió:
Simply put: <code> clone_ptr<int> return_rvalue() { return clone_ptr<int>(new int(1)); }
clone_ptr<int> p; // Boost.Move ---> temporary gets copied // my approach ---> temporary gets moved p = return_rvalue(); </code>
In both cases the temporary should get RVO'd (i.e. the copy should be elided) on all modern compilers. If you can find a modern compiler where Boost.Move does not RVO, then its design needs to be fixed.
Yes in case of constructors but not with assigments: clone_ptr<MyClass> p; for(){ p = return_rvalue(); } Although I guess that this missed optimization might not be so important. The same could be applied to containers //With old approach, copied instead vector.push_back(return_rvalue()); Best, Ion