#include <iostream>
#include <functional>
using namespace std;
struct Block {
function<int()> callback;
};
void set_callback(Block &block) {
int x = 1;
int y = 2;
block.callback = [x=std::move(x), y=std::move(y)] {
return x + y;
};
}
void run_callback(const Block &block) {
cout << "result: " << block.callback() << endl;
}
int main() {
Block block;
set_callback(block);
run_callback(block);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBCbG9jayB7CglmdW5jdGlvbjxpbnQoKT4gY2FsbGJhY2s7Cn07Cgp2b2lkIHNldF9jYWxsYmFjayhCbG9jayAmYmxvY2spIHsKCWludCB4ID0gMTsKCWludCB5ID0gMjsKCQoJYmxvY2suY2FsbGJhY2sgPSBbeD1zdGQ6Om1vdmUoeCksIHk9c3RkOjptb3ZlKHkpXSB7CgkJcmV0dXJuIHggKyB5OwoJfTsKfQoKdm9pZCBydW5fY2FsbGJhY2soY29uc3QgQmxvY2sgJmJsb2NrKSB7Cgljb3V0IDw8ICJyZXN1bHQ6ICIgPDwgYmxvY2suY2FsbGJhY2soKSA8PCBlbmRsOwp9CgppbnQgbWFpbigpIHsKCQoJQmxvY2sgYmxvY2s7CgkKCXNldF9jYWxsYmFjayhibG9jayk7CgkKCXJ1bl9jYWxsYmFjayhibG9jayk7CgkKCXJldHVybiAwOwp9