From c9b3af92c43cb649137c88eaa48802197a4bbb06 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 13 Jan 2024 13:34:46 +0100 Subject: Add cancel() to ScopeGuard. --- src/scope_guard.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') 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 _function; + bool _cancelled = false; }; -- cgit v1.2.3