How can I partially specialize a class template for ALL enumerations?

Let's say I have a template template:

template<typename T> class { // .... } 

I can partially highlight this pattern for ALL pointers:

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

Is there any way to specialize the template for ALL enumerations? i.e. do something like: (this does not work though)

 template<typename T> class<enum T> { // .... } 
+4
source share
1 answer

use C ++ 11 and SFINAE.

 #include <type_traits> template<typename T, typename = void> struct Specialize { }; template<typename T> struct Specialize<T, typename std::enable_if<std::is_enum<T>::value>::type> { void convert() { } }; enum E { }; int main() { Specialize<E> spec; spec.convert(); } 

Without C ++ 11, use boost::enable_if and boost::is_enum

+15
source

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


All Articles