Re: finding about move vs copy in C++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 31 December 2014 at 10:55, Anthony Shipman wrote:
> On Wed, 31 Dec 2014 09:18:35 pm Jonathan Wakely wrote:
>> What exactly are you worried about, the compiler failing to perform
>> moves, or your code missing opportunities to move?
>>
>> The former will very rarely be a problem, the latter can be solved by
>> understanding the language better.
>>
> Well there's the rub. When there may or may not be an automatically generated
> move assignment or constructor

That's easy to know. It's better to get into the habit of declaring
defaulted move operations anyway, instead of relying on implicitly
generated ones.

> and the compiler may or may not choose a move
> based on the risk of an exception being thrown

Nope, the compiler makes no such choice. The standard library might
choose not to move in such cases, but it does so by initializing
copies from lvalues not rvalues, so the compiler has no choice about
whether to move or not.

> and with the return value
> optimisation etc it's rather difficult to predict exactly what will happen.

If the source object is an rvalue or is a local variable being
returned from a function then it's eligble for moving. Otherwise not.
That covers pretty much every common case.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux