title: How to capture a unique_ptr into a lambda expression?
body: <p>I have tried the following:</p>
  
  <pre><code>std::function&lt;void ()&gt; getAction(std::unique_ptr&lt;MyClass&gt; &amp;&amp;psomething){
      //The caller given ownership of psomething
      return [psomething](){ 
          psomething-&gt;do_some_thing();
          //psomething is expected to be released after this point
      };
  }
  </code></pre>
  
  <p>But it does not compile. Any ideas?</p>
  
  <p>UPDATE:</p>
  
  <p>AS suggested, some new syntax is required to explicitly specify we need to transfer the ownership to the lambda, I am now thinking about the following syntax:</p>
  
  <pre><code>std::function&lt;void ()&gt; getAction(std::unique_ptr&lt;MyClass&gt; psomething){
      //The caller given ownership of psomething
      return [auto psomething=move(psomething)](){ 
          psomething-&gt;do_some_thing();
          //psomething is expected to be released after this point
      };
  }
  </code></pre>
  
  <p>Would it be a good candidate?</p>
  
  <p>UPDATE 1:</p>
  
  <p>I will show my implementation of <code>move</code> and <code>copy</code> as following:</p>
  
  <pre><code>template&lt;typename T&gt;
  T copy(const T &amp;t) {
      return t;
  }
  
  //process lvalue references
  template&lt;typename T&gt;
  T move(T &amp;t) {
      return std::move(t);
  }
  
  class A{/*...*/};
  
  void test(A &amp;&amp;a);
  
  int main(int, char **){
      A a;
      test(copy(a));    //OK, copied
      test(move(a));    //OK, moved
      test(A());        //OK, temporary object
      test(copy(A()));  //OK, copying temporary object
      //You can disable this behavior by letting copy accepts T &amp;  
      //test(move(A())); You should never move a temporary object
      //It is not good to have a rvalue version of move.
      //test(a); forbidden, you have to say weather you want to copy or move
      //from a lvalue reference.
  }
  </code></pre>