dune-common  2.2.0
static_assert.hh
Go to the documentation of this file.
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002 // vi: set et ts=8 sw=2 sts=2:
00003 #ifndef DUNE_STATIC_ASSERT_HH
00004 #define DUNE_STATIC_ASSERT_HH
00005 
00016 #if not HAVE_STATIC_ASSERT
00017 // Taken from BOOST
00018 //
00019 // Helper macro CPPMAGIC_JOIN:
00020 // The following piece of macro magic joins the two
00021 // arguments together, even when one of the arguments is
00022 // itself a macro (see 16.3.1 in C++ standard).  The key
00023 // is that macro expansion of macro arguments does not
00024 // occur in CPPMAGIC_DO_JOIN2 but does in CPPMAGIC_DO_JOIN.
00025 //
00026 #define CPPMAGIC_JOIN( X, Y ) CPPMAGIC_DO_JOIN( X, Y )
00027 #define CPPMAGIC_DO_JOIN( X, Y ) CPPMAGIC_DO_JOIN2(X,Y)
00028 #define CPPMAGIC_DO_JOIN2( X, Y ) X##Y
00029 
00030 template <bool x> struct static_assert_failure;
00031 
00032 template <> struct static_assert_failure<true> { };
00033 
00034 template<int x> struct static_assert_test{};
00035 #endif
00036 
00075 #if HAVE_STATIC_ASSERT
00076 #define dune_static_assert(COND,MSG) \
00077     static_assert(COND,MSG)
00078 #else
00079 #define dune_static_assert(COND,MSG) \
00080     typedef static_assert_test<                         \
00081       sizeof(static_assert_failure< (bool)( COND )>)\
00082       > CPPMAGIC_JOIN(dune_static_assert_typedef_, __LINE__)
00083 #endif
00084 
00085 namespace Dune {
00087 
00103 
00119 
00126   template<typename T>
00127   struct AlwaysFalse {
00129     static const bool value = false;
00130   };
00131 
00133 
00139   template<typename T>
00140   struct AlwaysTrue {
00142     static const bool value = true;
00143   };
00144 } // namespace Dune
00145 
00146 /* @} */
00147 
00148 #endif