assignment operator and self assignment

I was reading a article the other day and they were really adamant about checking for self assignment in the assignment operator. Then I read this really great article about being exception safe and using swap. ( http://www.cplusplus.com/articles/y8hv0pDG/ )

I noticed in the article he did not check for self assignment. I know he didnt forget. so can someone explain why. I dont want to be putting in there if some cases its pointless and cause confusion.
Checking for self assignment can be necessary when the object contains raw pointers that have to be deep-copied, because the standard "delete the pointer in *this, reallocate it, and copy from the rhs object to *this" doesn't work since "delete the pointer in *this" would also delete the pointer in rhs in the self-assignment case.

However, that is all irrelevant with the copy-swap idiom because the first part is to make a copy of the rhs. By making a copy of the rhs, I mean that raw pointers must be deep copied in the copy constructor. This obviates the need for a self-assignment check, since it now works, albeit a bit suboptimally since self-assignment should be a no-op. However, one can argue that the programmer who writes a = a; deserves what he gets. :)
haha ok
Topic archived. No new replies allowed.