title: error: call to implicitly-deleted copy constructor of unique_ptr with auto
body: <p>I have two template declarations as follows:</p>
  
  <pre><code>template &lt; typename T &gt;
        class node {
          public:
            ...
          const unique_ptr &lt; node &lt; T &gt;&gt; &amp; getParent();
          ...
          private:
            ...
          unique_ptr &lt; node &lt; T &gt;&gt; &amp; P; //for parent node
          ...
        };
  
      template &lt; typename T1, typename T2 &gt;
        class tree {
          public:
            tree(int, T2 &amp; );
          ...
          void travPreord();
          ...
          private:
            ...
        };
  </code></pre>
  
  <p>Within the definition of the public method </p>
  
  <pre><code>template&lt;typename T1, typename T2&gt; tree&lt;T1,T2&gt;::travPreord() 
  </code></pre>
  
  <p>I have the following code:</p>
  
  <pre><code>template &lt; typename T1, typename T2 &gt; 
      void tree &lt; T1, T2 &gt; ::travPreord() {
  
        //lambda definition
  
        function &lt; void(unique_ptr &lt; node &lt; T1 &gt;&gt; &amp; ) &gt; prntNode = [ &amp; ]
        (unique_ptr &lt; node &lt; T1 &gt;&gt; &amp; pN) {
  
          ...
  
          if(auto rPN = pN - &gt; getParent()) {
  
            ...
  
          }
  
        };
  
      }
  </code></pre>
  
  <p>For the assignment inside the if statement condition above, I get the following error from the compiler (g++ 4.2.1):</p>
  
  <blockquote>
    <p>error: call to implicitly-deleted copy constructor of
    'std::__1::unique_ptr >,
    std::__1::default_delete > > >'
    if(auto rPN = pN->getParent()){</p>
  </blockquote>
  
  <p>The arguments to the template instantiation highlighted in the error are supplied from the main():</p>
  
  <pre><code>int main() {
  
        vector &lt; string &gt; v;
  
        ...
  
        tree &lt; string, vector &lt; string &gt;&gt; T(v.size(), v);
  
        T.travPreord();
  
        ...
  
        return 0;
  
      }
  </code></pre>
  
  <p>I wrote the if statement condition under question on the following assumptions:</p>
  
  <ol>
  <li><p>It is possible to assign a unique_ptr to a reference.</p></li>
  <li><p>The auto keyword should deduce the type of the lvalue expression <code>rPN</code> to be the type of the rvalue expression <code>pN-&gt;getParent()</code>, which returns a type <code>unique_ptr&lt;node&lt;T&gt;&gt;&amp;.</code></p></li>
  </ol>
  
  <p>So I am not sure about the source of this error.</p>
  
  <p>Could anyone point to the same?</p>