fork(6) download
  1. #include <iostream>
  2. #include <memory>
  3. #include <vector>
  4. #include <exception>
  5. #include <functional>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. try {
  12. vector<int> v{};
  13. v.push_back(42);
  14. unique_ptr<decltype(v), function<void(decltype(v)*)>>
  15. p{&v, [] (decltype(v)* v) { if (uncaught_exception()) { v->pop_back(); }}};
  16. throw exception(); // rollback
  17. p.release(); // explicit commit
  18. } catch (...) {
  19. }
  20.  
  21. return 0;
  22. }
  23.  
  24.  
Success #stdin #stdout 0s 3408KB
stdin
Standard input is empty
stdout
Standard output is empty