fork(1) download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. // For enum
  5. template<typename T>
  6. typename std::enable_if<std::is_enum<T>::value, bool>::type
  7. func(T& t, int x)
  8. {
  9. std::cout << "enum" << std::endl;
  10. }
  11.  
  12. // for other
  13. template<typename T>
  14. typename std::enable_if<!std::is_enum<T>::value, bool>::type
  15. func(T& t, int x)
  16. {
  17. std::cout << "other" << std::endl;
  18. }
  19.  
  20. // for unsigned char
  21. template <>
  22. bool func(unsigned char& t, int x)
  23. {
  24. std::cout << "unsigned char" << std::endl;
  25. }
  26.  
  27. enum class E1 {value1, value2};
  28. enum E2 {value3, value4};
  29.  
  30. int main() {
  31. const int x = 42;
  32. E1 e1 = E1::value1;
  33. E2 e2 = value3;
  34. unsigned char c = '*';
  35. int i = 42;
  36.  
  37. func(e1, x);
  38. func(e2, x);
  39. func(c, x);
  40. func(i, x);
  41. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
enum
enum
unsigned char
other