fork(2) download
  1. #include <algorithm>
  2. #include <functional>
  3. #include <iostream>
  4.  
  5. class A
  6. {
  7. std::reference_wrapper<int> r;
  8. public:
  9. A(int& v) : r(v) {}
  10. void swap(A& rhs)
  11. {
  12. std::swap(r, rhs.r);
  13. }
  14.  
  15. int& get() const { return r; }
  16. };
  17.  
  18. int main()
  19. {
  20. int i = 42;
  21. int j = 0;
  22. A a(i), b(j);
  23.  
  24. a.swap(b);
  25. ++j;
  26. std::cout << j << "==" << a.get() << std::endl;
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
1==1