aboutsummaryrefslogtreecommitdiff
path: root/primedev/util/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'primedev/util/utils.h')
-rw-r--r--primedev/util/utils.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/primedev/util/utils.h b/primedev/util/utils.h
index 1a419607..c8cbc7e8 100644
--- a/primedev/util/utils.h
+++ b/primedev/util/utils.h
@@ -2,22 +2,24 @@
void RemoveAsciiControlSequences(char* str, bool allow_color_codes);
-class ScopeGuard
+template <typename T> class ScopeGuard
{
public:
auto operator=(ScopeGuard&) = delete;
ScopeGuard(ScopeGuard&) = delete;
- ScopeGuard(std::function<void()> callback) : m_callback(callback) {}
+ ScopeGuard(T callback) : m_callback(callback) {}
~ScopeGuard()
{
- m_callback();
+ if (!m_dismissed)
+ m_callback();
}
void Dismiss()
{
- m_callback = [] {};
+ m_dismissed = true;
}
private:
- std::function<void()> m_callback;
+ bool m_dismissed = false;
+ T m_callback;
};