Boost logo

Boost :

From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2007-05-21 14:42:22


I'd like to request the following functions added to shared_ptr's interface:

template <class T>
void * shared_ptr<T>::void_cast() const;

template <class T>
std::type_info const & shared_ptr<T>::type() const;

The first function mimics the use of dynamic_cast<void *>(p) for pointers to
polymorphic objects. The second function is similar to typeid(r), for
references to polymorphic objects. Of course, void_cast needs to be
specialized to apply the correct modifiers of T to the returned pointer
type.

There are two scenarios that need those functions:

- when using shared_ptr<T> in contexts where T is incomplete (or void);

- when the T in shared_ptr<T> has nothing to do with the type of the object
managed by the shared_ptr's control block. For example, through the recently
introduced aliasing constructor, it is possible for a shared_ptr<int> to
manage the lifetime of an object of some user-defined type that has the int
as a member.

Both functions are critical for implementing proper serialization of
shared_ptr objects.

Emil Dotchevski


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