fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. struct X { };
  5.  
  6. template<typename T>
  7. struct aux
  8. {
  9. void operator()(T&&) const { std::cout << 1 << std::endl; }
  10. };
  11.  
  12. template<typename T>
  13. struct aux<T&>
  14. {
  15. void operator()(T&) const { std::cout << 2 << std::endl; }
  16. };
  17.  
  18. template<typename T> void g(T&& t)
  19. {
  20. aux<T>()(std::forward<T>(t));
  21. }
  22.  
  23. int main()
  24. {
  25. X x;
  26. g(x); // 2
  27. g(X()); // 1
  28. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
2
1