#include <iostream>
#include <string>
#include <functional>
#include <vector>
class Test{
public:
Test() = default;
Test(const Test& other) = delete;
Test& operator=(const Test& other) = delete;
Test(Test&& other) = default;
Test& operator=(Test&& other) = default;
void setFunction(){
auto a = &Test::a;
lambda = [=](Test *t){
(t->*a) = 2;
};
}
int callAndReturn(){
lambda(this);
return a;
}
private:
std::function<void(Test*)> lambda;
int a = 50;
};
int main()
{
Test t;
t.setFunction();
std::vector<Test> elements;
elements.push_back(std::move(t));
std::cout << elements[0].callAndReturn() << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPHZlY3Rvcj4KCgpjbGFzcyBUZXN0ewoKcHVibGljOgoKICAgIFRlc3QoKSA9IGRlZmF1bHQ7CiAgICBUZXN0KGNvbnN0IFRlc3QmIG90aGVyKSA9IGRlbGV0ZTsKICAgIFRlc3QmIG9wZXJhdG9yPShjb25zdCBUZXN0JiBvdGhlcikgPSBkZWxldGU7CiAgICBUZXN0KFRlc3QmJiBvdGhlcikgPSBkZWZhdWx0OwogICAgVGVzdCYgb3BlcmF0b3I9KFRlc3QmJiBvdGhlcikgPSBkZWZhdWx0OwoKCgogICAgdm9pZCBzZXRGdW5jdGlvbigpewogICAgICAgIGF1dG8gYSA9ICZUZXN0OjphOwogICAgICAgIGxhbWJkYSA9IFs9XShUZXN0ICp0KXsKICAgICAgICAgICAgKHQtPiphKSA9IDI7CiAgICAgICAgfTsKICAgIH0gIAoKICAgIGludCBjYWxsQW5kUmV0dXJuKCl7CiAgICAgICBsYW1iZGEodGhpcyk7CiAgICAgICByZXR1cm4gYTsKICAgIH0KCnByaXZhdGU6CiAgICBzdGQ6OmZ1bmN0aW9uPHZvaWQoVGVzdCopPiBsYW1iZGE7IAogICAgaW50IGEgPSA1MDsKfTsKCgppbnQgbWFpbigpCnsKICBUZXN0IHQ7CiAgdC5zZXRGdW5jdGlvbigpOwogIHN0ZDo6dmVjdG9yPFRlc3Q+IGVsZW1lbnRzOwogIGVsZW1lbnRzLnB1c2hfYmFjayhzdGQ6Om1vdmUodCkpOwogIHN0ZDo6Y291dCA8PCBlbGVtZW50c1swXS5jYWxsQW5kUmV0dXJuKCkgPDwgc3RkOjplbmRsOwp9