fork(2) download
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. void foo(bool & currState, bool newState)
  6. {
  7. bool prevState = currState;
  8. currState = newState;
  9. std::unique_ptr<bool, std::function<void(bool*)>> txEnder(&prevState, [&prevState, &currState](bool* p) {
  10. currState = prevState;
  11. });
  12. cout << "currState: " << currState << endl;
  13. }
  14.  
  15.  
  16. int main() {
  17. bool state = false;
  18. foo(state, true);
  19. cout << "state: " << state << endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
currState: 1
state: 0