
Emil Dotchevski wrote:
I'd like to request the following functions added to shared_ptr's interface:
template <class T> void * shared_ptr<T>::void_cast() const;
I'd rather spell that 'pointer()' or something along those lines for consistency with 'type()'.
template <class T> std::type_info const & shared_ptr<T>::type() const;
There's an interesting ambiguity here. The easy case is X * px = new X; shared_ptr<void> pv( px ); where pv->pointer() == px && pv->type() == typeid(X). But consider the following slightly more interesting example: struct Base { virtual ~Base() {} }; struct Derived: Base { int i; }; Derived * pd = new Derived; Base * pb = pd; shared_ptr<void> pv( pb ); Now there are two reasonable interpretations; either pv->pointer() == pb && pv->type() == typeid(Base); or pv->pointer() == pd && pv->type() == typeid(Derived); Which one should shared_ptr pick?