Subject: Re: [boost] [smart_ptr] Interest in the missing smart pointer (that can target the stack)
From: Rob Stewart (rob.stewart_at_[hidden])
Date: 2016-01-30 05:20:20
On January 29, 2016 3:35:54 PM EST, Emil Dotchevski <emildotchevski_at_[hidden]> wrote:
> On Fri, Jan 29, 2016 at 1:40 AM, Rob Stewart <rob.stewart_at_[hidden]>
> > On January 29, 2016 2:48:56 AM EST, Emil Dotchevski <
> > emildotchevski_at_[hidden]> wrote:
> > If do_something() saves a copy of the shared pointer in a container,
> > example, later references will refer to a non-existent object.
> > nothing you can do about it short of using assertions or another
> > check with a call to std::terminate() or similar. That's hardly
> That's hardly a problem if it never happens. :)
> > > At any rate, what other use of null_deleter can you think of? Are
> > > saying that null_deleter makes no sense?
> > I've used it to refer to static objects, but never to automatic
> Static objects do get destroyed, except only God knows in what order,
> strictly speaking you can't know that shared_ptr references to them
> exist after they get destroyed.
Also true. Implied in my statement is knowledge, like you apparently implied with do_something(), that the all shared_ptrs will be destroyed before the referenced object is destroyed. In the case I was thinking about, the plugin framework releases the shared_ptr before unloading the dynamic library containing the static object.
> Consider that if you pass a shared_ptr
> to a
> function, it can copy it to a global shared_ptr. At least with local
> objects you can assert on unique().
> The point of null deleter is specifically to be able to use shared_ptr
> cases when it isn't possible for shared_ptr to control the lifetime of
> object. I don't think of the lack of safety as a disadvantage, it's a
I wouldn't go that far, but you're right that it's an example of "trust the programmer."
(Sent from my portable computation engine)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk