|
Boost : |
From: Daniel Frey (d.frey_at_[hidden])
Date: 2008-04-12 23:09:15
On Sun, 2008-04-13 at 05:22 +0300, Peter Dimov wrote:
> Daniel Frey:
> > I agree that the implementation should not drive the interface, but I
> > still fail to see why passing the deleter should be needed anyway. It's
> > not even used in the current enable_shared_from_this implementation, so
> > why do you think that it should be part of sp_accept_owner's interface?
>
> One of your earlier posts contained an example "observer" called
> shared_ptr_debugger. You didn't show it doing anything, but I can easily
> imagine it either logging all sp_accept_owner calls, in which case
> typeid(D).name() could come in handy, or checking whether sp_accept_owner is
> called twice on the same object. In the latter case, you do want to
> distinguish between deleterless and deleterful calls, because the same
> object can legitimately be owned by several shared_ptr instances with null
> (or effectively null) deleters.
>
> The change to the esft base demonstrates another use case, one in which the
> object wishes to recognize a particular deleter and do something different
> in sp_accept_owner. It's true that in this particular instance there is
> another way to achieve the desired "do nothing" behavior.
>
> I could however imagine scenarios in which sp_accept_owner and a deleter are
> used as a pair to achieve postconstructor and predestructor behavior. If the
> postconstructor action can fail, sp_accept_owner could indicate this by not
> setting the appropriate "perform predestructor action" flag inside the
> deleter.
I think that get_deleter() allows you to implement most of the above
features anyway. And I can also imagine to add a more general helper:
template< class T >
const std::type_info* get_type_info(shared_ptr<T> const& p);
which is implemented via a virtual function from sp_counted_base
(similar to get_deleter()). The implementation is constructed with
knowing the deleter's type, so it could simply return typeid(D). That
way even logging typeid(D).name() is possible. This helper is more
general as it can be used on any shared_ptr anytime.
Regards, Daniel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk