diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-01-13 13:34:46 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-01-13 13:34:46 +0100 |
| commit | c9b3af92c43cb649137c88eaa48802197a4bbb06 (patch) | |
| tree | 7f734abbea9f4ebec6aa5cb790d02af4620ca818 /src/scope_guard.h | |
| parent | 87ecaefdaad13fa31ff54270d4d5e6c483d2102b (diff) | |
Add cancel() to ScopeGuard.v1.8.94
Diffstat (limited to 'src/scope_guard.h')
| -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; }; |
