fork download
  1. #include <functional>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. template<typename T, typename = typename enable_if<is_integral<T>::value, T>::type>
  7. T foo(T a)
  8. {
  9. return a;
  10. }
  11.  
  12. template<typename T, typename = typename enable_if<is_floating_point<T>::value, void>::type>
  13. T foo(T a)
  14. {
  15. return a;
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21. foo(5);
  22. foo<float>(3.4);
  23.  
  24. return 0;
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:13:3: error: redefinition of ‘template<class T, class> T foo(T)’
prog.cpp:7:3: error: ‘template<class T, class> T foo(T)’ previously declared here
prog.cpp: In function ‘int main()’:
prog.cpp:22:19: error: no matching function for call to ‘foo(double)’
prog.cpp:22:19: note: candidate is:
prog.cpp:7:3: note: template<class T, class> T foo(T)
prog.cpp:7:3: note:   template argument deduction/substitution failed:
prog.cpp:6:22: error: no type named ‘type’ in ‘struct std::enable_if<false, float>’
stdout
Standard output is empty