title: What is boost's shared_ptr(shared_ptr<Y> const & r, T * p) used for?
body: <p><code>boost::shared_ptr</code> has an unusual constructor</p>
  
  <pre><code>template&lt;class Y&gt; shared_ptr(shared_ptr&lt;Y&gt; const &amp; r, T * p);
  </code></pre>
  
  <p>and I am a little puzzled as to what this would be useful for. Basically it shares ownership with <code>r</code>, but <code>.get()</code> will return <code>p</code>. <strong>not</strong> <code>r.get()</code>!</p>
  
  <p>This means you can do something like this:</p>
  
  <pre><code>int main() {
      boost::shared_ptr&lt;int&gt; x(new int);
      boost::shared_ptr&lt;int&gt; y(x, new int);
  
      std::cout &lt;&lt; x.get() &lt;&lt; std::endl;
      std::cout &lt;&lt; y.get() &lt;&lt; std::endl;
  
      std::cout &lt;&lt; x.use_count() &lt;&lt; std::endl;
      std::cout &lt;&lt; y.use_count() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>And you will get this:</p>
  
  <pre><code>0x8c66008
  0x8c66030
  2
  2
  </code></pre>
  
  <p>Note that the pointers are separate, but they both claim to have a <code>use_count</code> of 2 (since they share ownership of the same object).</p>
  
  <p>So, the <code>int</code> owned by <code>x</code> will exist as long as <code>x</code> <strong>or</strong> <code>y</code> is around. And if I understand the docs correct, the second <code>int</code> never gets destructed. I've confirmed this with the following test program:</p>
  
  <pre><code>struct T {
      T() { std::cout &lt;&lt; "T()" &lt;&lt; std::endl; }
      ~T() { std::cout &lt;&lt; "~T()" &lt;&lt; std::endl; }
  };
  
  int main() {
      boost::shared_ptr&lt;T&gt; x(new T);
      boost::shared_ptr&lt;T&gt; y(x, new T);
  
      std::cout &lt;&lt; x.get() &lt;&lt; std::endl;
      std::cout &lt;&lt; y.get() &lt;&lt; std::endl;
  
      std::cout &lt;&lt; x.use_count() &lt;&lt; std::endl;
      std::cout &lt;&lt; y.use_count() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>This outputs (as expected):</p>
  
  <pre><code>T()
  T()
  0x96c2008
  0x96c2030
  2
  2
  ~T()
  </code></pre>
  
  <p>So... what is the usefulness of this unusual construct which shares ownership of one pointer, but <strong>acts</strong> like another pointer (which it does not own) when used.</p>