title: Move semantics to avoid temporary object creation
body: <p>I am trying to do operations between large objects and I experiment with r-value references to avoid temporary object creations.
  The experiment is the following code, but the result is not what I expected.</p>
  
  <p>The code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  struct A
  {
      A() = default;
      A(const A&amp; a) { cout &lt;&lt; "copy ctor" &lt;&lt; endl; }
      A(A&amp;&amp; a) { cout &lt;&lt; "move ctor" &lt;&lt; endl; }
      A &amp;operator=(const A&amp; a) { cout &lt;&lt; "copy assign" &lt;&lt; endl; return *this; }
      A &amp;operator=(A&amp;&amp; a) { cout &lt;&lt; "move assign" &lt;&lt; endl; return *this; }
      A &amp;operator*=(double s) { cout &lt;&lt; "this = this *= s" &lt;&lt; endl; return *this; }
      A operator*(double s) const { cout &lt;&lt; "A = const this * s" &lt;&lt; endl; return *this; }
      A &amp;operator+=(const A &amp;b) { cout &lt;&lt; "this = this + const A&amp;" &lt;&lt; endl; return *this; }
      A operator+(const A &amp;b) const { cout &lt;&lt; "A = const this + const A&amp;" &lt;&lt; endl; return *this; }
      A &amp;operator+(A &amp;&amp;b) const { cout &lt;&lt; "A&amp;&amp; = const this + A&amp;&amp; --&gt; "; return b += *this; }
  };
  A &amp;operator+(A &amp;&amp;a, const A &amp;b) { cout &lt;&lt; "A&amp;&amp; = A&amp;&amp; + const A&amp; --&gt; "; return a += b; }
  A &amp;operator*(A &amp;&amp;a, double s) { cout &lt;&lt; "A&amp;&amp; = A&amp;&amp; * s --&gt; "; return a *= s; }
  
  int main()
  {
      A a,b,c,d;
      a = b + a * 4 + /*operator*(static_cast&lt;A&amp;&amp;&gt;(d), 2)*/ d * 2 + (A() + c) * 5;
  
      return 0;
  }
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>A&amp;&amp; = A&amp;&amp; + const A&amp; --&gt; this = this + const A&amp;     // A() + c
  A = const this * s                  // (...) * 5
  copy ctor                       // ???
  A = const this * s                  // d * 2
  copy ctor                       // ???
  A = const this * s                  // a * 4
  copy ctor                       // ???
  A&amp;&amp; = const this + A&amp;&amp; --&gt; this = this + const A&amp;   // (d*2) + (...)
  A&amp;&amp; = const this + A&amp;&amp; --&gt; this = this + const A&amp;   // (a*4) + (...)
  A&amp;&amp; = const this + A&amp;&amp; --&gt; this = this + const A&amp;   // b + (...)
  copy assign                     // a = (...)
  </code></pre>
  
  <p>What I expect:</p>
  
  <pre><code>A&amp;&amp; = A&amp;&amp; + const A&amp; --&gt; this = this + const A&amp;     // A() + c
  A&amp;&amp; = A&amp;&amp; * s --&gt; this = this *= s          // (...) * 5
  A&amp;&amp; = A&amp;&amp; * s --&gt; this = this *= s          // (...) * 2    d is not used anymore, so I want to move semantics
  A = const this * s      // a * 4    a is not used anymore, but I want to keep semantics
  A&amp;&amp; = A&amp;&amp; + const A&amp; --&gt; this = this + const A&amp; // (d*2) + (...)
  A&amp;&amp; = A&amp;&amp; + const A&amp; --&gt; this = this + const A&amp; // (a*4) + (...)
  A&amp;&amp; = A&amp;&amp; + const A&amp; --&gt; this = this + const A&amp; // b + (...)
  move assign     // a = (...)
  </code></pre>