Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-05-07 04:15:56


Hi Edouard,

Sorry for the late reply.

Edouard Poor wrote:
> In boost::mail_list, Aleksey Gurtovoy wrote:
>
> > Noel Yap wrote:
> >
> > > extern C* blah(); // should pointer be free'd by caller?
> > >
> > > If, instead, I could do:
> > >
> > > extern dumb_ptr< C > blah();
> > >
> > > the intent is clearer.
> >
> > Definitely. Here at work we would write the above as
> >
> > ref_ptr<C,!0> blah();
> >
> > or, if 'blah' _can_ return a null pointer,
> >
> > ref_ptr<C> blah();
> >
> > "Cannot-be-zero" part helps to get rid of lots of asserts (and
> > some bugs); we love it :). Of course, you need other smart pointers
> > to be cooperative with this one; e.g. life becomes much easier if
> > all the owning pointers are implicitly convertible to 'ref_ptr's.
>
> You didn't say, and no-one subsequently asked, but how does that work
> then? "!0" as a template argument?

Oh, that one is easy - !0 is simply a compile-time bool constant :).

> What, roughly, does your ref_ptr class look like?

Not quite roughly, but here -
http://www.meta-comm.com/engineering/resources/ref_ptr.h.

Aleksey


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