Boost logo

Boost Users :

Subject: Re: [Boost-users] intrusive_ptr vs shared-ptr
From: gast128 (gast128_at_[hidden])
Date: 2013-01-20 14:46:29


Igor R <boost.lists <at> gmail.com> writes:

> 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).

The shared_ptr in dtor sounds as a 'contradictio in terminis'. A common case
is that you have a change manager in which you want to de-register yourself in a
dtor. The changemanager has ofc weak_ptr's to the managed object.


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