commit 5eb105103b42abbd72e0553b3a0517216c802ff4 parent 22ff4e35809223c5e311c8d1fbc16feebb979420 Author: Michael Savage <mikejsavage@gmail.com> Date: Tue Oct 18 20:13:47 +0300 checked_cast Diffstat:
intrinsics.h | | | 7 | +++++++ |
diff --git a/intrinsics.h b/intrinsics.h @@ -125,6 +125,13 @@ inline void mike_assert( const bool predicate, const char * message ) { #define STATIC_ASSERT( p ) static_assert( p ) #endif +template< typename To, typename From > +To checked_cast( const From & from ) { + To result = To( from ); + ASSERT( From( result ) == from ); + return result; +} + // TODO: this sucks inline u8 * file_get_contents( const char * path, size_t * out_len = NULL ) { FILE * file = fopen( path, "rb" );