static_assert.hh
00001 #ifndef DUNE_STATIC_ASSERT_HH
00002 #define DUNE_STATIC_ASSERT_HH
00003
00004 #include "deprecated.hh"
00005
00031 template <bool condition>
00032 struct IsTrue
00033 {
00034 static void no() DUNE_DEPRECATED {};
00035 };
00036
00037 template <>
00038 struct IsTrue<true>
00039 {
00040 static void yes() DUNE_DEPRECATED {};
00041 };
00042
00043 #if not HAVE_STATIC_ASSERT
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #define CPPMAGIC_JOIN( X, Y ) CPPMAGIC_DO_JOIN( X, Y )
00054 #define CPPMAGIC_DO_JOIN( X, Y ) CPPMAGIC_DO_JOIN2(X,Y)
00055 #define CPPMAGIC_DO_JOIN2( X, Y ) X##Y
00056
00057 template <bool x> struct static_assert_failure;
00058
00059 template <> struct static_assert_failure<true> { };
00060
00061 template<int x> struct static_assert_test{};
00062 #endif
00063
00095 #if HAVE_STATIC_ASSERT
00096 #define dune_static_assert(COND,MSG) \
00097 static_assert(COND,MSG)
00098 #else
00099 #define dune_static_assert(COND,MSG) \
00100 typedef static_assert_test< \
00101 sizeof(static_assert_failure< (bool)( COND )>)\
00102 > CPPMAGIC_JOIN(dune_static_assert_typedef_, __LINE__)
00103 #endif
00104
00105
00106
00107 #endif