Boost logo

Boost Users :

Subject: Re: [Boost-users] scoped_ptr::release (again)
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2009-02-21 02:57:21


Yang Zhang skrev:
> From http://www.boost.org/doc/libs/1_36_0/libs/smart_ptr/scoped_ptr.htm:
>
> "If scoped_ptr had a release() member, it would become possible to
> transfer ownership of the held pointer, weakening its role as a way of
> limiting resource lifetime to a given context. Use std::auto_ptr where
> transfer of ownership is required. (supplied by Dave Abrahams)"
>
> But there already is a way to escape the scope, via swap().
>
> Would it make more sense to just provide release() and have users
> specify const if they want? (const scoped_ptr/scoped_array would
> effectively disallow swapping/releasing.)

FWIW, I think scoped_ptr/scoped_array should have a release() member.
The defining aspects of std::auto_ptr is its ability to transfer
ownership transparently, not that it has a release member.

Especially when working with legacy code, release() is necessary.
Therefore it is a great pity that the member is not provided.
In my view this categorises as over-encapsulation.

best regards

Thorsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net