Boost logo

Boost :

Subject: Re: [boost] several messages
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2012-08-05 12:39:26


On Sun, Aug 5, 2012 at 5:57 AM, Marc Glisse <marc.glisse_at_[hidden]> wrote:

> 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).
>

I believe Marc is correct. You must be able to destruct *and* assign-to a
moved-from object.

- Jeff


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