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 
00012 #if not HAVE_STATIC_ASSERT
00013 // Taken from BOOST
00014 //
00015 // Helper macro CPPMAGIC_JOIN:
00016 // The following piece of macro magic joins the two
00017 // arguments together, even when one of the arguments is
00018 // itself a macro (see 16.3.1 in C++ standard).  The key
00019 // is that macro expansion of macro arguments does not
00020 // occur in CPPMAGIC_DO_JOIN2 but does in CPPMAGIC_DO_JOIN.
00021 //
00022 #define CPPMAGIC_JOIN( X, Y ) CPPMAGIC_DO_JOIN( X, Y )
00023 #define CPPMAGIC_DO_JOIN( X, Y ) CPPMAGIC_DO_JOIN2(X,Y)
00024 #define CPPMAGIC_DO_JOIN2( X, Y ) X##Y
00025 
00026 template <bool x> struct static_assert_failure;
00027 
00028 template <> struct static_assert_failure<true> { };
00029 
00030 template<int x> struct static_assert_test{};
00031 #endif
00032 
00071 #if HAVE_STATIC_ASSERT
00072 #define dune_static_assert(COND,MSG) \
00073     static_assert(COND,MSG)
00074 #else
00075 #define dune_static_assert(COND,MSG) \
00076     typedef static_assert_test<                         \
00077       sizeof(static_assert_failure< (bool)( COND )>)\
00078       > CPPMAGIC_JOIN(dune_static_assert_typedef_, __LINE__)
00079 #endif
00080 
00081 namespace Dune {
00083 
00099 
00115 
00122   template<typename T>
00123   struct AlwaysFalse {
00125     static const bool value = false;
00126   };
00127 
00129 
00135   template<typename T>
00136   struct AlwaysTrue {
00138     static const bool value = true;
00139   };
00140 } // namespace Dune
00141 
00142 /* @} */
00143 
00144 #endif

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].