Boost logo

Boost :

Subject: Re: [boost] several messages
From: Marc Glisse (marc.glisse_at_[hidden])
Date: 2012-08-05 08:57:38


On Sun, 5 Aug 2012, John Maddock wrote:

>> Well, what happens then if you do something to a moved-from object other
>> than destructing it?
>>
>> number a=2;
>> number b=move(a);
>> a=2; // or a=b; or a=b+1; or ...
>
> It blows up your computer ;-)
>
> IMO It's a constraint (and the intent of move semantics), that moved-from
> objects can only be destroyed: if you require that the moved-from object
> remain usable, then move-assign become identical to a regular assign, and
> move semantics are basically useless. Not just for this lib, but for the std
> lib as well.

That doesn't match my understanding. What I got from previous discussions
is that you need to be able to assign to a moved-from object.

For instance, std::swap will only work for you if you implemented move
assignment as a swap. vector::insert will move elements to the right (one
move construction, the rest are move assignments) and then copy-assign a
new value to the moved-from hole (at least that's how it is implemented in
libcxx).

-- 
Marc Glisse

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