code_junkie

Why doesn't a swap / exchange operator exist in imperative or OO languages like C/C++/C#/Java…?

Nov 12th, 2011
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.14 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cassert>
  3.  
  4. int
  5. main()
  6. {
  7. using std::swap;
  8. int a(3), b(5);
  9. swap(a, b);
  10. assert(a == 5 && b == 3);
  11. }
Add Comment
Please, Sign In to add comment