4 ms·
Not if they have just the same value, but if they're the same memory location. So check the pointers: void swap(T &x, T &y) { if (&x == &y) return; x
by tlb 6y ago
Not if they have just the same value, but if they're the same memory location. So check the pointers:
void swap(T &x, T &y) {
if (&x == &y) return;
x ^= y;
y ^= x;
x ^= y;
}