fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <utility>
  4. using namespace std;
  5.  
  6. struct A {
  7. string x;
  8. };
  9.  
  10. struct B {
  11. string x;
  12. };
  13.  
  14. void func(const pair<A, B>& mypair) {
  15. cout << mypair.first.x << ", " << mypair.second.x << endl;
  16. }
  17.  
  18. int main() {
  19. A a;
  20. a.x = "test A";
  21. B b;
  22. b.x = "test B";
  23.  
  24. func(make_pair(a, b));
  25. cout << a.x << ", " << b.x << endl; // a and a are still here!
  26.  
  27. func(make_pair(move(a), move(b)));
  28. cout << a.x << ", " << b.x << endl; // a and a are now reset becuase they are moved!
  29. }
  30.  
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
test A, test B
test A, test B
test A, test B
,