18 #ifndef A_UTIL_SCOPEGUARD_HEADER_INCLUDED
19 #define A_UTIL_SCOPEGUARD_HEADER_INCLUDED
22 #include <type_traits>
25 #if ((defined _MSC_VER) && (_MSVC_LANG >= 201703L)) || \
26 ((!defined _MSC_VER) && (__cplusplus >= 201703L))
31 #define A_UTIL_HAVE_UNCAUGHT_EXCEPTIONS
32 #define A_UTIL_HAVE_GUARANTEED_COPY_ELISION
63 #ifdef A_UTIL_HAVE_GUARANTEED_COPY_ELISION
107 bool _enabled =
true;
108 typename std::decay<F>::type _f;
133 #ifdef A_UTIL_HAVE_UNCAUGHT_EXCEPTIONS
138 template <
class F,
bool ExecuteOnFailure>
141 explicit ScopeGuard(F&& f) : ::
a_util::ScopeGuard<F>(std::forward<F>(f))
147 const auto uncaught_exceptions_on_exit = std::uncaught_exceptions();
148 const auto success = _uncaught_exceptions_on_entry == uncaught_exceptions_on_exit;
149 if (ExecuteOnFailure == success) {
155 const int _uncaught_exceptions_on_entry = std::uncaught_exceptions();
169 inline auto scopeSuccess(F&& f)
171 return detail::ScopeGuard<F,
false>(std::forward<F>(f));
180 inline auto scopeFailure(F&& f)
182 return detail::ScopeGuard<F,
true>(std::forward<F>(f));
Scope guard executing a callable object of type F on scope exit.
~ScopeGuard()
Destroy the scope guard object and execute the callable if execution is enabled.
void dismiss() noexcept
Dismiss the execution of the callable on scope exit.
void rehire() noexcept
Rehire the execution of the callable on scope exit.
auto scopeExit(F &&f)
Creates a scope guard executing callable f on scope exit.
Serves as the root component, with common functionality documented in core functionality.