1
0
Fork 0
mirror of https://gitlab.com/niansa/SomeBot.git synced 2025-03-06 20:48:26 +01:00
SomeBot/LuaBridge3/Source/LuaBridge/detail/ScopeGuard.h
2023-03-02 14:10:47 +01:00

47 lines
825 B
C++

// https://github.com/vinniefalco/LuaBridge
// Copyright 2021, Lucio Asnaghi
// Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
// SPDX-License-Identifier: MIT
#pragma once
#include "Config.h"
#include "Stack.h"
namespace luabridge::detail {
//=================================================================================================
/**
* @brief Scope guard.
*/
template <class F>
class ScopeGuard
{
public:
template <class V>
ScopeGuard(V&& v)
: m_func(std::forward<V>(v))
, m_shouldRun(true)
{
}
~ScopeGuard()
{
if (m_shouldRun)
m_func();
}
void reset()
{
m_shouldRun = false;
}
private:
F m_func;
bool m_shouldRun;
};
template <class F>
ScopeGuard(F&&) -> ScopeGuard<F>;
} // namespace luabridge::detail