Boost logo

Boost :

Subject: Re: [boost] [smart_ptr] shared_ptr template type
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2009-07-15 09:40:03


On Wednesday, July 15, 2009, Stewart, Robert <Robert.Stewart_at_[hidden]> wrote:
> Gottlob Frege wrote:
>>
>> My standard answer has now become:
>>    1. use a traits/policy class
>>    2. have the default traits/policy call a free functinon
>>
>> eg:
>>
>> // default free function
>> // or yours will found by ADL if you supply your own
>> //
>> template<class T>  bool is_null_pointer(T p)
>> {
>>    return (p == 0);
>> };
>>
>> // default policy class, calls whatever it finds by ADL
>> // feel free to supply your own policy class instead
>> //
>> template<class T> struct default_smart_pointer_traits
>>    : public smart_pointer_traits<T>
>> {
>>    static bool is_null(pointer p)
>>    {
>>         return is_null_pointer(p);
>>    }
>> };
>
> That's a very nice approach.  You seem to lump traits and policy classes together, but they are clearly not equivalent.  I think a policy class is superior to a traits class, so your numbered bullets should not contain "traits/".
>

Yes I really mean policy. But the original example had a class called
'traits' being passed as a policy and I wanted to make sure it was
understood which class I was talking about. I should have clarified
more.

> What about function templates?  The above seems to apply to class templates only.  Overloading permits one function template to rely on a default functor type while another can take a functor as an argument.  (The former can call the latter, of course.)  The functor argument can be defaulted, provided the default functor is stateless.

I think we could make something work. Do you want to start with an example?

>
> _____
> Rob Stewart

Tony


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