fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class X {};
  5.  
  6. template<typename T>
  7. inline auto foo(T && rhs) -> decltype(foohelper(std::forward<T>(rhs), 0)) {
  8. return foohelper(std::forward<T>(rhs), 0);
  9. }
  10.  
  11. template<typename T>
  12. inline auto foohelper(T && rhs, int) -> decltype(fooimpl(std::forward<T>(rhs))) {
  13. return fooimpl(std::forward<T>(rhs));
  14. }
  15.  
  16. template<typename T>
  17. inline std::string foohelper(T && rhs, long) {
  18. return "bad";
  19. }
  20.  
  21. inline std::string fooimpl(const X & rhs) {
  22. return "good";
  23. }
  24.  
  25. int main() {
  26. std::cout << foo(X()) << std::endl;
  27. X x;
  28. std::cout << foo(x) << std::endl;
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
good
good