From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-09 14:58:14
From: "Thomas Witt" <witt_at_[hidden]>
> On Monday 09 September 2002 19:37, Peter Dimov wrote:
> > From: "Thomas Witt" <witt_at_[hidden]>
> > Another indication that you can't beat copy+swap correctness-wise.
> That's exactly what I thought as I discovered the problem. BTW there is
> another lesson I've learned about intrusive ptrs. Creating the A object in
> B's ctor like this:
> shared_ptr<B> self(intrusive_ptr(this));
> a_.reset(new A(self));
> is a very bad idea.
Yes. I need to add this to the documentation one day. This is the "can an
object create weak pointers to itself in its constructor" question, and the
answer is "no, make the constructor private, provide a factory method that
creates shared_ptr<Object> and then creates the weak pointers." You might
even be able to avoid the counted_base.
BTW, "self" in the above can be spelled "shared_from_this(this)", without
the intermediate intrusive_ptr.
> > The self-reset "feature"
> > is still there; should we remove it as well for 1.29 or can this wait?
> I am not religous about this one. Actually I think Beman has a point.
> should be allowed if ptr == 0. What about
> BOOST_ASSERT( !ptr || ptr != p);
> What did I miss this time?
Nothing, that's what shared_ptr::reset does. :-)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk