Boost logo

Boost :

Subject: Re: [boost] [smart_ptr] Interest in the missing smart pointer (that can target the stack)
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2016-01-28 20:53:58

On 29/01/2016 14:35, Emil Dotchevski wrote:
> On Thu, Jan 28, 2016 at 12:20 PM, Noah <duneroadrunner_at_[hidden]> wrote:
>>> registered_ptr can point to stack allocated objects (just like native C++
>>> pointers can),
> shared_ptr can point to stack-allocated objects, too. As a benefit, if you
> use shared_ptr to point at a stack-allocated object, you also get the
> weak_ptr functionality.

Yes, you can make a shared_ptr that points at a stack object (by using a
null deleter) but AFAIK this doesn't actually work as expected unless
you can guarantee that no shared_ptr instances will survive destruction
of the stack frame (ie. it is only used within the call chain and never
copied outside of it).

And it's way too easy to break that guarantee because it's not the
semantics that shared_ptr was designed for.

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