title: Typedef a shared_ptr type with a static custom deleter, similar to unique_ptr
body: <p>I have read through many questions on SO on custom deleter for <code>shared_ptr</code> and <code>unique_ptr</code>, and the difference between the two. But, I still haven't found any clear answer to this question:</p>
  
  <p>How can one best go about creating a type that acts as a <code>shared_ptr</code> with a custom deleter, similar to how <code>unique_ptr</code> has the deleter as part of the type definition?</p>
  
  <p>For <code>unique_ptr</code> usage, I use a deleter class, that handles deletion of individual types (limiting it to just two types, for brevity):</p>
  
  <pre><code>struct SDL_Deleter {                                
    void operator()( SDL_Surface* ptr ) { if (ptr) SDL_FreeSurface( ptr );} 
    void operator()( SDL_RWops* ptr )   { if (ptr) SDL_RWclose( ptr );} 
  };
  
  using SurfacePtr = std::unique_ptr&lt;SDL_Surface, SDL_Deleter&gt;;
  using RWopsPtr = std::unique_ptr&lt;SDL_RWops, SDL_Deleter&gt;;
  </code></pre>
  
  <p>Which can be used with something like</p>
  
  <pre><code>SurfacePtr surface(IMG_Load("image.png"));
  </code></pre>
  
  <p>And will call <code>SDL_FreeSurface</code> upon destruction.</p>
  
  <hr>
  
  <p>This is all fine and well. However, how does one go about achieving the same for <code>shared_ptr</code>? Its type is defined as</p>
  
  <pre><code>template&lt; class T &gt; class shared_ptr;
  </code></pre>
  
  <p>and the way to provide a custom deleter is through the constructor. It doesn't feel right that the user of the <code>shared_ptr</code> wrapper needs to know which pointer type is wrapped, and how that pointer is supposed to be deleted. What would be the best way to achieve the same kind of usage as with the <code>unique_ptr</code> example of above.</p>
  
  <p>In other words, that I could end up with:</p>
  
  <pre><code>SurfaceShPtr surface(IMG_Load("image.png"));
  </code></pre>
  
  <p>Instead of of something like</p>
  
  <pre><code>SurfaceShPtr surface(IMG_Load("image.png"),
                       [=](SDL_Surface* ptr){SDL_FreeSurface(ptr);});
  </code></pre>
  
  <p>Or, just slightly better</p>
  
  <pre><code>SurfaceShPtr surface(IMG_Load("image.png"),
                       SDL_Deleter());
  </code></pre>
  
  <hr>
  
  <p>Is there a way to do this, without having to create a RAII wrapper class (instead of a typedef), adding even more overhead?</p>
  
  <hr>
  
  <p>If the answer is "this isn't possible". Why not?</p>