we can move capture variable in c++ as follow.
string s;
auto f = [s = std::move(s)](){ /* do something */ };
we can copy capture this as follow.
auto f = [*this](){ /* do something */ };
but how can we move capture this in rvalue reference member function?
class Obj {
// ...
auto method() && {
// do something.
return [ /* "*this = std::move(*this)" is a syntax error */ ](){
// do something.
};
}
// ...
};
You can normally assign it to a variable. ;-)
Note that the type of
selfisconst Obj. If you want it to be nonconst, you have to make the lambdamutable.