fork(4) download
  1. #include <iostream>
  2.  
  3. struct A {};
  4.  
  5. struct B {
  6. static int bar() { std::cout << "B::bar()" << std::endl; return 0; }
  7. };
  8.  
  9. struct C {
  10. void bar(int) { std::cout << "C::bar(int)" << std::endl; }
  11. };
  12.  
  13. template <typename T>
  14. class X {
  15. public:
  16. static void foo() {
  17. foo_impl(static_cast<T*>(nullptr));
  18. }
  19. private:
  20. template <typename U>
  21. static auto foo_impl(U*) -> decltype(U::bar(), void()) {
  22. U::bar();
  23. }
  24. static void foo_impl(...) {}
  25. };
  26.  
  27. int main() {
  28. X<A>::foo();
  29. X<B>::foo();
  30. X<C>::foo();
  31. }
  32.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
B::bar()