common: scope_exit: Implement mechanism for canceling a scope exit.

This commit is contained in:
bunnei 2020-03-31 15:16:07 -04:00
parent 4caff51710
commit 4df6ef04ac
1 changed files with 8 additions and 1 deletions

View File

@ -12,10 +12,17 @@ template <typename Func>
struct ScopeExitHelper {
explicit ScopeExitHelper(Func&& func) : func(std::move(func)) {}
~ScopeExitHelper() {
func();
if (active) {
func();
}
}
void Cancel() {
active = false;
}
Func func;
bool active{true};
};
template <typename Func>