Dear Gavin,
On 15. Nov 2017, at 07:58, Gavin Lambert via Boost
wrote: On 15/11/2017 19:27, Gevorg Voskanyan wrote:
On 11/15/17 03:04, Gavin Lambert wrote:
Given that NRVO is mandatory now, <snip> It is? Since when? AFAIK C++17 makes RVO mandatory, but not NRVO.
True, I was thinking of a different case and misspoke. The rest of the post still stands though; any optimiser worth its salt should be able to apply NVRO there and elide most if not all of the copies, and it should be safer without sacrificing performance.
Granted that I have not actually measured this, and so might end up surprised.
I played around with the two versions of operators, the one returning rvalue references and the ones you suggested that might apply NVRO. https://github.com/HDembinski/testing_grounds/blob/master/test/test_fast_ope... https://github.com/HDembinski/testing_grounds/blob/master/test/test_fast_ope... On Apple Clang 9.0.0, NVRO does not seem to work, but perhaps I am not tracking this correctly. I use this class to track copying calls: static unsigned ctor_count = 0; struct A { A() { ++ctor_count; } A(const A&) { ++ctor_count; } A& operator=(const A&) { ++ctor_count; return *this; } A(A&&) {} A& operator=(A&&) { return *this; } A& operator+=(const A&) { return *this; } }; Best regards, Hans