Boost logo

Boost :

From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-07-29 13:40:23


Mathias Gaunard wrote:
> 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.

Why do you insist on calling move assignment "casting and unsafe magic"?
Ok. The value of a moved-from object is unspecified, but that is no
reason to make it far more dangerous.

> It's
> the same with regular empty objects: you have to make sure you do not
> access them.

No it isn't the same. There are some operations that ought to be
valid for any object, regardless of whether it is empty or not.
In particular if an type supports assignment, it should /always/
be safe to assign a new value to to an object of that type.

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

If an algorithm leaves, certain values in an unspecified state,
it is not safer to use swap to force them into a specific state
internally to the algorithm. It is clearer to use a move because
move means "I want a to hold the value that b held, and I don't
care what b holds." In addition, for all I care, a = std::move(b)
could be implemented as swap(a, b) for some types.

In Christ,
Steven Watanabe

Boost list run by bdawes at, gregod at, cpdaniel at, john at