Boost logo

Boost :

Subject: Re: [boost] [SmartPtr] alternative to enable_shared_from_this
From: Roberto Hinz (robhz786_at_[hidden])
Date: 2017-01-05 12:50:11


On Wed, Jan 4, 2017 at 1:41 PM, Peter Dimov <lists_at_[hidden]> wrote:

> We already have something very similar, enable_shared_from_raw. It's still
> a base class, but since it's not templated, multiple inheritance scenarios
> can use virtual inheritance from enable_shared_from_raw.
>

hmm, I didn't know enable_shared_from_raw until now. Still, can
shared_handle be an alternative to enable_shared_from_raw ?

enable_shared_from_raw has been criticized of been too prone to cause
memory leaks [1] . shared_handle doesn't have this flaw. And although
shared_handle still allow the user to shoot in his foot, the documentation
makes it clear how to avoid the risks. An even if the user doesn't read it,
the ugly function name shared_handle::forcibly_assemble_shared_ptr will
encourage him to be careful. So I seems a safer version of
enable_shared_from_raw.

[1]
http://stackoverflow.com/questions/22184772/why-is-boostenable-shared-from-raw-so-undocumented


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