fork download
  1. #include <iostream>
  2. #include <utility>
  3.  
  4. struct X
  5. {
  6. X() = default;
  7. X(X const &) { std::cout << "Copy X\n"; }
  8. X(X &&) { std::cout << "Move X\n"; }
  9. };
  10.  
  11. struct Foo
  12. {
  13. X * p;
  14. template <typename T> Foo(T t) : p(new T(std::move(t))) { }
  15. };
  16.  
  17. int main()
  18. {
  19. X x;
  20. Foo a { X() };
  21. Foo b { x };
  22. Foo c { std::move(x) };
  23. //Foo d(10); // Error
  24. }
  25.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Move X
Copy X
Move X
Move X
Move X