mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-23 13:55:50 +12:00
Fix typo
This commit is contained in:
parent
42cbcc1380
commit
5d9ded47da
35 changed files with 37343 additions and 21800 deletions
34
third_party/duckstation/duckstation_scoped_guard.h
vendored
Normal file
34
third_party/duckstation/duckstation_scoped_guard.h
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
/// ScopedGuard provides an object which runs a function (usually a lambda) when
|
||||
/// it goes out of scope. This can be useful for releasing resources or handles
|
||||
/// which do not normally have C++ types to automatically release.
|
||||
template<typename T>
|
||||
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(); }
|
||||
|
||||
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()
|
||||
{
|
||||
if (!m_func.has_value())
|
||||
return;
|
||||
|
||||
m_func.value()();
|
||||
m_func.reset();
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<T> m_func;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue