fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template<typename T>
  5. typename std::enable_if<(std::is_integral<T>::value || std::is_floating_point<T>::value), void>::type
  6. function(const T& value)
  7. {
  8. std::cout << "Only for integrals and floats" << std::endl;
  9. }
  10.  
  11. template<typename T>
  12. typename std::enable_if<(!std::is_integral<T>::value && !std::is_floating_point<T>::value), void>::type
  13. function(const T& value)
  14. {
  15. std::cout << "For all others" << std::endl;
  16. }
  17.  
  18. int main()
  19. {
  20. function(1);
  21. function(1.0);
  22. function('c');
  23. function("hello");
  24. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Only for integrals and floats
Only for integrals and floats
Only for integrals and floats
For all others