Boost logo

Boost :

Subject: Re: [boost] [operators] A modern SFINAE-based version of boost::operators?
From: Hans Dembinski (hans.dembinski_at_[hidden])
Date: 2017-11-15 09:16:24


Dear Gavin,

> On 15. Nov 2017, at 07:58, Gavin Lambert via Boost <boost_at_[hidden]> 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_operators.cpp <https://github.com/HDembinski/testing_grounds/blob/master/test/test_fast_operators.cpp>

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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk