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 // Taken from BOOST
00045 //
00046 // Helper macro CPPMAGIC_JOIN:
00047 // The following piece of macro magic joins the two
00048 // arguments together, even when one of the arguments is
00049 // itself a macro (see 16.3.1 in C++ standard).  The key
00050 // is that macro expansion of macro arguments does not
00051 // occur in CPPMAGIC_DO_JOIN2 but does in CPPMAGIC_DO_JOIN.
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

Generated on Thu Apr 2 10:39:54 2009 for dune-common by  doxygen 1.5.6