#include <iostream>
#include <memory>
using namespace std;
void foo(bool & currState, bool newState)
{
bool prevState = currState;
currState = newState;
std::unique_ptr<bool, std::function<void(bool*)>> txEnder(&prevState, [&prevState, &currState](bool* p) {
currState = prevState;
});
cout << "currState: " << currState << endl;
}
int main() {
bool state = false;
foo(state, true);
cout << "state: " << state << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBmb28oYm9vbCAmIGN1cnJTdGF0ZSwgYm9vbCBuZXdTdGF0ZSkKewoJYm9vbCBwcmV2U3RhdGUgPSBjdXJyU3RhdGU7CgljdXJyU3RhdGUgICAgICA9IG5ld1N0YXRlOwoJc3RkOjp1bmlxdWVfcHRyPGJvb2wsIHN0ZDo6ZnVuY3Rpb248dm9pZChib29sKik+PiB0eEVuZGVyKCZwcmV2U3RhdGUsIFsmcHJldlN0YXRlLCAmY3VyclN0YXRlXShib29sKiBwKSB7CgkgICAgY3VyclN0YXRlID0gcHJldlN0YXRlOwoJfSk7Cgljb3V0IDw8ICJjdXJyU3RhdGU6ICIgPDwgY3VyclN0YXRlIDw8IGVuZGw7Cn0KCgppbnQgbWFpbigpIHsKCWJvb2wgc3RhdGUgPSBmYWxzZTsKCWZvbyhzdGF0ZSwgdHJ1ZSk7Cgljb3V0IDw8ICJzdGF0ZTogIiA8PCBzdGF0ZSA8PCBlbmRsOwoJcmV0dXJuIDA7Cn0=