Plasma Engine  2.0
Loading...
Searching...
No Matches
ScopeExit.h
1
2#pragma once
3
4#include <Foundation/Basics.h>
5
7
9#define PL_SCOPE_EXIT(code) auto PL_PP_CONCAT(scopeExit_, PL_SOURCE_LINE) = plMakeScopeExit([&]() { code; })
10
12template <typename T>
14{
15 PL_ALWAYS_INLINE plScopeExit(T&& func)
16 : m_func(std::forward<T>(func))
17 {
18 }
19
20 PL_ALWAYS_INLINE ~plScopeExit() { m_func(); }
21
22 T m_func;
23};
24
26template <typename T>
27PL_ALWAYS_INLINE plScopeExit<T> plMakeScopeExit(T&& func)
28{
29 return plScopeExit<T>(std::forward<T>(func));
30}
Definition ScopeExit.h:14