Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-08-30 12:01:43

From: "Larry Evans" <jcampbell3_at_[hidden]>

> David Abrahams wrote:

> >Isn't it time, finally, to stick the allocation inside a factory
> >for the outer shared pointer object so that the user never has to touch
> >
> >
> If I understand you, then this factory function creates and returns an
> instance of placed_ptr<T>
> by doing the allocation for T (and the refcount), calling the
> appropriate T CTOR, and then
> returning the placed_ptr<T>. If so, then it suffers the same
> disadvantage which Philippe
> objected to earlier, i.e. it would require duplicating the T CTOR
> interface in the factor method.

No, you do it generically with a family of overloaded function templates.

> However, despite Philippe's objection, I'm still in favor of this
> approach since it's harder
> for the programmer to go wrong. I mentioned this earlier:
> but there's obviously different views on how idiot-proof the code should
> be. I also made
> the same point about shared_ptr, but Peter had some objections to that
> too. I can't remember
> the details.

It's the "forwarding function" problem. The language as currently specified
would require users to use boost::ref() to pass non-const references, and
would require the factory function implementation to use
boost::unwrap_reference to get the reference out.

           David Abrahams * Boost Consulting
dave_at_[hidden] *

Boost list run by bdawes at, gregod at, cpdaniel at, john at