title: Wrapper to build std::unique_ptr with plain function deleters
body: <p>I was trying to implement an <code>std::unique_ptr</code> factory that I could use like this:</p>
  
  <pre><code>auto fd = my_make_unique&lt;fclose&gt;(fopen("filename", "r"));
  </code></pre>
  
  <p>I.e., pass the deleter function as a template argument.</p>
  
  <p>My best attempt in C++11 was:</p>
  
  <pre><code>template&lt;typename D, D deleter, typename P&gt;
  struct Deleter {
      void operator()(P* ptr) {
          deleter(ptr);
      }
  };
  
  template&lt;typename D, D deleter, typename P&gt;
  std::unique_ptr&lt;P, Deleter&lt;D, deleter, P&gt;&gt; my_make_unique(P* ptr)
  {
      return std::unique_ptr&lt;P, Deleter&lt;D, deleter, P&gt;&gt;(ptr);
  }
  </code></pre>
  
  <p>In C++14 it is much cleaner:</p>
  
  <pre><code>template&lt;typename D, D deleter, typename P&gt;
  auto my_make_unique(P* ptr)
  {
      struct Deleter {
          void operator()(P* ptr) {
              deleter(ptr);
          }
      };
      return std::unique_ptr&lt;P, Deleter&gt;(ptr);
  }
  </code></pre>
  
  <p>But both solutuions would require me to pass the type of <code>&amp;fclose</code> before <code>fclose</code> itself as template argument:</p>
  
  <pre><code>auto fd = my_make_unique&lt;decltype(&amp;fclose), fclose&gt;(fopen("filename", "r"));
  </code></pre>
  
  <p>Is it possible to get rid of <code>decltype(&amp;fclose)</code> template argument in C++11? What about in C++14?</p>
  
  <p>EDIT: Why this question is not a duplicate of <a href="https://stackoverflow.com/questions/395123/raii-and-smart-pointers-in-c">RAII and smart pointers in C++</a>: referenced question is about general RAII techniques in C++, and one of the answers estates that <code>std::unique_ptr</code> can be used for this purpose. I am already familiar with RAII pattern and how <code>std::unique_ptr</code> is a solution, but I am concerned with present question on how to build an easier to use abstraction to this frequent case I encounter when interacting with C libraries.</p>