1 Jul
2013
1 Jul
'13
10:13 p.m.
On 13-07-01 02:42 PM, Andrew Ho wrote:
This allows this to be done:
val1 + val2 = val3;
changing the return type to const T would allow the compiler to catch this, but now doing val1 + val2 + val3 must always use copy semantics instead of move semantics.
Two answers: tell your users not to do a+b=c, or tell authors of value type to mark a rvalue overload of operator= "=delete", like: string & operator=(string &&) && = delete; string & operator=(const string &) && = delete; Nobody does this, I'm guessing, because it's just not a problem in practice. I've personally never seen this mistake in real code, and wouldn't worry too much about it. -- Eric Niebler Boost.org