any, any swap(any a, any b)
Returns two variables in reverse order. This function exists to improve readability when swapping the values of two variables.
Without swap()
:
int tmp = x; x = y; y = tmp;
With swap()
:
swap(x, y); x = r1; y = r2;