title: How do I pass a unique_ptr argument to a constructor or a function?
body: <p>I'm new to move semantics in C++11 and I don't know very well how to handle <code>unique_ptr</code> parameters in constructors or functions. Consider this class referencing itself:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;memory&gt;
  
  class Base
  {
    public:
  
      typedef unique_ptr&lt;Base&gt; UPtr;
  
      Base(){}
      Base(Base::UPtr n):next(std::move(n)){}
  
      virtual ~Base(){}
  
      void setNext(Base::UPtr n)
      {
        next = std::move(n);
      }
  
    protected :
  
      Base::UPtr next;
  
  };
  </code></pre>
  
  <p>Is this how I should write functions taking <code>unique_ptr</code> arguments?</p>
  
  <p>And do I need to use <code>std::move</code> in the calling code?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>Base::UPtr b1;
  Base::UPtr b2(new Base());
  
  b1-&gt;setNext(b2); //should I write b1-&gt;setNext(std::move(b2)); instead?
  </code></pre>