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 #ifndef STRINGIZE_H
18 #include "stringize.h"
19 #endif
20 
21 #if defined (Cxx11)
22 
23 #define STATIC_ASSERT(const_expression) static_assert(const_expression,#const_expression)
24 #define STATIC_ASSERT_ANNOTATED(const_expression,failReason) static_assert(const_expression,failReason)
25 
26 #else
27 
29  template <bool> struct is;
30  template <> struct is<true> { enum { value = 1 }; };
31  template<int x> struct static_assert_test{};
32 }
33 
34 #define CA_UNIQUETYPE(typename) concatenate_pscans(typename,__LINE__)
35 #define COMPILE_ASSERTED_TYPE(const_expression) ::arb_compile_assertion::static_assert_test<sizeof(::arb_compile_assertion::is< (bool)( const_expression ) >)>
36 #define ASSERT_VIA_IS(type_definition,type_id) typedef type_definition type_id; struct concatenate(using_,type_id) { type_id instance; }
37 #define STATIC_ASSERT(const_expression) ASSERT_VIA_IS(COMPILE_ASSERTED_TYPE(const_expression), CA_UNIQUETYPE(_arb_compile_assertion_typedef_))
38 #define STATIC_ASSERT_ANNOTATED(const_expression,annotation) STATIC_ASSERT(const_expression)
39 
40 #endif
41 
42 #else
43 #error static_assert.h included twice
44 #endif // STATIC_ASSERT_H
#define true
Definition: ureadseq.h:14