]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/mpl/assert.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
a20b232ade10dc70af27ee856e3f4987d2e03210
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / mpl / assert.hpp
1 \r
2 #ifndef BOOST_MPL_ASSERT_HPP_INCLUDED\r
3 #define BOOST_MPL_ASSERT_HPP_INCLUDED\r
4 \r
5 // Copyright Aleksey Gurtovoy 2000-2006\r
6 //\r
7 // Distributed under the Boost Software License, Version 1.0. \r
8 // (See accompanying file LICENSE_1_0.txt or copy at \r
9 // http://www.boost.org/LICENSE_1_0.txt)\r
10 //\r
11 // See http://www.boost.org/libs/mpl for documentation.\r
12 \r
13 // $Id: assert.hpp 49267 2008-10-11 06:19:02Z agurtovoy $\r
14 // $Date: 2008-10-11 02:19:02 -0400 (Sat, 11 Oct 2008) $\r
15 // $Revision: 49267 $\r
16 \r
17 #include <boost/mpl/not.hpp>\r
18 #include <boost/mpl/aux_/value_wknd.hpp>\r
19 #include <boost/mpl/aux_/nested_type_wknd.hpp>\r
20 #include <boost/mpl/aux_/yes_no.hpp>\r
21 #include <boost/mpl/aux_/na.hpp>\r
22 #include <boost/mpl/aux_/adl_barrier.hpp>\r
23 \r
24 #include <boost/mpl/aux_/config/nttp.hpp>\r
25 #include <boost/mpl/aux_/config/dtp.hpp>\r
26 #include <boost/mpl/aux_/config/gcc.hpp>\r
27 #include <boost/mpl/aux_/config/msvc.hpp>\r
28 #include <boost/mpl/aux_/config/static_constant.hpp>\r
29 #include <boost/mpl/aux_/config/pp_counter.hpp>\r
30 #include <boost/mpl/aux_/config/workaround.hpp>\r
31 \r
32 #include <boost/preprocessor/cat.hpp>\r
33 \r
34 #include <boost/config.hpp> // make sure 'size_t' is placed into 'std'\r
35 #include <cstddef>\r
36 \r
37 \r
38 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610)) \\r
39     || (BOOST_MPL_CFG_GCC != 0) \\r
40     || BOOST_WORKAROUND(__IBMCPP__, <= 600)\r
41 #   define BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES\r
42 #endif\r
43 \r
44 #if BOOST_WORKAROUND(__MWERKS__, < 0x3202) \\r
45     || BOOST_WORKAROUND(__EDG_VERSION__, <= 238) \\r
46     || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610)) \\r
47     || BOOST_WORKAROUND(__DMC__, BOOST_TESTED_AT(0x840))\r
48 #   define BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER\r
49 #endif\r
50 \r
51 // agurt, 10/nov/06: use enums for Borland (which cannot cope with static constants) \r
52 // and GCC (which issues "unused variable" warnings when static constants are used \r
53 // at a function scope)\r
54 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610)) \\r
55     || (BOOST_MPL_CFG_GCC != 0)\r
56 #   define BOOST_MPL_AUX_ASSERT_CONSTANT(T, expr) enum { expr }\r
57 #else\r
58 #   define BOOST_MPL_AUX_ASSERT_CONSTANT(T, expr) BOOST_STATIC_CONSTANT(T, expr)\r
59 #endif\r
60 \r
61 \r
62 BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_OPEN\r
63 \r
64 struct failed {};\r
65 \r
66 // agurt, 24/aug/04: MSVC 7.1 workaround here and below: return/accept \r
67 // 'assert<false>' by reference; can't apply it unconditionally -- apparently it\r
68 // degrades the quality of GCC diagnostics\r
69 #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)\r
70 #   define AUX778076_ASSERT_ARG(x) x&\r
71 #else\r
72 #   define AUX778076_ASSERT_ARG(x) x\r
73 #endif\r
74 \r
75 template< bool C >  struct assert        { typedef void* type; };\r
76 template<>          struct assert<false> { typedef AUX778076_ASSERT_ARG(assert) type; };\r
77 \r
78 template< bool C >\r
79 int assertion_failed( typename assert<C>::type );\r
80 \r
81 template< bool C >\r
82 struct assertion\r
83 {\r
84     static int failed( assert<false> );\r
85 };\r
86 \r
87 template<>\r
88 struct assertion<true>\r
89 {\r
90     static int failed( void* );\r
91 };\r
92 \r
93 struct assert_\r
94 {\r
95 #if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES)\r
96     template< typename T1, typename T2 = na, typename T3 = na, typename T4 = na > struct types {};\r
97 #endif\r
98     static assert_ const arg;\r
99     enum relations { equal = 1, not_equal, greater, greater_equal, less, less_equal };\r
100 };\r
101 \r
102 \r
103 #if !defined(BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES)\r
104 \r
105 bool operator==( failed, failed );\r
106 bool operator!=( failed, failed );\r
107 bool operator>( failed, failed );\r
108 bool operator>=( failed, failed );\r
109 bool operator<( failed, failed );\r
110 bool operator<=( failed, failed );\r
111 \r
112 #if defined(__EDG_VERSION__)\r
113 template< bool (*)(failed, failed), long x, long y > struct assert_relation {};\r
114 #   define BOOST_MPL_AUX_ASSERT_RELATION(x, y, r) assert_relation<r,x,y>\r
115 #else\r
116 template< BOOST_MPL_AUX_NTTP_DECL(long, x), BOOST_MPL_AUX_NTTP_DECL(long, y), bool (*)(failed, failed) > \r
117 struct assert_relation {};\r
118 #   define BOOST_MPL_AUX_ASSERT_RELATION(x, y, r) assert_relation<x,y,r>\r
119 #endif\r
120 \r
121 #else // BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES\r
122 \r
123 boost::mpl::aux::weighted_tag<1>::type operator==( assert_, assert_ );\r
124 boost::mpl::aux::weighted_tag<2>::type operator!=( assert_, assert_ );\r
125 boost::mpl::aux::weighted_tag<3>::type operator>(  assert_, assert_ );\r
126 boost::mpl::aux::weighted_tag<4>::type operator>=( assert_, assert_ );\r
127 boost::mpl::aux::weighted_tag<5>::type operator<( assert_, assert_ );\r
128 boost::mpl::aux::weighted_tag<6>::type operator<=( assert_, assert_ );\r
129 \r
130 template< assert_::relations r, long x, long y > struct assert_relation {};\r
131 \r
132 #endif \r
133 \r
134 \r
135 #if !defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER)\r
136 \r
137 template< bool > struct assert_arg_pred_impl { typedef int type; };\r
138 template<> struct assert_arg_pred_impl<true> { typedef void* type; };\r
139 \r
140 template< typename P > struct assert_arg_pred\r
141 {\r
142     typedef typename P::type p_type;\r
143     typedef typename assert_arg_pred_impl< p_type::value >::type type;\r
144 };\r
145 \r
146 template< typename P > struct assert_arg_pred_not\r
147 {\r
148     typedef typename P::type p_type;\r
149     BOOST_MPL_AUX_ASSERT_CONSTANT( bool, p = !p_type::value );\r
150     typedef typename assert_arg_pred_impl<p>::type type;\r
151 };\r
152 \r
153 template< typename Pred >\r
154 failed ************ (Pred::************ \r
155       assert_arg( void (*)(Pred), typename assert_arg_pred<Pred>::type )\r
156     );\r
157 \r
158 template< typename Pred >\r
159 failed ************ (boost::mpl::not_<Pred>::************ \r
160       assert_not_arg( void (*)(Pred), typename assert_arg_pred_not<Pred>::type )\r
161     );\r
162 \r
163 template< typename Pred >\r
164 AUX778076_ASSERT_ARG(assert<false>)\r
165 assert_arg( void (*)(Pred), typename assert_arg_pred_not<Pred>::type );\r
166 \r
167 template< typename Pred >\r
168 AUX778076_ASSERT_ARG(assert<false>)\r
169 assert_not_arg( void (*)(Pred), typename assert_arg_pred<Pred>::type );\r
170 \r
171 \r
172 #else // BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER\r
173         \r
174 template< bool c, typename Pred > struct assert_arg_type_impl\r
175 {\r
176     typedef failed      ************ Pred::* mwcw83_wknd;\r
177     typedef mwcw83_wknd ************* type;\r
178 };\r
179 \r
180 template< typename Pred > struct assert_arg_type_impl<true,Pred>\r
181 {\r
182     typedef AUX778076_ASSERT_ARG(assert<false>) type;\r
183 };\r
184 \r
185 template< typename Pred > struct assert_arg_type\r
186     : assert_arg_type_impl< BOOST_MPL_AUX_VALUE_WKND(BOOST_MPL_AUX_NESTED_TYPE_WKND(Pred))::value, Pred >\r
187 {\r
188 };\r
189 \r
190 template< typename Pred >\r
191 typename assert_arg_type<Pred>::type \r
192 assert_arg(void (*)(Pred), int);\r
193 \r
194 template< typename Pred >\r
195 typename assert_arg_type< boost::mpl::not_<Pred> >::type \r
196 assert_not_arg(void (*)(Pred), int);\r
197 \r
198 #   if !defined(BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES)\r
199 template< long x, long y, bool (*r)(failed, failed) >\r
200 typename assert_arg_type_impl< false,BOOST_MPL_AUX_ASSERT_RELATION(x,y,r) >::type\r
201 assert_rel_arg( BOOST_MPL_AUX_ASSERT_RELATION(x,y,r) );\r
202 #   else\r
203 template< assert_::relations r, long x, long y >\r
204 typename assert_arg_type_impl< false,assert_relation<r,x,y> >::type\r
205 assert_rel_arg( assert_relation<r,x,y> );\r
206 #   endif\r
207 \r
208 #endif // BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER\r
209 \r
210 #undef AUX778076_ASSERT_ARG\r
211 \r
212 BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_CLOSE\r
213 \r
214 \r
215 // BOOST_MPL_ASSERT((pred<x,...>))\r
216 \r
217 #define BOOST_MPL_ASSERT(pred) \\r
218 BOOST_MPL_AUX_ASSERT_CONSTANT( \\r
219       std::size_t \\r
220     , BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \\r
221           boost::mpl::assertion_failed<false>( \\r
222               boost::mpl::assert_arg( (void (*) pred)0, 1 ) \\r
223             ) \\r
224         ) \\r
225     ) \\r
226 /**/\r
227 \r
228 // BOOST_MPL_ASSERT_NOT((pred<x,...>))\r
229 \r
230 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)\r
231 #   define BOOST_MPL_ASSERT_NOT(pred) \\r
232 enum { \\r
233       BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \\r
234           boost::mpl::assertion<false>::failed( \\r
235               boost::mpl::assert_not_arg( (void (*) pred)0, 1 ) \\r
236             ) \\r
237         ) \\r
238 }\\r
239 /**/\r
240 #else\r
241 #   define BOOST_MPL_ASSERT_NOT(pred) \\r
242 BOOST_MPL_AUX_ASSERT_CONSTANT( \\r
243       std::size_t \\r
244     , BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \\r
245           boost::mpl::assertion_failed<false>( \\r
246               boost::mpl::assert_not_arg( (void (*) pred)0, 1 ) \\r
247             ) \\r
248         ) \\r
249    ) \\r
250 /**/\r
251 #endif\r
252 \r
253 // BOOST_MPL_ASSERT_RELATION(x, ==|!=|<=|<|>=|>, y)\r
254 \r
255 #if defined(BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES)\r
256 \r
257 #   if !defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER)\r
258 // agurt, 9/nov/06: 'enum' below is a workaround for gcc 4.0.4/4.1.1 bugs #29522 and #29518\r
259 #   define BOOST_MPL_ASSERT_RELATION_IMPL(counter, x, rel, y)      \\r
260 enum { BOOST_PP_CAT(mpl_assert_rel_value,counter) = (x rel y) }; \\r
261 BOOST_MPL_AUX_ASSERT_CONSTANT( \\r
262       std::size_t \\r
263     , BOOST_PP_CAT(mpl_assertion_in_line_,counter) = sizeof( \\r
264         boost::mpl::assertion_failed<BOOST_PP_CAT(mpl_assert_rel_value,counter)>( \\r
265             (boost::mpl::failed ************ ( boost::mpl::assert_relation< \\r
266                   boost::mpl::assert_::relations( sizeof( \\r
267                       boost::mpl::assert_::arg rel boost::mpl::assert_::arg \\r
268                     ) ) \\r
269                 , x \\r
270                 , y \\r
271                 >::************)) 0 ) \\r
272         ) \\r
273     ) \\r
274 /**/\r
275 #   else\r
276 #   define BOOST_MPL_ASSERT_RELATION_IMPL(counter, x, rel, y)    \\r
277 BOOST_MPL_AUX_ASSERT_CONSTANT( \\r
278       std::size_t \\r
279     , BOOST_PP_CAT(mpl_assert_rel,counter) = sizeof( \\r
280           boost::mpl::assert_::arg rel boost::mpl::assert_::arg \\r
281         ) \\r
282     ); \\r
283 BOOST_MPL_AUX_ASSERT_CONSTANT( bool, BOOST_PP_CAT(mpl_assert_rel_value,counter) = (x rel y) ); \\r
284 BOOST_MPL_AUX_ASSERT_CONSTANT( \\r
285       std::size_t \\r
286     , BOOST_PP_CAT(mpl_assertion_in_line_,counter) = sizeof( \\r
287         boost::mpl::assertion_failed<BOOST_PP_CAT(mpl_assert_rel_value,counter)>( \\r
288               boost::mpl::assert_rel_arg( boost::mpl::assert_relation< \\r
289                   boost::mpl::assert_::relations(BOOST_PP_CAT(mpl_assert_rel,counter)) \\r
290                 , x \\r
291                 , y \\r
292                 >() ) \\r
293             ) \\r
294         ) \\r
295     ) \\r
296 /**/\r
297 #   endif\r
298 \r
299 #   define BOOST_MPL_ASSERT_RELATION(x, rel, y) \\r
300 BOOST_MPL_ASSERT_RELATION_IMPL(BOOST_MPL_AUX_PP_COUNTER(), x, rel, y) \\r
301 /**/\r
302 \r
303 #else // !BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES\r
304 \r
305 #   if defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER)\r
306 #   define BOOST_MPL_ASSERT_RELATION(x, rel, y) \\r
307 BOOST_MPL_AUX_ASSERT_CONSTANT( \\r
308       std::size_t \\r
309     , BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \\r
310         boost::mpl::assertion_failed<(x rel y)>( boost::mpl::assert_rel_arg( \\r
311               boost::mpl::BOOST_MPL_AUX_ASSERT_RELATION(x,y,(&boost::mpl::operator rel))() \\r
312             ) ) \\r
313         ) \\r
314     ) \\r
315 /**/\r
316 #   else\r
317 #   define BOOST_MPL_ASSERT_RELATION(x, rel, y) \\r
318 BOOST_MPL_AUX_ASSERT_CONSTANT( \\r
319       std::size_t \\r
320     , BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \\r
321         boost::mpl::assertion_failed<(x rel y)>( (boost::mpl::failed ************ ( \\r
322             boost::mpl::BOOST_MPL_AUX_ASSERT_RELATION(x,y,(&boost::mpl::operator rel))::************))0 ) \\r
323         ) \\r
324     ) \\r
325 /**/\r
326 #   endif\r
327 \r
328 #endif\r
329 \r
330 \r
331 // BOOST_MPL_ASSERT_MSG( (pred<x,...>::value), USER_PROVIDED_MESSAGE, (types<x,...>) ) \r
332 \r
333 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202))\r
334 #   define BOOST_MPL_ASSERT_MSG_IMPL( counter, c, msg, types_ ) \\r
335 struct msg; \\r
336 typedef struct BOOST_PP_CAT(msg,counter) : boost::mpl::assert_ \\r
337 { \\r
338     using boost::mpl::assert_::types; \\r
339     static boost::mpl::failed ************ (msg::************ assert_arg()) types_ \\r
340     { return 0; } \\r
341 } BOOST_PP_CAT(mpl_assert_arg,counter); \\r
342 BOOST_MPL_AUX_ASSERT_CONSTANT( \\r
343       std::size_t \\r
344     , BOOST_PP_CAT(mpl_assertion_in_line_,counter) = sizeof( \\r
345         boost::mpl::assertion<(c)>::failed( BOOST_PP_CAT(mpl_assert_arg,counter)::assert_arg() ) \\r
346         ) \\r
347     ) \\r
348 /**/\r
349 #else\r
350 #   define BOOST_MPL_ASSERT_MSG_IMPL( counter, c, msg, types_ )  \\r
351 struct msg; \\r
352 typedef struct BOOST_PP_CAT(msg,counter) : boost::mpl::assert_ \\r
353 { \\r
354     static boost::mpl::failed ************ (msg::************ assert_arg()) types_ \\r
355     { return 0; } \\r
356 } BOOST_PP_CAT(mpl_assert_arg,counter); \\r
357 BOOST_MPL_AUX_ASSERT_CONSTANT( \\r
358       std::size_t \\r
359     , BOOST_PP_CAT(mpl_assertion_in_line_,counter) = sizeof( \\r
360         boost::mpl::assertion_failed<(c)>( BOOST_PP_CAT(mpl_assert_arg,counter)::assert_arg() ) \\r
361         ) \\r
362     ) \\r
363 /**/\r
364 #endif\r
365 \r
366 #define BOOST_MPL_ASSERT_MSG( c, msg, types_ ) \\r
367 BOOST_MPL_ASSERT_MSG_IMPL( BOOST_MPL_AUX_PP_COUNTER(), c, msg, types_ ) \\r
368 /**/\r
369 \r
370 #endif // BOOST_MPL_ASSERT_HPP_INCLUDED\r