18#ifndef A_UTIL_SCOPEGUARD_HEADER_INCLUDED
19#define A_UTIL_SCOPEGUARD_HEADER_INCLUDED
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
58 ScopeGuard() =
delete;
59 ScopeGuard(
const ScopeGuard&) =
delete;
60 ScopeGuard& operator=(
const ScopeGuard&) =
delete;
61 ScopeGuard& operator=(ScopeGuard&& other) =
delete;
63#ifdef A_UTIL_HAVE_GUARANTEED_COPY_ELISION
64 ScopeGuard(ScopeGuard&&) =
delete;
66 ScopeGuard(ScopeGuard&& other) : _enabled(other._enabled), _f(other._f)
107 bool _enabled =
true;
108 typename std::decay<F>::type _f;
133#ifdef A_UTIL_HAVE_UNCAUGHT_EXCEPTIONS
138template <
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();
169inline auto scopeSuccess(F&& f)
171 return detail::ScopeGuard<F,
false>(std::forward<F>(f));
180inline auto scopeFailure(F&& f)
182 return detail::ScopeGuard<F,
true>(std::forward<F>(f));
Definition scopeguard.h:56
ScopeGuard(F &&f)
Definition scopeguard.h:76
void rehire() noexcept
Definition scopeguard.h:101
~ScopeGuard()
Definition scopeguard.h:83
void dismiss() noexcept
Definition scopeguard.h:93
auto scopeExit(F &&f)
Definition scopeguard.h:128
Serves as the root component, with common functionality documented in core functionality.
Definition base.h:24