Boost logo

Boost :

Subject: Re: [boost] [xint] Third release is ready, requesting preliminary review
From: DE (satan66613_at_[hidden])
Date: 2010-05-04 11:16:21


on 04.05.2010 at 15:30
 Stewart, Robert wrote :

> DE wrote:
>> Giovanni Piero Deretta wrote :
>>
>> > No, but swap is your friend:
>>
>> > X operator- (X x) {
>> > modify-in-place x;
>>
>> > X ret; // this should be cheap
>> > ret.swap(x);
>> > return ret; // NRVO should kick in
>> > }
>>
>> i don't think it is a good idea to write such curious code in chase of
>> a _possibility_ (there are no guarantees) of rvo

> That's perfectly reasonable code. Consider
> <http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/>.

i've read the article (rather boring one)

i don't understand how is that different to

  X operator- (const X &x)
  {
    X ret(x);
    //modify 'ret'
    return ret;
  }

what about idiomatic

  return X().swap(x); //x is modified

-- 
Pavel
P.S.
if you notice a grammar mistake or weird phrasing in my message
please point it out

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