static_assert.hh

00001 #ifndef DUNE_STATIC_ASSERT_HH
00002 #define DUNE_STATIC_ASSERT_HH
00003 
00021 template <bool condition>
00022 struct IsTrue
00023 {
00024   static void no() {};
00025 };
00026 
00027 template <>
00028 struct IsTrue<true>
00029 {
00030   static void yes() {};
00031 };
00032 
00033 
00034 #include<iostream>
00035 
00036 // Taken from BOOST
00037 //
00038 // Helper macro CPPMAGIC_JOIN:
00039 // The following piece of macro magic joins the two
00040 // arguments together, even when one of the arguments is
00041 // itself a macro (see 16.3.1 in C++ standard).  The key
00042 // is that macro expansion of macro arguments does not
00043 // occur in CPPMAGIC_DO_JOIN2 but does in CPPMAGIC_DO_JOIN.
00044 //
00045 #define CPPMAGIC_JOIN( X, Y ) CPPMAGIC_DO_JOIN( X, Y )
00046 #define CPPMAGIC_DO_JOIN( X, Y ) CPPMAGIC_DO_JOIN2(X,Y)
00047 #define CPPMAGIC_DO_JOIN2( X, Y ) X##Y
00048 
00049 template <bool x> struct static_assert_failure;
00050 
00051 template <> struct static_assert_failure<true> { };
00052 
00053 template<int x> struct static_assert_test{};
00054 
00060 #define dune_static_assert(B,MSG) \
00061    typedef static_assert_test<\
00062       sizeof(static_assert_failure< (bool)( B )>)\
00063       > CPPMAGIC_JOIN(dune_static_assert_typedef_, __LINE__)
00064 
00065 #endif

Generated on 6 Nov 2008 with Doxygen (ver 1.5.6) [logfile].