title: How to move unique_ptr to raw pointer?
body: <p>I have a function that is used to allocate a buffer with given size. The buffer will be preprocess/filled some data before return. This preprocess may return false to represent this buffer is not processed right. So I want to apply <strong>RAII</strong> on this buffer to avoid early return without <code>delete[]</code> it.</p>
  
  <p>Usually I use <code>unique_ptr</code> to help me to auto release the local allocated object. In this case I need to return this allocated object (Owned by <code>unique_ptr</code>) and <strong>transfer the ownership to caller</strong>. But the compiler complains that I cannot convert <code>unique_ptr&lt;T[]&gt;</code> to <code>T*</code> while I <code>std::move</code> the <code>unique_ptr</code>. It looks like <code>unique_ptr</code> can only be moved to another <code>unique_ptr</code> instead of raw pointer.</p>
  
  <p>Is any way to transfer the ownership from <code>unique_ptr</code> to a <code>raw pointer</code>? Or just the <code>unique_ptr</code> is not suitable for this case?</p>
  
  <pre><code>bool PreProcess(int* v) { /* return nothing wrong? true: false; */ }
  
  bool GetBuffer(int** ppRetBuf, int size)
  {
      std::unique_ptr&lt;int[]&gt; buf(new (std::nothrow) int[size]());
      if(PreProcess(buf.get())
      {
          *ppRetBuf = std::move(buf); // Compiler complains:  
                                      // Error C2440 '=': cannot convert from 'std::unique_ptr&lt;int [],std::default_delete&lt;_Ty&gt;&gt;' to 'int *'
          return true;
      }
      return false; // No need to manually delete[] failure buffer
  }
  
  int main()
  {
      int * buf = nullptr;
      GetBuffer(&amp;buf, 100);
  }
  </code></pre>