aboutsummaryrefslogtreecommitdiff
path: root/primedev
diff options
context:
space:
mode:
authorJack <66967891+ASpoonPlaysGames@users.noreply.github.com>2024-01-30 22:06:40 +0000
committerGitHub <noreply@github.com>2024-01-30 23:06:40 +0100
commit6ad955ae0aab8b79910cb4a12777419a78a42a90 (patch)
tree51fa865c4dc367a3813def27761e174c7e6f2cac /primedev
parent350e6b14636519fb4e5f7297783fbc0fdbad0197 (diff)
downloadNorthstarLauncher-6ad955ae0aab8b79910cb4a12777419a78a42a90.tar.gz
NorthstarLauncher-6ad955ae0aab8b79910cb4a12777419a78a42a90.zip
ScopeGuard improvements (#651)
`std::function` introduced a layer of indirection that can be removed through templating the class.
Diffstat (limited to 'primedev')
-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;
};