Hacker News new | past | comments | ask | show | jobs | submit login

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;
  }



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: