Boost logo

Boost :

From: Pavel Vasiliev (pavel_at_[hidden])
Date: 2003-02-03 11:18:58


>> The advantage is that with void*-based implementation...

> There are no significant drawbacks that I can see.

> The only drawback is that with a void * px it's easier to create a broken
> implementation that will almost work. For example

> template<class Y> shared_ptr<T>::shared_ptr(shared_ptr<Y> const & rhs):
> px(rhs.px), pn(rhs.pn) {}

> is buggy, and should now be

> template<class Y> shared_ptr<T>::shared_ptr(shared_ptr<Y> const & rhs):
> px(static_cast<T*>(rhs.get())), pn(rhs.pn) {}

Yes, this needs much care. One must use something like:

// Will not compile if there is no implicit conversion from U* to T*.
template <typename T, typename U>
inline
T* implc(U *pU) // nothrow
{
    return pU;
}

(this is taken from the implementation of refc_ptr)
and then

template<class Y> shared_ptr<T>::shared_ptr(shared_ptr<Y> const & rhs):
px(implc<T>(rhs.get())), pn(rhs.pn) {}

Since the smart pointers are especially useful when stored in std
containers instead of raw pointers, may be it worth troubles to
specialize containers for their void*-based versions? Both
boost::shared_ptr and my (newly proposed) refc_ptr potentially allow
this.


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