fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. struct foo {
  5. int value;
  6.  
  7. explicit foo(int value) : value(value) {
  8. std::cout << "foo(" << value << ")\n";
  9. }
  10.  
  11. foo(foo const& other) : value(other.value) {
  12. std::cout << "foo(foo(" << value << "))\n";
  13. }
  14.  
  15. foo(foo&& other) : value(std::move(other.value)) {
  16. other.value = -1;
  17. std::cout << "foo(move(foo(" << value << "))\n";
  18. }
  19.  
  20. ~foo() {
  21. if (value != -1)
  22. std::cout << "~foo(" << value << ")\n";
  23. }
  24. };
  25.  
  26. int main() {
  27. std::vector<foo> foos;
  28. foos.emplace_back(1);
  29. foos.emplace_back(2);
  30. }
Success #stdin #stdout 0s 2964KB
stdin
Standard input is empty
stdout
foo(1)
foo(2)
foo(move(foo(1))
~foo(1)
~foo(2)