fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. class Test {
  7. public:
  8. Test() { cout << "Test()\n"; }
  9. Test(int x):val_(x){ cout << "Test(" << x << ")\n"; }
  10. Test(const Test& t):val_(t.val_) { cout << "Test(const Test& " << t.val_ << ")\n"; }
  11. Test(Test&&t) :val_(t.val_) { cout << "Test(const Test&& " << t.val_ << ")\n"; t.val_ = 0; }
  12. Test& operator = (const Test& t) {
  13. cout << "Test& operator = (const Test& " << t.val_ <<")\n";
  14. val_ = t.val_;
  15. return *this;}
  16. Test& operator = (Test&& t) {
  17. cout << "Test& operator = (const Test&&" << t.val_ <<")\n";
  18. val_ = t.val_; t.val_ = 0;
  19. return *this;}
  20. ~Test() { cout << "~Test(" << val_ <<")\n"; }
  21. int val() const { return val_; }
  22. private:
  23. int val_ = 0;
  24. };
  25.  
  26. struct Quest
  27. {
  28. Test t;
  29. Quest(Test&& t):t(t){}
  30. };
  31.  
  32. struct Qwest
  33. {
  34. Test t;
  35. Qwest(Test&& t):t(move(t)){}
  36. };
  37.  
  38. int main(int argc, const char * argv[])
  39. {
  40. Test t(5), s(6);
  41. Quest q(move(t));
  42. Qwest w(move(s));
  43. }
  44.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Test(5)
Test(6)
Test(const Test& 5)
Test(const Test&& 6)
~Test(6)
~Test(5)
~Test(0)
~Test(5)