2026-06-05 13:44:39 +09:00

34 lines
464 B
C++

#pragma once
template<typename T>
class ScopeExit
{
T mFunc;
public:
ScopeExit(T aFunc)
: mFunc(aFunc)
{
}
~ScopeExit()
{
mFunc();
}
};
template<typename F>
ScopeExit<F> onScopeExit(F f)
{
return ScopeExit<F>(f);
};
#define __strcat2(s1, s2) s1 ## s2
#define __strcat1(s1, s2) __strcat2(s1, s2)
#define ON_SCOPE_EXIT(...) \
auto __strcat1(onExit, __LINE__) = onScopeExit( [&](void) {__VA_ARGS__} )