title: Passing a unique_ptr to a function which adds it to a vector
body: <p>I have a class that holds a vector of unique_ptr. The class also has a method to add an element to the vector.</p>
  
  <pre><code>class PointerVector
  {
    public:
      void addPointer(std::unique_ptr&lt;int&gt; p);
  
    private:
      std::vector&lt;std::unique_ptr&lt;int&gt;&gt; mPointers;
  };
  </code></pre>
  
  <p>The <code>addPointer</code> method definition:</p>
  
  <pre><code>void PointerVector::addPointer(std::unique_ptr&lt;int&gt; p)
  {
    mPointers.emplace_back(std::move(p));
  }
  </code></pre>
  
  <p>So I use <code>std::move</code> to transfer ownership of the pointer.</p>
  
  <p>When I call <code>addPointer</code>, I also use <code>std::move</code>:</p>
  
  <pre><code>PointerVector pv;
  std::unique_ptr&lt;int&gt; i(new i(1));
  pv.addPointer(std::move(i));
  </code></pre>
  
  <p>Is this the correct way to do things? It feels like a hassle having to call <code>std::move</code> all the time.</p>
  
  <p><strong>Edit</strong>: I actually want to hold a vector of unique_ptr to a class, but I wanted to try with an int first, to make things easier.</p>