fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. using namespace std;
  5.  
  6. enum type_t {
  7. integer,
  8. float_v,
  9. bool_v,
  10. other
  11. };
  12.  
  13. template<typename T>
  14. struct get_type
  15. {
  16. static constexpr type_t type = is_same<T,bool>:: value ? bool_v :
  17. is_integral<T>::value ? integer :
  18. is_same<T,float>::value ? float_v : other;
  19. };
  20.  
  21. int main(int argc, char * argv[])
  22. {
  23. cout << get_type<long>::type << endl;
  24. cout << get_type<double>::type << endl;
  25. cout << get_type<float>::type << endl;
  26. cout << get_type<bool>::type << endl;
  27. }
  28.  
Success #stdin #stdout 0.01s 5532KB
stdin
Standard input is empty
stdout
0
3
1
2