From: Carl Hetherington Date: Sat, 13 Jan 2024 12:34:46 +0000 (+0100) Subject: Add cancel() to ScopeGuard. X-Git-Tag: v1.8.94 X-Git-Url: https://git.carlh.net/gitweb/?p=libdcp.git;a=commitdiff_plain;h=c9b3af92c43cb649137c88eaa48802197a4bbb06 Add cancel() to ScopeGuard. --- 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; };