ARB
static_assert.h
Go to the documentation of this file.
1 // ============================================================= //
2 // //
3 // File : static_assert.h //
4 // Purpose : compile time assertion //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // ============================================================= //
10 
11 #ifndef STATIC_ASSERT_H
12 #define STATIC_ASSERT_H
13 
14 #ifndef CXXFORWARD_H
15 #include <cxxforward.h>
16 #endif
17 
18 #if defined (Cxx11)
19 
20 #define STATIC_ASSERT(const_expression) static_assert(const_expression,#const_expression)
21 #define STATIC_ASSERT_ANNOTATED(const_expression,failReason) static_assert(const_expression,failReason)
22 
23 #else
24 
26  template <bool> struct is;
27  template <> struct is<true> { enum { value = 1 }; };
28  template<int x> struct static_assert_test{};
29 }
30 
31 #define CA_JOIN(X,Y) X##Y
32 #define CA_JOINTYPE(X,Y) CA_JOIN(X, Y)
33 #define CA_UNIQUETYPE(typename) CA_JOINTYPE(typename,__LINE__)
34 
35 #define COMPILE_ASSERTED_TYPE(const_expression) ::arb_compile_assertion::static_assert_test<sizeof(::arb_compile_assertion::is< (bool)( const_expression ) >)>
36 #define STATIC_ASSERT(const_expression) typedef COMPILE_ASSERTED_TYPE(const_expression) CA_UNIQUETYPE(_arb_compile_assertion_typedef_)
37 #define STATIC_ASSERT_ANNOTATED(const_expression,annotation) STATIC_ASSERT(const_expression)
38 
39 #endif
40 
41 #else
42 #error static_assert.h included twice
43 #endif // STATIC_ASSERT_H
#define true
Definition: ureadseq.h:14