fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. template<class T>
  5. struct printer {
  6. friend std::ostream &operator<<(std::ostream &output, const printer&) {
  7. return output << typeid(int).name();
  8. }
  9. };
  10.  
  11. template<class T>
  12. struct printer<T&> {
  13. friend std::ostream &operator<<(std::ostream &output, const printer&) {
  14. return output << typeid(int).name() << "&";
  15. }
  16. };
  17.  
  18. template<class T>
  19. struct printer<T&&> {
  20. friend std::ostream &operator<<(std::ostream &output, const printer&) {
  21. return output << typeid(int).name() << "&&";
  22. }
  23. };
  24.  
  25. int main(int argc,char *argv[])
  26. {
  27. std::cout << printer<int>() << std::endl;
  28. std::cout << printer<int&>() << std::endl;
  29. std::cout << printer<int&&>() << std::endl;
  30. }
  31.  
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
i
i&
i&&