From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2006-10-25 17:18:31
I think it would be useful to add the following features to shared_ptr:
1. Support for aliasing: if I have a shared_ptr<T> pt, to get a
shared_ptr<Y> py (where T and Y are possibly unrelated types) such that pt
and py share ownership. For example, if T is an array of elements of type Y,
with this feature pointing an element from the array through a shared_ptr<Y>
would keep the entire array afloat. Similar example is being able to point
through a shared_ptr<Y> to a member of an object of class T, which would
keep the entire T object afloat.
2. Support for obtaining (as a void *) the address of the original object
passed to shared_ptr when the object was first created. That is, if we have
a shared_ptr<T> pt( new T ), which is later converted to a shared_ptr<Y> py,
I can call py.most_derived_ptr() to obtain the pointer returned by "new T"
as a void *. Note that in general, most_derived_ptr has different semantics
than dynamic_cast<void *>(py.get()): most_derived_ptr returns the same
pointer that the deleter sees, while the dynamic_cast works with the pointer
contained in the shared_ptr object. Also, dynamic_cast<void *>(pt.get())
requires that T is polymorphic, and shared_ptr has been carefuly designed to
avoid this requirement.
3. Support for obtaining the std::type_info of the original object.
I have not done any research on this, and it seems to me that these features
are a natural extension of the shared_ptr framework so it's likely that
others have had similar ideas before me. If anyone has experience with
implementing or using these features, I'm very interested to get some
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk