#ifndef _ENSURE_H_ #define _ENSURE_H_ #ifndef NDEBUG _OPEN_NAMESPACE_(DBC) struct ensure { ensure(){} static void stop_execution(){ ::DebugBreak(); } }; _CLOSE_NAMESPACE_(DBC) template< typename bool_expr > inline void operator, ( DBC::ensure const & _, bool_expr const & x ) { if( !x ) DBC::ensure::stop_execution(); } # define _ensure_ DBC::ensure(), #else //release mode: # define COMMENT_MACRO ADDSLASH_MACRO(/) # define ADDSLASH_MACRO(s) /##s # define _ensure_ COMMENT_MACRO #endif // // // Usage example: // #include <stdio.h> // char first_char( char const * s ) // { // _ensure_ s && ::strlen(s); // return s[0]; // } // // Cheers! // #endif
code/root/inc/ensure.h.txt · Last modified: 2006/10/09 22:39 by chuck_starchaser


