fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. struct node
  5. {
  6. template < class T >
  7. void analyze(T t, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
  8. {
  9. std::cout << "is_arithmetic type " << t << "\n";
  10. }
  11.  
  12. template < class T >
  13. void analyze(T t, typename std::enable_if<std::is_floating_point<T>::value>::type* = 0)
  14. {
  15. std::cout << "is_floating_point type " << t << "\n";
  16. }
  17.  
  18. void analyze(bool t)
  19. {
  20. std::cout << "is bool type " << t << "\n";
  21. }
  22. };
  23.  
  24.  
  25. int main() {
  26.  
  27. node n;
  28. n.analyze(13);
  29. n.analyze(3.1415);
  30. n.analyze(false);
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
is_arithmetic type 13
is_floating_point type 3.1415
is bool type 0