00001
00002
00003
00004
00005
00006 #ifndef ASSERT_H
00007 #define ASSERT_H
00008
00009 #include<stdexcept>
00010
00011 #ifdef DEBUG
00012 #define ASSERT(X) if (!(X)) { runtime_error("Assertion failed: " #X); }
00013 #else
00014 #define ASSERT(X)
00015 #endif
00016
00017
00018 template <bool> struct STATIC_ASSERTION_FAILURE;
00019
00023 template <> struct STATIC_ASSERTION_FAILURE<true>{};
00024
00027 template<int> struct static_assert_test{};
00028
00029 #define ASSERT_JOIN( X, Y ) DO_ASSERT_JOIN( X, Y )
00030 #define DO_ASSERT_JOIN( X, Y ) X##Y
00031 #define STATIC_ASSERT( B ) \
00032 enum { ASSERT_JOIN(static_assert_test, __LINE__) \
00033 = sizeof(STATIC_ASSERTION_FAILURE< ( B ) >) }
00034
00035 #endif