Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-05-23 09:39:14


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?


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