title: How does one downcast a std::shared_ptr?
body: <p>Consider:</p>
  
  <pre><code>struct SomethingThatsABase
  {
      virtual bool IsChildOne() const { return false; }
      virtual bool IsChildTwo() const { return false; }
  };
  
  struct ChildOne : public SomethingThatsABase
  {
      virtual bool IsChildOne() const { return true; }
  };
  
  struct ChildTwo : public SomethingThatsABase
  {
      virtual bool IsChildTwo() const { return true; }
  };
  
  void SomeClientExpectingAChildOne(std::shared_ptr&lt;ChildOne&gt; const&amp; ptrOne)
  {
      //Does stuff
  }
  
  void SomeClient(std::shared_ptr&lt;SomethingThatsABase&gt; const&amp; ptr)
  {
      if (ptr-&gt;IsChildOne())
      {
          SomeClientExpectingAChildOne(ptr); //Oops.
          //Hmm.. can't static_cast here, because we need a `shared_ptr` out of it.
      }
  }
  </code></pre>
  
  <p>(Note that I can't simply do a <code>std::shared_ptr&lt;ChildOne&gt;(static_cast&lt;ChildOne*&gt;(ptr.get()))</code>, because then the reference counts don't get shared between the two <code>shared_ptr</code>s)</p>