title: using swap to implement move assignment
body: <p>Something occurred to me which I think it completely reasonable, but I'd like people's opinion on it in case I'm just completely missing something. So firstly, my understanding of <code>T&amp; operator=(T&amp;&amp; rhs)</code> is that we <strong>don't care</strong> what the contents of <code>rhs</code> are when we are done, just that the contents have been moved into <code>this</code> and that <code>rhs</code> is safely destructable.</p>
  
  <p>That being said, a common exception safe implementation of the copy-assignment operator, assuming that swaps are cheap, looks like this:</p>
  
  <pre><code>T&amp; operator=(const T&amp; rhs) {
      if(this != &amp;rhs) {
          T(rhs).swap(*this);
      }
      return *this;
  }
  </code></pre>
  
  <p>So one natural way to implement the move-assignment operator would be like this:</p>
  
  <pre><code>T&amp; operator=(T&amp;&amp; rhs) {
      if(this != &amp;rhs) {
          T(std::move(rhs)).swap(*this);
      }
      return *this;
  }
  </code></pre>
  
  <p>But then it occured to me, <code>rhs</code> doesn't have to be empty! So, why not just do a plain <code>swap</code>?</p>
  
  <pre><code>T&amp; operator=(T&amp;&amp; rhs) {
      rhs.swap(*this); // is this good enough?
      return *this;
  }
  </code></pre>
  
  <p>I <strong>think</strong> that this satisfies what the move-assignment operator needs to do... but like I said, this just occurred to me, so I assume that it's possible that I'm missing something.</p>
  
  <p>The only "downside" that I can think of is that things owned by <code>this</code> will potentially live longer using the plain swap when compared to the version which does a move-construct/swap.</p>
  
  <p>Thoughts?</p>