Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-04-24 05:23:20

I've changed the shared_ptr(T *) constructor to a member template,
template<class Y> shared_ptr(Y *).

This allows code like shared_ptr<void> pv(new int) or shared_ptr<X> px(new
Y) (where X doesn't have a virtual destructor) to do the right thing. The
former equivalent was the more verbose shared_ptr<X> px = shared_ptr<Y>(new

This breaks some existing code since '0' is no longer an acceptable
argument; for instance, px.reset(0) needs to be rewritten as px.reset().

I'm still undecided about the case where Y is derived from counted_base. The
current behavior doesn't detect this and allocates an external reference
count; having two separate reference counts for the same object is almost
always a mistake.

On the other hand, making the constructor autodetect is a semantic overload
(a single function with multiple behaviors) which is typically to be avoided
(it breaks the use_count() == 1 postcondition in some cases.)

Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at, gregod at, cpdaniel at, john at