Boost logo

Boost :

From: Phil Bouchard (philippe_at_[hidden])
Date: 2008-08-28 03:15:57

As it turns out I think a release() member function should be added to the
smart pointer. Its purpose is to give away ownership of the object. See
the following pseudo-code:

template <typename T>
    class smart_ptr
        smart_ptr(element_type *);

        value_type * get();

        element_type * release()
            element_type * __p = pointer_ref();

            pointer_ref() = 0;

            if (-- counter_ref())
                return 0;
                return __p;

It follows the same idea of its predecessor auto_ptr<> but will return a
null pointer if the object is still shared thus not ready to be deleted.
This way the allocator will be much easier to support either by calling this
function before deallocate(), inside it or by using a specialized wrapper
class to handle it:

template <typename T>
    class allocator
        typedef smart_ptr<T> pointer;

        void deallocate(pointer & __p)
            delete p.release();


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