iutest  1.17.99.14
iutest_static_assertion.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_STATIC_ASSERTION_HPP_53842FD6_9E5D_40A6_905D_EC6DEBE5ED6A_
16 #define INCG_IRIS_IUTEST_STATIC_ASSERTION_HPP_53842FD6_9E5D_40A6_905D_EC6DEBE5ED6A_
17 
18 //======================================================================
19 // define
20 #if IUTEST_HAS_STATIC_ASSERT_TYPEEQ
21 
22 #if 0
23 
24 namespace iutest
25 {
26 
27 namespace detail
28 {
29  template<typename T1, typename T2>
30  struct StaticAssertTypeEqHelper;
31 }
32 
37 template<typename T1, typename T2>
38 static bool StaticAssertTypeEq()
39 {
40  return detail::StaticAssertTypeEqHelper<T1, T2>();
41 }
42 
43 } // end of namespace iutest
44 
45 #else
46 
53 #define StaticAssertTypeEq detail::StaticAssertTypeEqHelper
54 
55 #endif
56 
57 #endif
58 
62 #if IUTEST_HAS_STATIC_ASSERT
63 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)))
64 # define IUTEST_STATIC_ASSERT_MSG(B, Msg) static_assert(B, "static_assert: " Msg)
65 #else
66 # define IUTEST_STATIC_ASSERT_MSG(B, Msg) static_assert(B, Msg)
67 #endif
68 #else
69 # define IIUT_STATIC_ASSERT_SIZECHECK(B) sizeof(::iutest::detail::static_assert_failure< (bool)(B) >) // NOLINT
70 # define IUTEST_STATIC_ASSERT_MSG(B, Msg) \
71  typedef ::iutest::detail::StaticAssertionTest< IIUT_STATIC_ASSERT_SIZECHECK(B) > \
72  IUTEST_PP_CAT(iutest_static_assert_typedef_, IUTEST_PP_COUNTER) IUTEST_ATTRIBUTE_UNUSED_
73 #endif
74 
78 #ifdef IUTEST_STATIC_ASSERT_MSG
79 # ifdef IUTEST_NO_VARIADIC_MACROS
80 # define IUTEST_STATIC_ASSERT(B) IUTEST_STATIC_ASSERT_MSG((B), #B)
81 # else
82 # define IUTEST_STATIC_ASSERT(...) IUTEST_STATIC_ASSERT_MSG((__VA_ARGS__), #__VA_ARGS__)
83 # endif
84 #endif
85 
89 #ifndef IUTEST_STATIC_ASSERT_IF_EXISTS
90 # if IUTEST_HAS_IF_EXISTS
91 # define IUTEST_STATIC_ASSERT_IF_EXISTS(identifier, msg) \
92  IUTEST_STATIC_ASSERT_MSG( IUTEST_IF_EXISTS(identifier, true) IUTEST_IF_NOT_EXISTS(identifier, false), msg)
93 # else
94 # define IUTEST_STATIC_ASSERT_IF_EXISTS(identifier, msg)
95 # endif
96 #endif
97 
101 #ifndef IUTEST_STATIC_ASSERT_IF_NOT_EXISTS
102 # if IUTEST_HAS_IF_EXISTS
103 # define IUTEST_STATIC_ASSERT_IF_NOT_EXISTS(identifier, msg) \
104  IUTEST_STATIC_ASSERT_MSG(IUTEST_IF_NOT_EXISTS(identifier, true) IUTEST_IF_EXISTS(identifier, false), msg)
105 # else
106 # define IUTEST_STATIC_ASSERT_IF_NOT_EXISTS(identifier, msg)
107 # endif
108 #endif
109 
110 //======================================================================
111 // function
112 namespace iutest
113 {
114 
115 namespace detail
116 {
117 
119 template<typename T1, typename T2>
120 struct StaticAssertTypeEqHelper;
121 
122 #if !defined(IUTEST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
123 namespace helper
124 {
125 
127 template<bool b>struct static_assert_typeeq;
129 template<>struct static_assert_typeeq<true> { operator bool() const { return true; } };
130 
131 }
132 
134 template<typename T1, typename T2>
135 struct StaticAssertTypeEqHelper
136  : public helper::static_assert_typeeq< iutest_type_traits::is_same<T1, T2>::value >
137 {
138 };
139 
140 #endif
141 
143 template<bool b>struct static_assert_failure;
145 template<> struct static_assert_failure<true> { enum { value = 1 }; };
146 
148 template<int x>struct StaticAssertionTest {};
149 
150 } // end of namespace detail
151 } // end of namespace iutest
152 
153 #endif // INCG_IRIS_IUTEST_STATIC_ASSERTION_HPP_53842FD6_9E5D_40A6_905D_EC6DEBE5ED6A_
#define StaticAssertTypeEq
型アサーション
Definition: iutest_static_assertion.hpp:54
iutest root namespace
Definition: iutest_charcode.hpp:33