News for hackers. Stuff that matters.
Re:C++ Programming Questions to Ask on Interview (2017) by gpderetta on Friday October 19, 2018 @04:30AM (#18255082)
actually that move assignment operator is not ideal. The foo parameter won't be destroyed immediately but only at the end of whatever scope (if any) it was at the call site.

The idiomatic copy and swap is like this:

T& operator =(T x) // note pass by value { std::swap(this, x); return this; }

This acts both as a normal and move assignment operator (if T is not copy constructible);

edit: how do you get HN to show asterisks? There should be one before each 'this'

Re:C++ Programming Questions to Ask on Interview (2017) by arh68 on Friday October 19, 2018 @07:04AM (#18255764)
Prefix each line with 4 spaces:

    T& operator =(T x) // note pass by value
    { std::swap(*this, x); return *this; }