|
Boost Users : |
From: Ian McCulloch (ianmcc_at_[hidden])
Date: 2005-03-05 13:31:26
David Abrahams wrote:
> Ian McCulloch <ianmcc_at_[hidden]> writes:
>
>> David Abrahams wrote:
>>
>>> Ian McCulloch <ianmcc_at_[hidden]> writes:
>>>
>>>>> * Coupling; you need to include a primary template.
>>>>
>>>> Ok, but what does that primary template do? Surely nothing, or some
>>>> very conservative default.
>>>
>>> Actually you don't need to include a primary template. All you need
>>> is a declaration with no body. You can do that without even pulling
>>> in a header.
>>>
>>
>> I think, an empty body is better than a bare declaration. At least, with
>>
>> template <typename T>
>> struct my_algo_impl {};
>>
>> you can do SFINAE on whether my_algo_impl<T> is actually defined or not,
>> for some T (ie. using T::result_type, or probably better
>> boost::result_of).
>
> That's a useful technique, but I don't see how it relates to coupling.
> In order for a user to provide a specialization of some library
> template for her type, she need only provide the bare declaration.
> Bare declarations and empty definitions aren't alternatives, they're
> apples and oranges.
>
True. I had forgotten that you might want to define a specialization but
only make use of it elsewhere. But what happens if the primary template
has some additional paramters with default values (eg, Enable = void)?
Would you regard that as bad style ? Actually, I tend to avoid that
anyway, and instead if the primary template has a default then forward it
to another template that does the enable_if tricks/hacks. But thats mostly
because I usually end up very confused when I try to combine partial
specialization and enable_if ;-)
Cheers,
Ian
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net