|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-04-16 15:06:53
Ion Gaztañaga wrote:
> For objects that have no such default-state, and have no resource
> reassignment functions (like reset() or similar) there is no problem
> because there is no interface to reuse the object.
I think I was with you until this point. It seems to me that the exact
opposite is true; objects that have no "empty" or "default" state cannot
implement a move, at least not easily, whereas reusing a moved-from object
via assignment or reset is no problem at all.
FWIW, I've changed the shared_ptr move constructors and assignment operators
to leave the source empty, but this doesn't mean that I'm convinced that the
general case needs to be constrained in such a way. In particular,
T& operator=( T && r )
{
swap( r );
return *this;
}
seems a very reasonable implementation of move assignment, and has a slight
performance advantage (one call to ~T instead of two in a typical use case)
over
T& operator=( T && r )
{
T( move( r ) ).swap( *this );
return *this;
}
which is what is needed for r to be left empty.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk