title: Indicating (non) transfer of ownership with unique_ptr
body: <p>Suppose I have a class like this:</p>
  
  <pre><code>class Node {
  public:
      Node(Node* parent = 0) : mParent(parent) {}
      virtual ~Node() {
          for(auto p : mChildren) delete p;
      }
  
      // Takes ownership
      void addChild(Node* n);
  
      // Returns object with ownership
      Node* firstChild() const;
  
      // Does not take ownership
      void setParent(Node* n) { mParent = n; }
  
      // Returns parent, does not transfer ownership
      Node* parent() const { return mParent; }
  
  private:
  list&lt;Node*&gt; mChildren;
  Node* mParent;
  };
  </code></pre>
  
  <p>I'd now like to use smart pointers and/or rvalue references to indicate where ownership is and isn't transferred.</p>
  
  <p>My first guess would be to change <code>mChildren</code> to contain <code>unique_ptr</code>s, adapting the function signatures as follows.</p>
  
  <pre><code>    // Takes ownership
      void addChild(unique_ptr&lt;Node&gt; n);
  
      // Returns object with ownership
      unique_ptr&lt;Node&gt;&amp; firstChild() const;
  
      // Does not take ownership
      void setParent(Node* n) { mParent = n; }
  
      // Returns parent, does not transfer ownership
      Node* parent() const { return mParent; }
  </code></pre>
  
  <p>Now, this would be kind of problematic when I need to pass the result of <code>Node::firstChild()</code> to some function that observes it, but does not take ownership, as I'd need to explicitly call <code>.get()</code> on the <code>unique_ptr</code>, which as I understand it, is not recommended.</p>
  
  <p>What is the correct and recommended way to indicate ownership using <code>unique_ptr</code> without having to resort to using <code>.get()</code> and passing around bare pointers?</p>