Possible Duplicate:
What can I do with a moved-from object?
For example, see this code:
template<class T>
void swap(T& a, T& b)
{
T tmp(std::move(a));
a = std::move(b);
b = std::move(tmp);
}
Is it just me, or is there a bug here? If you move
a
into tmp
, then doesn't a
become invalid?
i.e. Shouldn't the move-assignment to a
from b
be a move-constructor call with placement new
instead?
If not, then what's the difference between the move constructor and move assignment operator?
template<class T>
void swap(T& a, T& b)
{
T tmp(std::move(a));
new(&a) T(std::move(b));
new(&b) T(std::move(tmp));
}