Boost logo

Boost :

From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2004-01-27 12:53:59


Jonathan Turkanis wrote:
> "Peter Dimov" <pdimov_at_[hidden]> wrote in messag:
>
>
>>>>Howard Hinnant wrote:
>>>>
>>>>><snip>
>>>>>And I submit that:
>>>>>S<T[], my_deleter>
>>>>>is more elegant syntax than:
>>>>>S_array<T, my_deleter>
>
>
> <snip>
>
>>>Need to be? No. But I still like it. <shrug> I was convinced
>>>because that's how a newbie expected it to work.
>>
>>I'm starting to not like it. :-) The problem is:
>>
>> template<class X> void f(S_ptr<X> px);
>>
>>where f doesn't support arrays. A reasonably common occurence.
>
> S_array<>
>
>>doesn't match, but S_ptr<T[]> does. The author of f would need to
>
> learn
>
>>about enable_if to prevent array pointers from being passed to f.
>
> This is
>
>>not good, although the exact degree of not-goodness is somewhat
>
> debatable.
>
>
> I'm not sure I see the problem. (Maybe because I already implemented
> this feature :-)
>
> If pointers to objects and pointers to arrays need different
> treatment, one can use:
>
> template<class X> void f(S_ptr<X> px);
> template<class X> void f(S_ptr<X[]> px);

The problem is that you don't always want to have both overloads and in
those cases a compiler error is very unhelpful. I can't come up with
very good examples, at least not right now. But in general, disabling an
overload is far better than failing to compile. Maybe Peter has some use
case where this applies?

-- 
Daniel Wallin

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