diff options
| -rw-r--r-- | src/scope_guard.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/scope_guard.h b/src/scope_guard.h index 37b963ad..d422528c 100644 --- a/src/scope_guard.h +++ b/src/scope_guard.h @@ -61,11 +61,19 @@ public: ~ScopeGuard() { - _function(); + if (!_cancelled) { + _function(); + } + } + + void cancel() + { + _cancelled = true; } private: std::function<void()> _function; + bool _cancelled = false; }; |
