title: shared_ptr with non-pointer resources
body: <p>In C++11 is it possible to use <code>shared_ptr</code> to control non-pointer resources?</p>
  
  <hr>
  
  <p>It is possible to use <code>unique_ptr</code> to manage non-pointer resources.  This is done by implementing a custom deleter class which provides:</p>
  
  <ol>
  <li>A <code>typedef {TYPE} pointer;</code> where <code>{TYPE}</code> is the non-pointer resource type</li>
  <li><code>operator()(pointer)</code> which frees the controlled resource</li>
  </ol>
  
  <p>...and then instantiating a <code>unique_ptr</code> with the custom deleter as the second template parameter.</p>
  
  <p>For example, under Windows it is possible to create a <code>unique_ptr</code> which manages a <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms685104%28v=vs.85%29.aspx" rel="noreferrer">service control handle</a>.  This handle type is not freed by calling <code>delete</code>, but by calling <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682028%28v=vs.85%29.aspx" rel="noreferrer"><code>CloseServiceHandle()</code></a>.  Here is sample code which does this:</p>
  
  <h2>Custom Deleter</h2>
  
  <pre><code>struct SvcHandleDeleter
  {
      typedef SC_HANDLE pointer;
      SvcHandleDeleter() {};
  
      template&lt;class Other&gt; SvcHandleDeleter(const Other&amp;) {};
  
      void operator()(pointer h) const
      {
          CloseServiceHandle(h);
      }
  };
  
  
  typedef std::unique_ptr&lt;SC_HANDLE,SvcHandleDeleter&gt; unique_sch;
  </code></pre>
  
  <h2>Instantiation</h2>
  
  <pre><code>unique_sch scm(::OpenSCManagerA(0, 0, SC_MANAGER_ALL_ACCESS));
  </code></pre>
  
  <hr>
  
  <p>Is it possible to use <code>shared_ptr</code> to control a non-pointer resource as well?</p>
  
  <p>According to the documentation, there are <a href="http://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr" rel="noreferrer"><code>shared_ptr</code> constructor overloads</a> which take provide the means to provide a custom deleter class, but none of the constructors accept a resource type that is not either a pointer or a wrapper around a pointer.</p>
  
  <p>How can this be done?</p>