fork download
  1. #include <iostream>
  2.  
  3. struct C
  4. {
  5. C(int n_) : n(n_) {};
  6. C(const C& x) { n = x.n; std::cout << "Copy: " << n << std::endl; }
  7. C(C&& x) { n = x.n; std::cout << "Move: " << n << std::endl; }
  8. int n;
  9. };
  10.  
  11. template <class X, class Y>
  12. struct Pair
  13. {
  14. X x;
  15. Y y;
  16. };
  17.  
  18. template <class X, class Y>
  19. Pair<X, Y> make_pair(X&& x, Y&& y)
  20. {
  21. return Pair<X, Y>{std::forward<X>(x), std::forward<Y>(y)};
  22. }
  23.  
  24. #define MAKE_PAIR(x,y) decltype(make_pair(x,y)){x,y}
  25.  
  26. int main()
  27. {
  28. auto z1 = Pair<C, C>{C(1),C(2)};
  29. auto z2 = make_pair(C(3),C(4));
  30. auto z3 = MAKE_PAIR(C(5),C(6));
  31. }
  32.  
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
Move: 3
Move: 4