medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 31d6516a0e780033c4db5e86261b5aa9f21cd935
parent f7e6830239d20e09b0d6259a32c74b0ec0bd6af4
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat Nov 19 12:06:37 +0200

SCOPE_EXIT

Diffstat:
intrinsics.h | 13+++++++++++++
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git a/intrinsics.h b/intrinsics.h @@ -136,6 +136,19 @@ inline void mike_assert( const bool predicate, const char * message ) { #define STATIC_ASSERT( p ) static_assert( p ) #endif +template< typename F > +struct ScopeExit { + ScopeExit( F f_ ) : f( f_ ) { } + ~ScopeExit() { f(); } + F f; +}; + +template< typename F > +ScopeExit< F > MakeScopeExit( F f ) { + return ScopeExit< F >( f ); +}; +#define SCOPE_EXIT( code ) auto CONCAT( SCOPE_EXIT_, __COUNTER__ ) = MakeScopeExit( [=]() { code; } ) + template< typename To, typename From > To checked_cast( const From & from ) { To result = To( from );