Specialization of the template class for several types satisfying the condition

If I have a template class, for example:

template<typename T> class Type { /* ... */ }; 

Without modifying the Type any way, is there an easy way to specialize it for all those types that match the compilation condition? For example, if I wanted to specialize in Type for all integral types, I would like to do something like this (just something that works):

 template<typename T> class Type<std::enable_if<std::is_integral<T>, T>::type> { /* ... */ }; 
+4
source share
1 answer

This should work:

 template<typename T, bool B = std::is_integral<T>::value> class Type; // doesn't have to be a specialization, although I think it more clear this way template<typename T> class Type<T, false> { /* ... */ }; template<typename T> class Type<T, true> { /* ... */ }; 
+6
source

Source: https://habr.com/ru/post/1387449/


All Articles