|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-04-11 14:38:07
Frank Mori Hess:
> On Friday 11 April 2008 12:11 pm, Peter Dimov wrote:
>> I'm still not 100% convinced that we need this functionality in
>> shared_ptr.
>> But if we do, it seems that the proper way to add it is to make
>> shared_ptr
>> issue an unqualified call to
>>
>> sp_accept_owner( this, p );
>
> It does provide an alternative to making shared_from_this() callable in
> constructors. As long as sp_accept_owner() is always run after
> enable_shared_from_this is set up (and there is no reason it can't be
> since
> shared_ptr is fully aware of enable_shared_from_this) then it is usable as
> a
> post constructor where shared_from_this can be used safely. Actually, you
> don't even need enable_shared_from_this if don't need to use
> shared_from_this() outside the postconstructor, since you are passed in
> the
> owning shared_ptr.
You're right! sp_accept_owner can indeed be used as a postconstructor.
My original idea was for it to replace sp_enable_shared_from_this entirely,
making enable_shared_from_this non-special and fully implementable in "user
mode". This doesn't seem to be a problem for the use case you describe
though. The programmer would just implement sp_accept_owner for the derived
class and call sp_accept_owner( (esft*)this ) before using shared_from_this.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk