Boost logo

Boost :

From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2008-08-28 12:54:12


On Thu, Aug 28, 2008 at 12:27, Michael Marcin <mike.marcin_at_[hidden]> wrote:
> Sebastian Redl wrote:
>>
>> Phil Bouchard wrote:
>>>
>>> As it turns out I think a release() member function should be added to
>>> the smart pointer.
>>
>> Which smart_ptr?
>>
>> I think scoped_ptr should have a release(). It's technically impossible to
>> add a useful one to the refcounted smart pointers.
>>
>
> It works for refcounted smart pointers iff p.unique() == true.
>

Which means it's likely a race condition if you try to do it in a
multi-threaded program, because a weak_ptr could get lock()ed at any
point. Custom deleters also make it quite awkward to handle properly.

Since it would require that only one pointer holds it, it seems like
the correct way to do it is to use unique_ptr instead, which enforces
that invariant.

~ Scott


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