summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-01-13 13:34:46 +0100
committerCarl Hetherington <cth@carlh.net>2024-01-13 13:34:46 +0100
commitc9b3af92c43cb649137c88eaa48802197a4bbb06 (patch)
tree7f734abbea9f4ebec6aa5cb790d02af4620ca818
parent87ecaefdaad13fa31ff54270d4d5e6c483d2102b (diff)
Add cancel() to ScopeGuard.v1.8.94
-rw-r--r--src/scope_guard.h10
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;
};