Boost logo

Boost :

From: Daniel Frey (d.frey_at_[hidden])
Date: 2008-04-29 17:42:26


On Tue, 2008-04-29 at 20:03 +0300, Peter Dimov wrote:
> My current line of thinking is that they should not, as even Frank is having
> second thoughts about it. But I haven't made up my mind yet. There's not
> much time left though.

Trying to implement enable_shared_from_this with only the public
interface of shared_ptr, weak_ptr, etc. (and of course sp_accept_owner
and sp_deleter_wrapper) turns out to be a good test for completeness
IMHO.

I tried to do this and found one thing that I cannot do with the current
implementation of weak_ptr: I cannot test if it's empty. It lacks the
conversion to bool, similar to shared_ptr. Or is there any way to do
this I missed?

I attached a patch (tested, passing all regression tests) to turn the
current trunk version into a more reference-like implementation. It
shows that conversion for bool of a weak_ptr is a desirable feature (see
init_weak_once), since only now I understand what _owner was really
meant for: It worked around the lack of weak_ptr conversion to bool by
manually tracking it's internal state.

In case conversion to bool seems to dangerous to you, I'd suggest to add
at least an explicit method to test for px != 0 (.empty()?), to allow
implementations to avoid tracking internal state manually.

Regards, Daniel




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk