AK: Add ArmedScopeGuard, a scope guard that can be disarmed

This commit is contained in:
Andrew Kaster 2020-01-09 00:35:32 -07:00 committed by Andreas Kling
parent 4cee441279
commit 9681d41bf0
Notes: sideshowbarker 2024-07-19 10:05:28 +09:00

View file

@ -21,6 +21,28 @@ private:
Callback m_callback;
};
template<typename Callback>
class ArmedScopeGuard {
public:
ArmedScopeGuard(Callback callback)
: m_callback(move(callback))
{
}
~ArmedScopeGuard()
{
if (m_armed)
m_callback();
}
void disarm() { m_armed = false; }
private:
Callback m_callback;
bool m_armed { true };
};
}
using AK::ScopeGuard;
using AK::ArmedScopeGuard;