fork download
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <utility>
  4.  
  5. // Mutually exclusive enable_if test
  6. template<typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
  7. void foo(T)
  8. {
  9. std::cout << "Integral\n";
  10. }
  11.  
  12. template<typename T, typename std::enable_if<! std::is_integral<T>::value && sizeof(T) <= 4, int>::type = 0>
  13. void foo(T)
  14. {
  15. std::cout << "Not integral, <= 4\n";
  16. }
  17.  
  18. template<typename T, typename std::enable_if<! std::is_integral<T>::value && (sizeof(T) > 4), int>::type = 0>
  19. void foo(T)
  20. {
  21. std::cout << "Not integral, > 4\n";
  22. }
  23.  
  24. int main()
  25. {
  26. foo(3);
  27. foo(0.0);
  28. foo(0.0f);
  29. }
Success #stdin #stdout 0s 4528KB
stdin
Standard input is empty
stdout
Integral
Not integral, > 4
Not integral, <= 4