fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <stdexcept>
  4.  
  5. template <typename T>
  6. void f(const T &) { std::cout << "NO" << std::endl; }
  7.  
  8. template <typename T, int SFINAE = sizeof(static_cast<std::ostream &(std::ostream::*)(T)>(
  9. &std::ostream::operator<<))>
  10. void f(const T &) { std::cout << "YES" << std::endl; }
  11.  
  12. int main() {
  13. typedef const char *(std::exception::*F0)() const;
  14. F0 f0 = &std::exception::what;
  15.  
  16. f(0);
  17. f("abc");
  18. f(static_cast<const char *>("abc"));
  19. f(0.);
  20. f(f0);
  21. f(std::vector<int>());
  22.  
  23. return 0;
  24. }
Compilation error #stdin compilation error #stdout 0s 3456KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:16:5: error: call of overloaded 'f(int)' is ambiguous
  f(0);
     ^
prog.cpp:6:6: note: candidate: void f(const T&) [with T = int]
 void f(const T &) { std::cout << "NO" << std::endl; }
      ^
prog.cpp:10:6: note: candidate: void f(const T&) [with T = int; int SFINAE = 8]
 void f(const T &) { std::cout << "YES" << std::endl; }
      ^
prog.cpp:19:6: error: call of overloaded 'f(double)' is ambiguous
  f(0.);
      ^
prog.cpp:6:6: note: candidate: void f(const T&) [with T = double]
 void f(const T &) { std::cout << "NO" << std::endl; }
      ^
prog.cpp:10:6: note: candidate: void f(const T&) [with T = double; int SFINAE = 8]
 void f(const T &) { std::cout << "YES" << std::endl; }
      ^
stdout
Standard output is empty