On Tue, Feb 5, 2013 at 2:10 AM, Dominique Devienne <ddevienne@gmail.com> wrote:
On Mon, Feb 4, 2013 at 6:23 PM, Nathan CrookstonI don't see the difference between the shared_ptr being created from
<nathan.crookston@gmail.com> wrote:
>> Since Foo embeds a weak_ptr, why can't it new the pi_ on the spot?
>> (I'm using Boost 1.44).
>
> Hmm, it might be interesting to have shared_from_this create a shared_ptr if
> none exists, but I don't know what that might complicate -- perhaps it would
> cause issues at destruction?
the "inside" or the "outside", as far as that pi_ is concerned.
Indeed, I (naively) think it can work, and I'm interested in finding
>> PS: On a related note, why doesn't boost::shared_ptr<Foo>(p_foo)
>> (where p_foo is a raw Foo*) implicitly apply the aliasing Ctor, to
>> share the same px, to avoid the classic bug of having several
>> different pn on the same px, since p_foo derives from
>> enable_shared_from_this()? Initially i thought that's what
>> sp_enable_shared_from_this() and pe->_internal_accept_owner() were
>> meant to do, but obviously that's not the case.
>
> I suspect something like this could be made to work if the previous also
> worked -- but the class is documented to *not* allow the previous to work.
> I'd have to think about why (or maybe Peter will enlighten us).
out why this was not implemented, especially whether it was conscious
decision (rational?) or simply overlooked.
int MyThing::Foo(){shared_from_this();return this->x;}
Thanks for any insight on this. Could very well be I'm missing
something obvious (my C++ expertise doesn't rise to Boost levels), but
so far I fail to see the drawbacks.
There's already code that tightly couples
shared_ptr/weak_ptr/enable_shared_from_this,