title: How can I make a shared_ptr from an opaque pointer typedef? (or: how can I "unwrap" typedef?)
body: <p>If you have an opaque pointer typedef, is there a way to dynamically refer to the pointed-to type, say, for use in templates? For instance, say you have something like this:</p>
  
  <pre><code>struct Foo; // Forward declared struct
  typedef Foo* FooPtr; // Opaque pointer
  </code></pre>
  
  <p>Because the smart pointer types are templates in terms of the pointer-to type, to define a <code>std::shared_ptr</code> of this, it seems that you have to say:</p>
  
  <pre><code>std::shared_ptr&lt;struct Foo&gt; theSharedPtr;
  </code></pre>
  
  <p>Is there any way to define such a pointer without "manually" unwrapping the opaque pointer typedef?  I feel like I must be missing something obvious here, but you might imagine something like these (note: these do not work):</p>
  
  <pre><code>std::shared_ptr&lt;*FooPtr&gt; theSharedPointer;
  // or
  std::shared_ptr&lt;pointedto(FooPtr)&gt; theSharedPointer;
  </code></pre>
  
  <p>I feel like this should be possible. Am I missing something? I feel like this is an impending forehead-smacking moment...</p>
  
  <p>EDIT: Noodling around some more, it appears that, in the common case, <code>shared_ptr&lt;T&gt;</code> wants to take the <code>sizeof(T)</code>. You can get around this by providing a deleter to the constructor. I suspect this makes this a bit of an edge case, but it still seems like with all the type wrangling in C++, I should be able to "unwrap" a pointer type without doing so by hand.</p>