As https://stackoverflow.com/a/3279550/943619 ably describes, the right way to implement operator=
is usually:
my_type& operator=(my_type other) {
swap(*this, other);
return *this;
}
friend void swap(my_type& lhs, my_type& rhs) { ... } // This can vary some.
However, Howard Hinnant has pointed out that you can sometimes do significantly better by implementing separate overloads for lvalue and rvalue arguments:
my_type& operator=(const my_type& other) { ... }
my_type& operator=(my_type&& other) { ... }
Clearly the 2-overload solution can save one move in several cases, but such a small improvement is unlikely to show up in benchmarks. I'm looking, instead, for the cases where writing 2 overloads can ~double the performance.