Boost logo

Boost Users :

Subject: Re: [Boost-users] intrusive_ptr vs shared-ptr
From: Igor R (boost.lists_at_[hidden])
Date: 2013-01-20 16:16:01


>> OTOH, intrusive_ptr doesn't have a weak_ptr counterpart -- and this is
>> much more problematic, imho.
>
> Yes that's an important feature too, but the ctor case is also a common case
> (e.g. solvable by adding an extra static 'Create').
>
> To my knowledge the following drawbacks exist for shared_ptr:
> - you cannot use enabled_shared_from_this in the constructor.
> - you cannot use shared_ptr's in the destructor.
> - (never make a new shared_ptr family to an already shared object).
> - (enabled_shared_from_this only usable if the object is created as shared_ptr,
> not on the stack or just on the heap).

Well, all these points either have a reasonable solution/workaround
that doesn't complicate the design much, or describe a quite
"marginal" use-case.
But the lack of weak-ptr makes impossible an object existence
tracking, which is commonly used in a wide range of tasks. In some
cases this would complicate the design and make it more error-prone
(eg. manual breaking of circular references), and in some other cases
it renders completely impossible a use of some facilities (like
Boost.Signals2).


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net