Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2001-04-05 09:41:04


At 12:09 AM 4/5/2001, jk_at_[hidden] wrote:

>5 Apr 2001 04:38:59 +0400 David Abrahams wrote:
>>numbers of arguments. The kind of templates needed to do complete
function
>>argument deduction are one example. Another example is the that of
>>"forwarding constructors" for such things as smart pointers (i.e.
imagine
>>you could construct auto_ptr<T> with the arguments that get passed to
any
>of
>>T's constructors, thereby building the referent). I had to use these all
>
>Do you mean this:
>
> boost::shared_ptr<foo> bar(x, 1, "buz");
>
>instead of
>
> boost::shared_ptr<foo> bar(new foo(x, 1, "buz"));

Yes. I've run some smart pointer experiments, and the templated forwarding
constructors technique really works. But as Dave points out, the technique
is currently limited by having to anticipate how many parameters might ever
be needed, and by parameter type issues.

Having the smart pointer do the construction of the pointed to object
eliminates a potent source of errors. There are reports from the field
that these errors (passing the same pointer to multiple smart pointers) do
occur in practice, even among experienced programmers, and are very
difficult to debug.

>What chances that boost::smart_ptr will be eventually modified?

Either the boost smart pointers would be modified, or a new
smart_pointer_generator<> would use the technique, or both.

--Beman


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