Re: an intrusive smart pointer
In article <memo.20071230150549.3896A@brangdon.cix.compulink.co.uk>,
Dave Harris <brangdon@ntlworld.com> wrote:
cbarron413@adelphia.net (Carl Barron) wrote (abridged):
see intrusive_ptr at www.boost.org.
Can you explain how it solves the problem? As far as I can tell from:
http://www.boost.org./libs/smart_ptr/intrusive_ptr.html
it punts. It provides a constructor:
intrusive_ptr(T * p, bool add_ref = true);
which add-refs by default. To support objects that increment the count in
their constructor we have to avoid the syntax:
intrusive_ptr<T> p = new T();
even though this is natural and compiles. The library also supports
objects that don't increment the count in their constructor, and I see no
hint as to how the problem of premature deletion inside the constructor
is addressed. It seems to me it leaves the problem in the lap of the
user.
Or is your point that if boost can't solve it, nobody can?
My point is that 99% of your problem is solved as is in intrusive_ptr
and the only apparent problem of using it is that the ctor taking a T *
has a default parameter to add to the reference count and you want that
to default to be false. So the solution is write a smart ptr similiar
to intrusive_ptr<T> but have a ctor that defaults the bool to false
instead of true. So coding your smart ptr should now be fairly easy.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]