fork download
  1. #include <iostream>
  2.  
  3. struct T {
  4. int n;
  5. T(int n) : n(n) { std::cout << "create " << n << "\n"; }
  6. T(T const &x) : n(x.n) { std::cout << "copy " << n << "\n"; }
  7. T(T &&x) : n() { std::swap(n, x.n); std::cout << "move " << n << "\n"; }
  8. ~T() { std::cout << "destroy " << n << "\n"; }
  9.  
  10. void operator+=(T const &x) { n += x.n; }
  11. };
  12. T operator+(T a, T const &b) { a += b; return a; }
  13.  
  14. T f() { return T(18); }
  15. int main() {
  16. T obj {f() + T(24)};
  17. return 0;
  18. }
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
create 24
create 18
move 42
destroy 0
destroy 24
destroy 42