Boost logo

Boost :

Subject: Re: [boost] [Operators] Update, const-correctness and operator chaining
From: Eric Niebler (eniebler_at_[hidden])
Date: 2013-07-01 18:13:16

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 list run by bdawes at, gregod at, cpdaniel at, john at