$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
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 
> like:
> 
>   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 
> ownership,
> 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
    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.
Aleksey