From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2008-07-24 10:58:14
Steven Watanabe wrote:
> I don't think that boost::function should provide a never empty guarantee
> for several technical reasons:
> a) Providing the guarantee has a runtime cost. Allowing
> empty Boost.Function objects is free.
It only has a cost if the object doesn't have a no-throw move, and
almost all types should be able to provide that.
> b) Looking forward to C++0x, it is impossible to implement a
> no throw move for objects than have no empty state.
Moving itself almost never needs to throw, I think, except when they
need to register their address in a global collection of something like
The problem is that the destructor will still be called on the old
object, so that object needs to be in a valid deletable state while not
putting any side-effect on the new object.
That does require an empty state in some cases, but that state could
only be reached from the move constructor.
T::T(T&& o) could make 'o' empty, but there could be no other way to
make 'o' empty otherwise.
(I personally wonder if it wouldn't have been better to not call
destructors on moved objects)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk