title: std::move on object pointed to by a unique_ptr
body: <p>Is it legal to move objects pointed to by a <code>unique_ptr</code> rather than the uptr itself? e.g. <code>std::unique_ptr&lt;Foo&gt; uptr(new Foo()); Foo bar = std::move(*uptr);</code> Any potential gotchas?</p>
  
  <p><code>std::move</code> semantics state that on moving, the object is in valid but unspecified state. Is the <code>unique_ptr</code> <code>reset</code>/<code>release</code> still safe?</p>
  
  <p>I tried this for vectors and it works - <a href="https://ideone.com/d1OfUm" rel="nofollow">https://ideone.com/d1OfUm</a></p>
  
  <pre><code>int main() {
    std::unique_ptr&lt;std::vector&lt;int&gt; &gt; uptr(new std::vector&lt;int&gt;);
  
    uptr-&gt;push_back(23);
    uptr-&gt;push_back(45);
    uptr-&gt;push_back(34);
  
    std::cout &lt;&lt; "uptr size = " &lt;&lt; uptr-&gt;size() &lt;&lt; std::endl;
    for (auto i=0; i &lt; uptr-&gt;size(); ++i) {
      std::cout &lt;&lt; "(*uptr)[" &lt;&lt; i &lt;&lt; "] = " &lt;&lt; (*uptr)[i] &lt;&lt; std::endl;
    }
    std::cout &lt;&lt; std::endl;
  
    std::vector&lt;int&gt; v = std::move(*uptr);
  
    std::cout &lt;&lt; "uptr size post move = " &lt;&lt; uptr-&gt;size() &lt;&lt; std::endl;
    for (auto i=0; i &lt; uptr-&gt;size(); ++i) {
      std::cout &lt;&lt; "(*uptr)[" &lt;&lt; i &lt;&lt; "] = " &lt;&lt; (*uptr)[i] &lt;&lt; std::endl;
    }
    std::cout &lt;&lt; std::endl;
  
    std::cout &lt;&lt; "moved vec size = " &lt;&lt; v.size() &lt;&lt; std::endl;
    for (auto i=0; i &lt; v.size(); ++i) {
      std::cout &lt;&lt; "v[" &lt;&lt; i &lt;&lt; "] = " &lt;&lt; v[i] &lt;&lt; std::endl;
    }
    std::cout &lt;&lt; std::endl;
  
    return 0;
  }
  </code></pre>