Boost logo

Boost Users :

Subject: Re: [Boost-users] enable_shared_from_this()
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2013-02-07 11:42:09


Frank Mori Hess<fmh6jj_at_[hidden]> wrote:

> That means
> throwing exceptions from the constructor after using shared_from_raw
> (or in any derived constructor since ithe derived constructor would be
> called later) causes bad things to happen.
That's no different from stashing away a raw pointer from a constructor (e.g. passing it
as a "parent" pointer to a referenced object). But that could be improved upon: The
collaborators can be given a weak_ptr only. But, we may require that collaborators have
owning references. In my library, a "borrower" (weak_ptr) could optionally hold a strong
reference as well, so the reference could be upgraded from weak to strong after a point of
commitment is reached.

If there were some kind of on-spec pending ptr type, they could be seen as strong
references eventually and in normal use, but automatically cleared or committed by the
Create wrapper. That is, you would not have to keep track of the collaborators and hook
them up in a second stage; rather, all such pending ptrs would become solid (wherever they
are) with one call made after the ctor is golden.

I never had a problem with it, though.

—John


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