|
Boost : |
From: Beman Dawes (bdawes_at_[hidden])
Date: 2008-07-15 09:27:01
Johan Torp wrote:
>
> Loïc Joly-2 wrote:
>> I was wondering whether there was any plan to implement a unique_ptr in
>> boost, that would replace scoped_ptr, and would default to scoped_ptr on
>> compilers lacking move semantic?
>>
>
> While std::unique_ptr and std::shared_ptr together cover a lot of
> functionality, I don't think boost::scoped_ptr should be changed or removed.
>
> In some sense, scoped_ptr provides better static guarantees than unique_ptr.
> If you see a scoped_ptr declared at function scope you can be sure that it
> is deallocated when the function exits (unless someone abuses it with
> get()+reset(0)). A unique_ptr might transfer it ownership elsewhere.
>
> So scoped_ptr's type tells us something and there is probably lots of code
> out there which wants to convey this information. Therefor we shouldn't
> change it's semantics. Also, scoped_ptr and auto_ptr are more lightweight
> since they do not have the extra level of indirection that a custom deleter
> requires.
Strongly agree.
Many of my uses of scoped_ptr are in industrial code that will be
maintained for years or even decades by programmers with very limited
familiarity with the code involved. scoped_ptr communicates both to the
maintainer and the compiler that ownership is never transfered. That is
critical enough to justify a separate type, even though in other
respects it is the same as unique_ptr.
--Beman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk