title: Why shared pointer assignment does 'swap'?
body: <p>As i understand when assigned shared ptr should behave like:</p>
  
  <p>a) <code>if (--this-&gt;count == 0) { release this-&gt;count and this-&gt;obj }</code></p>
  
  <p>b) <code>this-&gt;count = r-&gt;count, this-&gt;obj = r-&gt;obj;</code></p>
  
  <p>What boost does is just</p>
  
  <pre><code>shared_ptr &amp; operator=( shared_ptr const &amp; r ) BOOST_NOEXCEPT
  {
      this_type(r).swap(*this);
      return *this;
  }
  </code></pre>
  
  <p>So what is the magic behind swap and why this works?</p>