fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A
  5. {
  6. template<typename T> A(T&&) { cout << "T&&" << endl; }
  7. A(A&) { cout << "A&" << endl; }
  8. A(const A&) { cout << "const A&" << endl; }
  9. A(A&&) { cout << "A&&" << endl; }
  10. A(const A&&) { cout << "const A&&" << endl; }
  11. };
  12.  
  13. struct B
  14. {
  15. template<typename T> B(T&&) { cout << "T&&" << endl; }
  16. B(B&) { cout << "B&" << endl; }
  17. B(const B&) { cout << "const B&" << endl; }
  18. B(B&&) { cout << "B&&" << endl; }
  19. B(const B&&) = delete;
  20. };
  21.  
  22. int main() {
  23. A pi(3.14159); // T&&
  24. const A answer(42); // T&&
  25. A a1(pi); // A&
  26. A a2(answer); // const A&
  27. A a3(std::move(pi)); // A&&
  28. A a4(std::move(answer)); // const A&&
  29.  
  30. B hello("Hello"); // T&&
  31. const B world("World"); // T&&
  32. B b1(hello); // B&
  33. B b2(world); // const B&
  34. B b3(std::move(hello)); // B&&
  35. // B b4(std::move(world)); // error: const B&& is deleted
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 4392KB
stdin
Standard input is empty
stdout
T&&
T&&
A&
const A&
A&&
const A&&
T&&
T&&
B&
const B&
B&&