Move capture in lambda

How do I capture by move (also known as rvalue reference) in a C++11 lambda?

I am trying to write something like this:

std::unique_ptr<int> myPointer(new int);

std::function<void(void)> example = [std::move(myPointer)]{
   *myPointer = 4;
};

6 Answers
6

Leave a Comment