This equation swaps two numbers without a temporary variable, but uses arithmetic operations:
a = (a+b) - (b=a);
How can I do it without arithmetic operations? I was thinking about XOR.
This equation swaps two numbers without a temporary variable, but uses arithmetic operations:
a = (a+b) - (b=a);
How can I do it without arithmetic operations? I was thinking about XOR.
C++11 allows to:
std::swap(a, b);
std::swap_ranges(a.begin(), a.end(), b.begin());
std::tie(b, a) = std::make_tuple(a, b);
std::tie(c, b, a) = std::make_tuple(a, b, c);