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