9#define MR_FINALLY DETAIL_MR_FINALLY( ScopeGuard )
11#ifdef __cpp_exceptions
14#define MR_FINALLY_ON_SUCCESS DETAIL_MR_FINALLY( ExceptionScopeGuard<true>::Type )
17#define MR_FINALLY_ON_THROW DETAIL_MR_FINALLY( ExceptionScopeGuard<false>::Type )
22#define MR_FINALLY_ON_SUCCESS MR_FINALLY
24#define MR_FINALLY_ON_THROW (void)[&]()
28#define DETAIL_MR_FINALLY( type_ ) \
29 auto DETAIL_MR_FINALLY_CAT( _mrScopeGuard, __COUNTER__ ) = ::MR::detail::MakeScopeGuard<::MR::detail::type_>{} ->* [&]() -> void
31#define DETAIL_MR_FINALLY_CAT( x, y ) DETAIL_MR_FINALLY_CAT_( x, y )
32#define DETAIL_MR_FINALLY_CAT_( x, y ) x##y
49#ifdef __cpp_exceptions
50template <
bool Success>
51struct ExceptionScopeGuard
57 int ex = std::uncaught_exceptions();
60 Type( F&& func ) : func( std::move( func ) ) {}
61 Type(
const Type& ) =
delete;
62 Type& operator=(
const Type& ) =
delete;
63 ~Type() noexcept( !Success )
65 if ( ( ex == std::uncaught_exceptions() ) == Success )
72template <
template <
typename>
typename T>
78 return T<F>( std::move( func ) );
Definition MRFinally.h:39
~ScopeGuard()
Definition MRFinally.h:46
ScopeGuard(F &&func)
Definition MRFinally.h:43
ScopeGuard & operator=(const ScopeGuard &)=delete
ScopeGuard(const ScopeGuard &)=delete
Definition MRFinally.h:35
Definition MRFinally.h:74
T< F > operator->*(F &&func)
Definition MRFinally.h:76