Boost logo

Boost :

Subject: Re: [boost] scoped_ptr deleter
From: Stefan Strasser (strasser_at_[hidden])
Date: 2009-09-16 12:08:16


Am Wednesday 16 September 2009 16:01:00 schrieb Felipe Magno de Almeida:
> On Wed, Sep 16, 2009 at 12:54 PM, Stefan Strasser
>
> <strasser_at_[hidden]> wrote:
> > Am Wednesday 16 September 2009 10:34:35 schrieb Berserker:
> >> Dmitry Goncharov wrote:
> >>  > 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)
> >
> > could you explain what those advantages are?
> > a scoped_ptr can't be copied at can't be moved. so there are two use
> > cases left for a scoped_ptr deleter:
> >
> >  - scoped_ptr as a class member: execute code when the class gets
> > destructed -> that's what a destructor is for.
>
> You could say the same for use delete in the destructor and never use
> scoped_ptr at all.

the point of a deleter is to execute CUSTOM code at destruction.
using scoped_ptr (without deleter) automates deletion so you don't have to
write custom code that does that. that simplifies things a lot.
but a scoped_ptr delete would provide the same thing as a destructor or a
scope exit: execute custom code.
the only reason shared_ptr or unique_ptr do have deleters is because the point
of destruction aren't statically known, as they can be copied or moved.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk