Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-30 12:24:16

From: "Howard Hinnant" <hinnant_at_[hidden]>
> "Howard Hinnant" <hinnant_at_[hidden]> wrote in message
> >> And whatever that smart pointer is called, I think:
> >>
> >> initialize(std::auto_ptr<X>& p) {
> >> px_.reset(p.release());
> >> }
> >>
> >> is much preferred since it explicitly says what is happening, and
> >> decouples typeof(px_) from std::auto_ptr.
> >>
> >> Sometimes less is more.

First let me say that I prefer not to add scoped_ptr::reset(auto_ptr), as I
consider the release() form good enough. The situation pictured above is
relatively rare.

> On Monday, September 30, 2002, at 12:13 PM, Ed Brey wrote:
> > I infer from this that you would then be in favor of dropping the
> > auto_ptr overload on the constructor.
> Yes, that is a fair statement (and dropping reset too). Although I
> should qualify this statement with one of backward compatibility and
> migration. We can't do what I suggest until there has been an
> alternative smart pointer available for some period of time.

To put things in perspective:

Greg Colvin (17.06.2002): "I don't see any reason not to provide this
Dave Abrahams (18.06.2002): "I support the change to scoped_ptr."

> Agree 100% that you need transfer semantics for this application. I
> think we need another smart pointer.

>From Beman's post-Curaçao notes:

"* Proliferation of Standard Library smart pointers is a serious concern; if
a policy-based smart pointer and a compatible shared_ptr were available,
they would be preferred; scoped_ptr, scoped_array, and shared_array were
not viewed favorably by many LWG members."

> > A related question is how does adding the word release make the
> > example any clearer, unless you would also do the same when
> > transfering to shared_ptr?
> I'm all for consistency! :-)

shared_ptr's case is different, as its reset is allowed to throw:

shared_ptr<X> px;
auto_ptr<X> px2;

px = px2; // strong guarantee, px2 unchanged if reset throws
px.reset(px2.release()); // px2 NULL, object destroyed if reset throws

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