28 Aug 09:13
[smart_ptr] release()
From: Phil Bouchard <philippe <at> fornux.com>
Subject: [smart_ptr] release()
Newsgroups: gmane.comp.lib.boost.devel
Date: 2008-08-28 07:15:57 GMT
Subject: [smart_ptr] release()
Newsgroups: gmane.comp.lib.boost.devel
Date: 2008-08-28 07:15:57 GMT
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;
else
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:
(Continue reading)
RSS Feed