Misc: Backports from PCSX2 UI

This commit is contained in:
Connor McLaughlin
2022-10-23 14:09:54 +10:00
parent 8438506206
commit 72dfbaf6cc
37 changed files with 1037 additions and 271 deletions

View File

@ -12,16 +12,14 @@ class ScopedGuard final
public:
ALWAYS_INLINE ScopedGuard(T&& func) : m_func(std::forward<T>(func)) {}
ALWAYS_INLINE ScopedGuard(ScopedGuard&& other) : m_func(std::move(other.m_func)) { other.m_func = nullptr; }
ALWAYS_INLINE ~ScopedGuard() { Invoke(); }
ALWAYS_INLINE ~ScopedGuard() { Run(); }
ScopedGuard(const ScopedGuard&) = delete;
void operator=(const ScopedGuard&) = delete;
/// Prevents the function from being invoked when we go out of scope.
ALWAYS_INLINE void Cancel() { m_func.reset(); }
/// Explicitly fires the function.
ALWAYS_INLINE void Invoke()
/// Runs the destructor function now instead of when we go out of scope.
ALWAYS_INLINE void Run()
{
if (!m_func.has_value())
return;
@ -30,6 +28,9 @@ public:
m_func.reset();
}
/// Prevents the function from being invoked when we go out of scope.
ALWAYS_INLINE void Cancel() { m_func.reset(); }
private:
std::optional<T> m_func;
};