Line | |
---|
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 | namespace arb_compile_assertion { |
---|
15 | template <bool> struct is; |
---|
16 | template <> struct is<true> { enum { value = 1 }; }; |
---|
17 | template<int x> struct static_assert_test{}; |
---|
18 | } |
---|
19 | |
---|
20 | #define CA_JOIN(X,Y) X##Y |
---|
21 | #define CA_JOINTYPE(X,Y) CA_JOIN(X, Y) |
---|
22 | #define CA_UNIQUETYPE(typename) CA_JOINTYPE(typename,__LINE__) |
---|
23 | |
---|
24 | #define COMPILE_ASSERTED_TYPE(const_expression) ::arb_compile_assertion::static_assert_test<sizeof(::arb_compile_assertion::is< (bool)( const_expression ) >)> |
---|
25 | #define COMPILE_ASSERT(const_expression) typedef COMPILE_ASSERTED_TYPE(const_expression) CA_UNIQUETYPE(_arb_compile_assertion_typedef_) |
---|
26 | |
---|
27 | #else |
---|
28 | #error static_assert.h included twice |
---|
29 | #endif // STATIC_ASSERT_H |
---|
Note: See
TracBrowser
for help on using the repository browser.