Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2006-03-29 07:36:51


On 03/28/2006 05:45 PM, David Abrahams wrote:
> I've developed some facilities that perhaps ought to be developed into
> full-fledged libraries or components of existing Boost libraries.
> This work centers around my long-standing threat to build a library
> that could create smart pointers safely, without ever exposing a raw
> pointer to the user. For example,
[snip]
> std::auto_ptr<foo> y(new_<foo>(*x, "hello, world", x));
> boost::shared_ptr<foo> z(new_<foo>(*x, (char const*)"hello, world", x));

My interpretation of "create smart pointers safely" is that there's no
way the user can "accidentally" create a smart pointer which
"originally" was a raw pointer. Since shared_ptr has a CTOR taking a
raw pointer, this doesn't make shared_ptr "safe". OTOH, even if
the raw pointer CTOR of shared_ptr were removed, there would still be
the shared_ptr CTOR taking an auto_ptr, and since auto_ptr can be
constructed from a raw pointer, this still would not make share_ptr
"safe" since "origin" of the shared_ptr could come from a raw pointer.

AFAICT, the only way a smart pointer can be made "safe" (as defined
above) is to only allow CTOR arguments which are "safe" (w.r.t. raw
pointer origination) themselves. And the only way to do that is
provide a template class having a merge of the properties of
auto_ptr and new_, IOW, it's derived from auto_ptr or contains
an auto_ptr, and the CTOR interface is like the new_ CTOR interface.
e.g. like the auto_overhead I'd mentioned before.

Or maybe I'm misunderstanding your definition of "safe"?


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