Why can't a pointer be automatically converted into a unique_ptr when returning it?
<p>Let me pose my question through an example.</p>

<pre><code>#include &lt;memory&gt;

std::unique_ptr&lt;int&gt; get_it() {
        auto p = new int;
        return p;
}

int main() {
        auto up ( get_it() );
        return 0;
}
</code></pre>

<p>This fails to compile with the following error:</p>

<pre><code>a.cpp:5:9: error: could not convert ‘p’ from ‘int*’ to ‘std::unique_ptr&lt;int&gt;’
  return p;
         ^
</code></pre>

<p>Why isn't there an automatic conversion from a raw pointer to a unique one here? And what should I be doing instead? </p>

<p>Motivation: I understand it's supposed to be good practice to use smart pointers for ownership to be clear; I'm getting a pointer (which I own) from somewhere, as an <code>int*</code> in this case, and I (think I) want it in a <code>unique_ptr</code>.</p>

<hr>

<p>If you're considering commenting or adding your own answer, please address <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4029.pdf" rel="noreferrer">Herbert Sutter's arguments for this to be possible in proposal N4029</a>.</p>