Boost logo

Boost :

Subject: Re: [boost] [move] moving temporaries of copyable types
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2009-08-10 10:57:30


David Abrahams escribió:
>> Simply put:
>> <code>
>> clone_ptr<int> return_rvalue()
>> {
>> return clone_ptr<int>(new int(1));
>> }
>>
>> clone_ptr<int> p;
>> // Boost.Move ---> temporary gets copied
>> // my approach ---> temporary gets moved
>> p = return_rvalue();
>> </code>
>
> In both cases the temporary should get RVO'd (i.e. the copy should be
> elided) on all modern compilers. If you can find a modern compiler
> where Boost.Move does not RVO, then its design needs to be fixed.

Yes in case of constructors but not with assigments:

clone_ptr<MyClass> p;

for(){
   p = return_rvalue();
}

Although I guess that this missed optimization might not be so
important. The same could be applied to containers

//With old approach, copied instead
vector.push_back(return_rvalue());

Best,

Ion


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