title: How to pass unique_ptr<T> in place of a raw *output* pointer parameter?
body: <p>I have a <em>pre-existing</em> function in an <em>external</em> library, which looks like this;</p>
  
  <pre><code>bool CreateTheThing(MyThing *&amp; pOut);
  </code></pre>
  
  <p>In short; I give it a raw pointer (by reference), and the function allocates memory and assigns my pointer to the newly-allocated object.  When the function returns, it is <em>my</em> responsibility to free the memory, when I'm done.</p>
  
  <p>Obviously, I'd like to store this result into a <code>unique_ptr&lt;MyThing&gt;</code>, and avoid the manual <code>delete</code>.</p>
  
  <p>I <em>could</em> create a temporary raw pointer to use with the API call, and pass it into the constructor for the <code>unique_ptr</code>;</p>
  
  <pre><code>MyThing* tempPtr;
  CreateTheThing(tempPtr);
  unique_ptr&lt;MyThing&gt; realPtr = unique_ptr&lt;MyThing&gt;(tempPtr);
  </code></pre>
  
  <p>Is there a more direct method than this?  One which doesn't require a temporary raw pointer?  Ideally, there would be a method of <code>unique_ptr</code> which exposes its internal pointer in a way that could work directly with the <code>CreateTheThing</code> method?  </p>
  
  <p><code>unique_ptr&lt;T&gt;::get()</code> does not allow this, to my knowledge.  The pointer it returns is not a reference to the internally-used pointer.</p>