|
Boost : |
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2008-07-29 12:57:23
Steven Watanabe wrote:
> This only provides yet another way to assign (And to get undefined
> behavior if you forget to use the right function).
>
> a = b; // a must not have been moved from
> a = move(b); // ditto
> reassign(a, b); // a may have been moved from. doesn't even provide
> basic exception safety.
> reassign(a, std::move(b)); // a may have been moved from. Exception
> safe as long as the move constructor can't throw.
>
> I thought that you were advocating safety?
As I said, moving lvalues is unsafe, since you should treat them like
rvalues and thus do not access them later.
Since you casted and did unsafe magic, you have to be careful whether
the objects you are manipulating are in a moved/empty state or not. It's
the same with regular empty objects: you have to make sure you do not
access them.
At least, if you allow a non-empty object to be assigned to a empty one,
but not the other way around, emptiness cannot propagate.
About the exception-safety issue, I assume constructing an empty value
to put back in a should be nothrow.
>
>> Anyway, I'm pretty sure that function could be purely implemented in
>> terms of swap, which seems like a safer construct.
>>
>
> Sure it could be implemented in terms of swap, but I disagree that
> swap is safer than proper move assignment.
It is, since you're not letting any object in any empty state that
obviously has only limited abilities.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk