Boost logo

Boost Users :

From: Alan M. Carroll (amc_at_[hidden])
Date: 2008-08-10 12:47:30


I greatly prefer intrusive_ptr to shared_ptr, but one drawback of that is there is no equivalent of weak_ptr. I have started work on a class to do that and my biggest question, honestly, was what to name it.

The basic logic turned out to be fairly simple. The target class declares a member that is an instance of the weak pointer. Other classes that want a weak pointer to the target instance also declare a member weak pointer, which must be initialized with a copy of the target instance member. The member provides a method to generate an intrusive_ptr to the target, which is either valid or nil depending on whether the target has been destructed. When the target and all weak pointers are destructed, everything gets cleaned up. The weak pointers don't affect the target reference count. No changes to Boost.intrusive_ptr are required. The one improvement I see would be to merge it into the reference counter utility class discussed earlier (optionally, of course - perhaps via a subclass of the reference counter). Yeah, I think I'll do that.

My questions:

1) What would be a good name for such a class? I am using "tell_tale" for now, in analogy to tell tale lights on devices that go out when the device fails. Obviously "weak_ptr" is out. "weak_intrusive_ptr" seems a bit verbose, but may that's OK.

2) Is there any interest in Boostifying the class, or am I the only one who would use it? It's a matter of how much I indulge my idiosyncrasies.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net