forked from Bananymous/banan-os
BAN: Add basic ScopeGuard
This commit is contained in:
22
BAN/include/BAN/ScopeGuard.h
Normal file
22
BAN/include/BAN/ScopeGuard.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <BAN/Function.h>
|
||||||
|
|
||||||
|
namespace BAN
|
||||||
|
{
|
||||||
|
|
||||||
|
class ScopeGuard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ScopeGuard(const BAN::Function<void()>& func)
|
||||||
|
: m_func(func)
|
||||||
|
{ }
|
||||||
|
~ScopeGuard()
|
||||||
|
{
|
||||||
|
m_func();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
BAN::Function<void()> m_func;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user