#include <iostream>
#include <memory>
#include <vector>
#include <exception>
#include <functional>
using namespace std;
int main()
{
try {
vector<int> v{};
v.push_back(42);
unique_ptr<decltype(v), function<void(decltype(v)*)>>
p{&v, [] (decltype(v)* v) { if (uncaught_exception()) { v->pop_back(); }}};
throw exception(); // rollback
p.release(); // explicit commit
} catch (...) {
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8ZXhjZXB0aW9uPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKCXRyeSB7CiAgICAgICAgdmVjdG9yPGludD4gdnt9OwogICAgICAgIHYucHVzaF9iYWNrKDQyKTsKICAgICAgICB1bmlxdWVfcHRyPGRlY2x0eXBlKHYpLCBmdW5jdGlvbjx2b2lkKGRlY2x0eXBlKHYpKik+PgogICAgICAgICAgICBweyZ2LCBbXSAoZGVjbHR5cGUodikqIHYpIHsgaWYgKHVuY2F1Z2h0X2V4Y2VwdGlvbigpKSB7IHYtPnBvcF9iYWNrKCk7IH19fTsKICAgICAgICB0aHJvdyBleGNlcHRpb24oKTsgLy8gcm9sbGJhY2sgCiAgICAgICAgcC5yZWxlYXNlKCk7IC8vIGV4cGxpY2l0IGNvbW1pdAoJfSBjYXRjaCAoLi4uKSB7Cgl9CgkKICAgIHJldHVybiAwOwp9Cgo=