fork download
  1. #include <iostream>
  2. #include <utility>
  3.  
  4. using namespace std;
  5.  
  6. struct bar
  7. {
  8. int i;
  9. bar() : i(0) {}
  10. explicit bar(int i0) : i(i0) {}
  11. bar(bar const & b) : i(b.i) { cout << "copy ctor " << i << endl; }
  12. bar(bar && b) : i(move(b.i)) { cout << "move ctor " << i << endl; }
  13. };
  14.  
  15. struct foo
  16. {
  17. bar a, b;
  18. foo() : a(), b() {}
  19.  
  20. template<class T1, class T2>
  21. foo(T1 && i0, T2 && i1) : a(forward<T1 &&>(i0)), b(forward<T2 &&>(i1)) {}
  22. };
  23.  
  24. int main(){
  25. bar b1(1), b2(2);
  26. foo f1(b1, b2);
  27. foo f2(b1, bar(3));
  28. foo f3(bar(4), b2);
  29. foo f4(bar(5), bar(6));
  30.  
  31. foo f5(7, 8);
  32. }
  33.  
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
copy ctor 1
copy ctor 2
copy ctor 1
move ctor 3
move ctor 4
copy ctor 2
move ctor 5
move ctor 6