mirror of
https://gitlab.com/niansa/SomeBot.git
synced 2025-03-06 20:48:26 +01:00
47 lines
825 B
C++
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
|