News for hackers. Stuff that matters.
Re:The Anatomy of the Assignment Operator (1997) by conistonwater on Tuesday March 03, 2015 @04:00PM (#9140717)
Um, what's wrong with the simpler

    if (this == &that) return *this;
    TFoo tmp(that);
    swap(tmp);
    return *this;
(Assume swap does not throw, it's trivial to implement because swapping pointers wouldn't throw.) This way the constructor of tmp takes care of destroying partially-constructed objects and you don't need to do it by hand. It seems like the clean up code just repeats what the compiler would automatically generate for you in a constructor.

[This is from 1997, btw.]

Re:The Anatomy of the Assignment Operator (1997) by Sharlin on Tuesday March 03, 2015 @04:15PM (#9140810)
Yes, the copy-and-swap idiom [1] is the classic "correct" (but somewhat unintuitive) answer to this problem. It was probably not widely known in 1997, though.

[1] http://stackoverflow.com/questions/3279543/what-is-the-copy-...

Re:The Anatomy of the Assignment Operator (1997) by maxlybbert on Tuesday March 03, 2015 @04:28PM (#9140892)
According to the article, correctly implementing copy assignment wasn't widely known either.
Re:The Anatomy of the Assignment Operator (1997) by pdpi on Tuesday March 03, 2015 @02:31PM (#9140024)
It's an oft-quoted fact that Rust is meant to take stuff that good C/C++ programmers already do and build it into the language. If you weren't convinced of this before reading this post, then pay close attention to how important the author considers pointer ownership to be.
Re:The Anatomy of the Assignment Operator (1997) by mainland on Tuesday March 03, 2015 @04:40PM (#9140963)
The first "correct" solution will leak memory if the call to TSuperFoo::operator= throws an exception.
Re:The Anatomy of the Assignment Operator (1997) by dietrichepp on Tuesday March 03, 2015 @03:26PM (#9140471)
And this is why we use C++11 wherever we can.