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 
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 // Taken from BOOST
00047 //
00048 // Helper macro CPPMAGIC_JOIN:
00049 // The following piece of macro magic joins the two
00050 // arguments together, even when one of the arguments is
00051 // itself a macro (see 16.3.1 in C++ standard).  The key
00052 // is that macro expansion of macro arguments does not
00053 // occur in CPPMAGIC_DO_JOIN2 but does in CPPMAGIC_DO_JOIN.
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 } // namespace Dune
00161 
00162 /* @} */
00163 
00164 #endif
Generated on Mon Apr 26 10:45:21 2010 for dune-common by  doxygen 1.6.3