X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2Fsenfassert.hh;h=7b86d5e151d5fd42b25d1780da8f3603b8de0e4f;hb=refs%2Fheads%2Fmaster;hp=dd1ac50f9b562b4ad1dc6aa1d26f6a1e0ab99618;hpb=ab7ff164ab5ae711ec09ce2b24228510f1ffdcff;p=senf.git diff --git a/senf/Utils/senfassert.hh b/senf/Utils/senfassert.hh index dd1ac50..7b86d5e 100644 --- a/senf/Utils/senfassert.hh +++ b/senf/Utils/senfassert.hh @@ -32,6 +32,7 @@ #define HH_SENF_Utils_senfassert_ 1 // Custom includes +#include "IgnoreValue.hh" //#include "senfassert.mpp" //-///////////////////////////////////////////////////////////////////////////////////////////////// @@ -39,7 +40,7 @@ #ifndef SENF_DEBUG # define SENF_ASSERT(x, comment) -# define SENF_ASSERT_EXPRESSION(expression, comment) expression +# define SENF_ASSERT_EXPRESSION(expression, comment) senf::IGNORE( expression ) #else @@ -49,6 +50,41 @@ #endif + +/* Lifted direct from: + Modern C++ Design: Generic Programming and Design Patterns Applied Section 2.1 + by Andrei Alexandrescu +*/ +namespace senf { +namespace detail { + template class compile_time_check + { + public: + compile_time_check(...) {} + }; + + template<> class compile_time_check + { + }; +}} + + /* + SENF_STATIC_ASSERT is only in operation when SENF_DEBUG is defined. It will test its first + argument at compile time and on failure report the error message of the second argument, + which must be a valid c++ classname. i.e. no spaces, punctuation or reserved keywords. + */ +#ifdef SENF_DEBUG +# define SENF_STATIC_ASSERT(expr, msg) \ + do { \ + struct STATIC_ASSERT_FAILED_##msg {}; \ + typedef senf::detail::compile_time_check< (expr) != 0 > tmplimpl; \ + tmplimpl aTemp = tmplimpl(STATIC_ASSERT_FAILED_##msg()); \ + (void)sizeof(aTemp); \ + } while (0) +#else +# define SENF_STATIC_ASSERT(expr, msg) +#endif + //-///////////////////////////////////////////////////////////////////////////////////////////////// //#include "senfassert.cci" //#include "senfassert.ct"