Subject: Re: [boost] scoped_ptr deleter
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-09-16 09:29:15
> Dmitry Goncharov wrote:
> > Andrey Semashev wrote:
> > > Noncopyable nature doesn't mean its type is insignificant. This change
> > > would break the interface as the following code won't work anymore:
> > >
> > > template< template< typename > class Ptr >
> > > void make_a(Ptr< A >& p);
> > >
> > > scoped_ptr< A > p;
> > > make_a(p);
> > >
> > > This may not be the most frequent use pattern but nonetheless it's valid.
> > The difficulty that your example demonstrates is caused by
> > the nature
> > of template template parameters. scoped_ptr should not be
> > blamed for that.
> I agree, moreover I think that the advantages of this patch (often
> required in the list) justify the 1% use cases of Andrey Semashev's
> sample that in my opinion can be simplified in this way:
> template<typename T, typename P>
> void make_ptr(P &p)
> p.reset(new T());
I think you meant "p.reset(new T);".
Andrey's example is clearly unusual, but is not likely to be as trivial as you show (if you actually meant to illustrate Andrey's implied implementation). Clearly, make_a() can do any amount of work to create the pointer to put into p. I'd expect most use cases to be satisfied with a helper function that returns a raw pointer that it used to initialize a scoped_ptr rather than this approach, but there may be a non-obvious reason for it.
Your version is as easy to use and provides the same flexibility, so it is an easy change to make and loses no functionality. Specialization is slightly more verbose, of course, but that shouldn't be a big deal either. Therefore, it is reasonable to break what little code follows Andrey's approach.
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk