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