$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-07-14 05:52:46
Jaap Suter wrote:
> Hi,
>
> a weak_ptr can be said to have three states.
>
> 1. Never been assigned to (default constructed)
> 2. Assigned to, lock will return a shared_ptr to a valid object.
> 3. Assigned to, but the object pointed to is dead and lock will
> return null.
>
> As far as I know it is currently impossible to distinguish between
> case 1
> and 3. Am I overlooking something? If not, can somebody explain the
> reason why it is not possible to distinguish the two cases?
> Admittedly, I cannot come up with any elegant design in which such a
> distinction is useful, so the question is merely theoretical.
There is no particular reason to make 1 and 3 indistinguishable. You are
right that weak_ptr could have provided an "is empty" query in addition to
expired(). There just aren't any compelling use cases for it, as far as I
know.