From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-12-18 12:22:58


Rani Sharoni wrote:

> Why is it important that the shared_ptr(weak_ptr<Y> const & r)
> constructor throws an exception?

If a function's requirements are met, but the postcondition cannot, this
function should throw an exception.

It is not possible to place a !r.expired() requirement on the constructor,
because the user can never enforce it reliably. The only remaining
shared_ptr in r's ownership group may be destroyed (by another thread, for
example) between the r.expired() test and the constructor call.

If you don't want an exception, use r.lock().