Re: Should partial specializations be ablel to have default
arguments?
Am Samstag, 10. M?rz 2012 20:20:56 UTC+1 schrieb Johannes Schaub (litb):
Currently this is forbidden:
template<typename T>
class hash;
template<typename = void,
typename U,
typename enable_if<is_enum<U>::value, int>::type = 0
struct hash<U> {
// if argument is an enum, then this specialization is used
};
Allowing default arguments in partial specializations could be used for
SFINAE cases like this. The spec currently says that default arguments
are forbidden for partial specializations because they could not be used
anyway (because for completing an argument list, the default arguments
declared in the template-parameter-list of the primary template is
used). But for SFINAE cases like above, default arguments could be
useful IMO.
What do you think about this?
If we're to have a feature only for filtering out specializations, how about one that is actually meant for that purpose?
In other words, default arguments in partial specializations are useful only for SFINAE, nothing else, and SFINAE for specialization filtering is a hack. A proper feature (e.g. static if) would be a much better choice.
Sebastian
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]