Boost logo

Boost :

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


From: "Fernando Cacciola" <fcacciola_at_[hidden]>
> I wonder if this could be confusing: shared_ptr uses a detached or
intrusive
> count depending on how it is constructed.... I find more intuitive to
expect
> that shared_ptr uses a detached or intrusive count depending on the
pointee
> type, regardless of how you create it.

Let's assume that shared_ptr autodetects. Consider my original example:

// some member function

shared_ptr<this_type> f()
{
    return shared_ptr<this_type>(this);
}

Is this correct? Yes, if this_type is derived from counted_base, undefined
behavior otherwise.

Now consider the explicit version:

// some member function

shared_ptr<this_type> f()
{
    return intrusive_ptr<this_type>(this);
}

Now the compiler can verify the correctness.

It's always better when the correctness of the code can be determined
without context.


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