|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2002-11-21 10:47:06
"Peter Dimov" <pdimov_at_[hidden]> writes:
> From: "David Abrahams" <dave_at_[hidden]>
>>
>> Wow, such service!!
>>
>> Well, it needs some help for MSVC. I'll be happy to make those patches
>> if neccessary.
>
> Does it? What kind of help? Can you post a test case that fails on MSVC?
Just the usual workaround here, I presume
template<class D, class T> D * get_deleter(shared_ptr<T> const & p, D* = 0)
^^^^^^
{
return static_cast<D *>(p._internal_get_deleter(typeid(D)));
}
To allow usage which doesn't collide with class templates and prevent link problems.
>
> 'D' in counted_base_impl<P, D> is never cv-qualified and never a reference
> type, so I figured that things will work reasonably well. get_deleter<D
> const> might not work but you don't need to use that... I think?
>
>> And what about the need for 2-phase check because the
>> deleter may have been optimized away? That was your concern.
>
> No, there is no need for a 2-phase check. This
>
> if(has_deleter<D>(p))
> {
> D * p = get_deleter<D>(p);
> // ...
> }
>
> is equivalent to
>
> if(D * p = get_deleter<D>(p))
> {
> // ...
> }
>
> The deleter can only be optimized away completely if shared_ptr hasn't been
> constructed with a deleter (in which case get_deleter<X> should return 0 for
> any X). Otherwise, the deleter will be there, although it may be an empty
> base, if compressed_pair is used. But it still will have an address.
Perfect; I'm very happy that a simple interface is possible.
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk