From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-04-15 16:06:55
Noel Yap wrote:
> This has probably been asked many times, but here it goes: Why
> doesn't boost have a dumb_ptr<> to replace the "left-over" use of
> free pointers (eg no ownership semantics, copyable, ...)?
> For example, if I wanted to transfer ownership, I'd do something
> extern std::auto_ptr< C > createC();
> OTOH, there's a lot of legacy code that has:
> extern C* createC();
> Which means if I wanted to write a function that doesn't pass
> its ownership semantics is ambiguous:
> 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
or, if 'blah' _can_ return a null pointer,
"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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk