Dune Core Modules (2.3.1)

static_assert.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_STATIC_ASSERT_HH
4 #define DUNE_STATIC_ASSERT_HH
5 
16 #if not HAVE_STATIC_ASSERT
17 // Taken from BOOST
18 //
19 // Helper macro CPPMAGIC_JOIN:
20 // The following piece of macro magic joins the two
21 // arguments together, even when one of the arguments is
22 // itself a macro (see 16.3.1 in C++ standard). The key
23 // is that macro expansion of macro arguments does not
24 // occur in CPPMAGIC_DO_JOIN2 but does in CPPMAGIC_DO_JOIN.
25 //
26 #define CPPMAGIC_JOIN( X, Y ) CPPMAGIC_DO_JOIN( X, Y )
27 #define CPPMAGIC_DO_JOIN( X, Y ) CPPMAGIC_DO_JOIN2(X,Y)
28 #define CPPMAGIC_DO_JOIN2( X, Y ) X ## Y
29 
30 template <bool x> struct static_assert_failure;
31 
32 template <> struct static_assert_failure<true> { };
33 
34 template<int x> struct static_assert_test {};
35 #endif
36 
75 #if HAVE_STATIC_ASSERT
76 #define dune_static_assert(COND,MSG) \
77  static_assert(COND,MSG)
78 #else
79 #define dune_static_assert(COND,MSG) \
80  typedef static_assert_test< \
81  sizeof(static_assert_failure< (bool)( COND )>)\
82  > CPPMAGIC_JOIN (dune_static_assert_typedef_, __LINE__)
83 #endif
84 
85 namespace Dune {
103 
119 
126  template<typename T>
127  struct AlwaysFalse {
129  static const bool value = false;
130  };
131 
139  template<typename T>
140  struct AlwaysTrue {
142  static const bool value = true;
143  };
144 } // namespace Dune
145 
146 /* @} */
147 
148 #endif
static const bool value
always a false value
Definition: static_assert.hh:129
static const bool value
always a true value
Definition: static_assert.hh:142
Dune namespace.
Definition: alignment.hh:14
template which always yields a false value
Definition: static_assert.hh:127
template which always yields a true value
Definition: static_assert.hh:140
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 15, 22:30, 2024)