Boost logo

Boost :

Subject: Re: [boost] Improving the assignment operators of various Boosttypes
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-09-11 04:29:59


On Thu, Sep 11, 2008 at 9:34 AM, Gevorg Voskanyan <v_gevorg_at_[hidden]> wrote:
> Giovanni Piero Deretta wrote:
>
>> If you do not want to deal with move emulation (which I've found very
>> brittle in complex expressions), a simple way to to gain the advantage
>> of T::operator=(T rhs) even when assigning from lvalues is something
>> like:
>>
>> templateT destructive_copy(T& x) {
>> using std::swap;
>> T result;
>> swap(result, x);
>> return x;
>> }
>>
>> which relies on NRVO to eliminate expensive copies:
>
> Shouldn't the last statement be return result; instead? Or maybe I am missing something?
>

Yes, of course :), sorry for the typo...

-- 
gpd

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