summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/ScopeGuard.h16
1 files changed, 7 insertions, 9 deletions
diff --git a/Source/Core/Common/ScopeGuard.h b/Source/Core/Common/ScopeGuard.h
index d95ef8e4ae..c1cad06dd7 100644
--- a/Source/Core/Common/ScopeGuard.h
+++ b/Source/Core/Common/ScopeGuard.h
@@ -4,17 +4,15 @@
#pragma once
-#include <functional>
+#include <optional>
namespace Common
{
+template <typename Callable>
class ScopeGuard final
{
public:
- template <class Callable>
- ScopeGuard(Callable&& finalizer) : m_finalizer(std::forward<Callable>(finalizer))
- {
- }
+ ScopeGuard(Callable&& finalizer) : m_finalizer(std::forward<Callable>(finalizer)) {}
ScopeGuard(ScopeGuard&& other) : m_finalizer(std::move(other.m_finalizer))
{
@@ -22,13 +20,13 @@ public:
}
~ScopeGuard() { Exit(); }
- void Dismiss() { m_finalizer = nullptr; }
+ void Dismiss() { m_finalizer.reset(); }
void Exit()
{
if (m_finalizer)
{
- m_finalizer(); // must not throw
- m_finalizer = nullptr;
+ (*m_finalizer)(); // must not throw
+ m_finalizer.reset();
}
}
@@ -37,7 +35,7 @@ public:
void operator=(const ScopeGuard&) = delete;
private:
- std::function<void()> m_finalizer;
+ std::optional<Callable> m_finalizer;
};
} // Namespace Common