11 #ifndef __UT_SCOPEEXIT_H_INCLUDED__
12 #define __UT_SCOPEEXIT_H_INCLUDED__
32 : myAction(action) { }
34 : myAction(action) { }
36 : myAction(std::move(action)) { }
38 : myAction(std::move(other.myAction)) { }
49 namespace UT_ScopeGuard
72 #define UT_SCOPE_EXIT_CONCAT_IMPL(x, y) x ## y
73 #define UT_SCOPE_EXIT_CONCAT(x, y) UT_SCOPE_EXIT_CONCAT_IMPL(x, y)
74 #define UT_SCOPE_EXIT_VAR(name) UT_SCOPE_EXIT_CONCAT(name, __COUNTER__)
79 #define UT_SCOPE_EXIT_RUN_IMPL(func_name, scope_name, ...) \
80 auto func_name = [&]() { __VA_ARGS__; }; \
81 UT_ScopeExit<decltype(func_name)> scope_name(func_name) \
95 #define UT_AT_SCOPE_EXIT(...) \
96 UT_SCOPE_EXIT_RUN_IMPL(UT_SCOPE_EXIT_VAR(scope_exit_lambda), \
97 UT_SCOPE_EXIT_VAR(scope_exit_scope), \
112 #define UT_SCOPE_EXIT \
113 auto UT_SCOPE_EXIT_VAR(scope_exit_scope) \
114 = UT_ScopeGuard::OnExit() + [&]() noexcept \
117 #endif // __UT_SCOPEEXIT_H_INCLUDED__
UT_ScopeExit which runs the given lambda on destruction.
UT_ScopeExit< F > operator+(OnExit, F &&fn)
UT_ScopeExit(UT_ScopeExit &&other)
UT_ScopeExit(const F &&action)