|
Boost : |
Subject: Re: [boost] several messages
From: John Maddock (boost.regex_at_[hidden])
Date: 2012-08-05 08:05:09
>> The move constructor doesn't allocate - it takes ownership of the GMP
>> variable, and sets the variable in the moved-from object to a null state.
>> The *destructor* then has an added check to ensure it doesn't try and
>> clear null GMP objects: that's basically the only change. IMO the cost
>> of the extra if statement in the destructor is worth it - and should be
>> trivial compared to calling the external library routine to clear the GMP
>> variable.
>
> 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.
John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk