Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-10-01 12:53:39

From: "David Abrahams" <dave_at_[hidden]>
> I don't know how long I'll be able to hold this position in the face of
> move semantics, but so far I've been successful at promoting the idea that
> a "destructible but otherwise unusable" state is misguided for most
> classes. One thing I don't like about this arrangement is that is tends to
> encourage that sort of design. I think it might be avoidable by having the
> user inherit from something like this:
> struct intrusive_count
> {
> intrusive_count() : count(new counted_base) {}
> ~intrusive_count() { if (count->weak_count == 0) delete count; }
> counted_base* count;
> };
> Just a thought.

The current situation... leaves something to be desired. It is acceptable;
while the object is in a "zombie state" there should be no references left
to it (unless someone has stored a plain pointer/reference) as weak pointers
no longer hand out a shared_ptr, and it's usually pretty obvious what the
dispose() overload should do. Still, it doesn't "just work".

I think I can make a variation of the above work (interestingly the
destructor has to be empty AFAICS) but OTOH having an embedded count
eliminates one heap allocation.

Subject needs further research.

Boost list run by bdawes at, gregod at, cpdaniel at, john at