Boost logo

Boost :

From: Daniel Frey (d.frey_at_[hidden])
Date: 2008-04-10 09:57:40


On Thu, 2008-04-10 at 09:27 -0400, Frank Mori Hess wrote:
> On Thursday 10 April 2008 06:40 am, Daniel Frey wrote:
> > On Wed, 2008-04-09 at 20:13 -0400, Frank Mori Hess wrote:
> > I attached a minimalistic patch against the trunk which enhances the
> > current code into that direction.
>
> The static_cast in your patch is going to have problems with virtual base
> classes. I think you could just use the Y* available in
> sp_enable_shared_from_this and call _internal_accept_owner from that.

Note that 5.2.9/8 only refers to B and D's relationship. Since we are
creating a new base class, we can define that non-virtual derivation is
a precondition. In the patch I've shown the static_cast should be
perfectly legal and it should work in all cases, AFAICT.

> Also, on further thought, I don't think enable_shared_from_this_base needs to
> be a template class at all.

If you have an easier implementation without further overhead, I'd be
happy to see it.

> > The name (enable_shared_from_this_base) is probably not a good name. I
> > think that from shared_ptr's point of view, it doesn't need to know what
> > the callback is used for. It might be better to call it
> > notify_on_ownership or something in that direction. And the callback
> > function should probably also be renamed. Suggestions?
>
> I agree. notify_on_ownership seems ok. Some other possibilities are
> ownership_observer or shared_ptr_observer. The callback might be
> accept_shared_ptr_owner() or update_shared_ptr_owner()

Those are excellent suggestions. I think shared_ptr_observer and
update_shared_ptr_owner are the names I like most.

> Also, I don't think enable_shared_from_this should actually use this base
> class in the end, whatever it is called (although it is a good test). If it
> does, the user will have to take special care to avoid problems when deriving
> from both enable_shared_from_this and this base class. This might happen if
> the user is deriving from the base class for purposes other than
> re-implementing enable_shared_from_this.

Good point. I'll need some time to think about this case.

Regards, Daniel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk