Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Algorithm to swap two values of the same data type.
The definition of std::swap is in algorithm.h.
#include <algorithm> |
Consider specializing std::swap for your own classes when you know a more efficient way to exhange their values by calling operator= three times [1].
template <class T> |
The XOR swap is another way to swap two values. Prefer using std::swap [2].
void XorSwap (int *x, int *y) |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.