• Giuseppe Ottaviano's avatar
    Allow creation of dismissed ScopeGuards · cc049da2
    Giuseppe Ottaviano authored
    Summary:
    This diff enables a symmetrical pattern to `makeGuard()`/`dismiss()`: `makeDismissedGuard()` will create a guard that will not execute unless `rehired()`'d.
    
    This is for use cases where the guard's scope is wider than where the condition on whether it should execute is evaluated. For example
    ```
    State state;
    auto guard = makeDismissedGuard([&] { cleanup(state); });
    if (modifyStateInAWayThatRequiresCleanup(state)) {
      guard.rehire();
    }
    // Use state.
    ```
    
    Reviewed By: yfeldblum
    
    Differential Revision: D27931274
    
    fbshipit-source-id: fbf7048dc991b73553cd6429f5e73345e4104d49
    cc049da2
ScopeGuardTest.cpp 8.46 KB