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