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 5b9e69e7fe
commit b2b0f85b7d

View file

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