X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2Fsenfassert.hh;h=ef270060a1d4e67331e0e5b9dc342b408a142361;hb=72cc548dfc3fa72d14d4d8c1a178f162165e933a;hp=dd1ac50f9b562b4ad1dc6aa1d26f6a1e0ab99618;hpb=c40594da2a8fc3d681ed3c2e74ff632f1df2b31c;p=senf.git diff --git a/senf/Utils/senfassert.hh b/senf/Utils/senfassert.hh index dd1ac50..ef27006 100644 --- a/senf/Utils/senfassert.hh +++ b/senf/Utils/senfassert.hh @@ -49,6 +49,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"