Boost logo

Boost :

Subject: Re: [boost] [operators] A modern SFINAE-based version of boost::operators?
From: Peter Dimov (lists_at_[hidden])
Date: 2017-11-15 16:41:39

Daniel Frey wrote:
> > On 15. Nov 2017, at 17:05, Peter Dimov via Boost <boost_at_[hidden]>
> > wrote:
> >
> > For those interested, here's a test program with which you can play. The
> > results are, respectively, 0+1, 3+0, 0+3, 0+3, 0+0.
> Nice, thanks for that. But the 0+0 is slightly misleading, as you don't
> copy the value with a copy-ctor, but you initialise a new value directly -
> this should count as well, especially thinking of cases like a matrix-like
> class with, say, an array of NxM elements as a direct member.

True, it does not count the constructions. These are 4 for the += based
variations and 7 for the plain op+.

It's all slightly misleading anyway, because for the small matrix case the
copy/move constructors don't actually have side effects and therefore get
optimized out; they are only relevant in the case of something like
std::string where copy/move aren't defaulted.

Also, the results for

    T t1(1), t2(2), t3(3), t4(4);
    T t = t1 + t2 + t3 + t4;

are slightly different. 4+1+1, 4+3+0, 4+1+2, 4+1+3, 7+0+0.

Boost list run by bdawes at, gregod at, cpdaniel at, john at