title: A simple tree class with smart pointers
body: <p>I am learning smart pointers. Using smart pointers, I can think of a simple class to implement a binary tree, as shown below.</p>
  
  <pre><code>class BinTree
  {
    ....
    std::unique_ptr&lt;BinTree&gt; leftChild;
    std::unique_ptr&lt;BinTree&gt; rightChild;
  };
  </code></pre>
  
  <p>Things get complicated though, If I also want to keep a pointer to the parent, because in that case each node will be pointed from 3 nodes (2 children and one parent). One could use <code>shared_ptr</code> of course, but I've read that it is too inefficient. So, what would be the best solution here? </p>
  
  <p>I was thinking of using a <code>weak_ptr</code> to point the parent because children would not be creating/owning their parents anyway, but a <code>weak_ptr</code> cannot be created from a <code>unique_ptr</code>, only a <code>shared_ptr</code>.</p>