static_assert.hh
Go to the documentation of this file.00001
00002
00003 #ifndef DUNE_STATIC_ASSERT_HH
00004 #define DUNE_STATIC_ASSERT_HH
00005
00006 #include "deprecated.hh"
00007
00033 template <bool condition>
00034 struct IsTrue
00035 {
00036 static void no() DUNE_DEPRECATED {};
00037 };
00038
00039 template <>
00040 struct IsTrue<true>
00041 {
00042 static void yes() DUNE_DEPRECATED {};
00043 };
00044
00045 #if not HAVE_STATIC_ASSERT
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #define CPPMAGIC_JOIN( X, Y ) CPPMAGIC_DO_JOIN( X, Y )
00056 #define CPPMAGIC_DO_JOIN( X, Y ) CPPMAGIC_DO_JOIN2(X,Y)
00057 #define CPPMAGIC_DO_JOIN2( X, Y ) X##Y
00058
00059 template <bool x> struct static_assert_failure;
00060
00061 template <> struct static_assert_failure<true> { };
00062
00063 template<int x> struct static_assert_test{};
00064 #endif
00065
00104 #if HAVE_STATIC_ASSERT
00105 #define dune_static_assert(COND,MSG) \
00106 static_assert(COND,MSG)
00107 #else
00108 #define dune_static_assert(COND,MSG) \
00109 typedef static_assert_test< \
00110 sizeof(static_assert_failure< (bool)( COND )>)\
00111 > CPPMAGIC_JOIN(dune_static_assert_typedef_, __LINE__)
00112 #endif
00113
00114 namespace Dune {
00116
00132
00148
00155 template<typename T>
00156 struct AlwaysFalse {
00158 static const bool value = false;
00159 };
00160 }
00161
00162
00163
00164 #endif