fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. struct Noisy {
  7. int n;
  8. Noisy() :n(0) { cout << "Noisy()\n"; }
  9. Noisy(const Noisy & o) :n(o.n) { cout << "copy Noisy\n"; }
  10. Noisy(Noisy&& o) :n(o.n) { cout << "move Noisy\n"; }
  11. };
  12.  
  13. Noisy foo(bool x)
  14. {
  15. Noisy a;
  16. a.n = 5;
  17. Noisy b;
  18. b.n = 10;
  19.  
  20. // does this not exclude the possibility of copy elision?
  21. if (x) return a;
  22. else return b;
  23. }
  24.  
  25. int main()
  26. {
  27. // does this not move? See output below
  28. Noisy n = foo(rand()%2==0);
  29. cout << n.n;
  30. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
Noisy()
Noisy()
move Noisy
10