
13 Feb
2010
13 Feb
'10
7:41 p.m.
AMDG Peter Foelsche wrote:
Is there some way to check at compile time whether a particular specialization exists? E.g. I have a template class with two template arguments which are commutative -- means they can be exchanged and the result is the same. Can I check whether
type<A, B> exists and if not select type<B, A>?
You can't specializations directly, but if you can change the primary template you can use: template<class T, class U> struct type { typedef void this_is_the_primary_definition_of_type; }; and use SFINAE to check for the typedef. There are other ways to do this like adding a base class. The key is to add something whose presence can be detected to the primary template. In Christ, Steven Watanabe