fork download
  1. #include <iostream>
  2.  
  3. template <class T>
  4. struct rref {
  5. rref (T& t) : t(t) {}
  6. T& t;
  7. };
  8.  
  9. template<class T>
  10. rref<T> move(const T& t) {
  11. return rref<T>(const_cast<T&>(t));
  12. }
  13.  
  14. // you now can do a "move ctor"
  15. struct Foo {
  16. Foo() {}
  17. Foo(rref<Foo>) { std::cout << "move ctor\n"; }
  18. void operator=(rref<Foo>) { std::cout << "move assign\n"; }
  19. Foo(const Foo&);
  20. void operator=(const Foo&);
  21. };
  22.  
  23. Foo make_foo()
  24. {
  25. Foo foo;
  26. return foo;
  27. }
  28.  
  29. int main() {
  30. Foo foo = move(make_foo());
  31. }
  32.  
Success #stdin #stdout 0s 4208KB
stdin
Standard input is empty
stdout
move ctor