Thanks Doug. Here\'s the fix:
void swap(int& a, int& b) { if (&a == &b) // added this check to ensure the same address is not passed in
Anything xor'd with itself is zero.