Safe reference counting cannot be implemented as a library

David Nadlinger via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 28 04:29:13 PDT 2015


On Wednesday, 28 October 2015 at 11:21:17 UTC, Manu wrote:
> RC is okay-ish in C++11 (with rval references), although it 
> could be
> much better, for instance, the type mangling/wrapping induced 
> by this
> sort of library solution always leads to awkward situations, ie,
> 'this' pointer in a method is not an RC object anymore! Methods 
> can't
> give out pointers to themselves (ie, signaling events where it's
> conventional to pass a 'sender' to the subscribers). Pretty 
> massive
> fail!

Did you look into doing something like 
std::enable_shared_from_this? I use it pretty routinely in 
networking code (boost.asio), and while it is not as pretty as it 
could be, it does the trick.

  – David


More information about the Digitalmars-d mailing list