2 #ifndef BOOST_MPL_ASSERT_HPP_INCLUDED
3 #define BOOST_MPL_ASSERT_HPP_INCLUDED
5 // Copyright Aleksey Gurtovoy 2000-2004
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)
11 // See http://www.boost.org/libs/mpl for documentation.
13 // $Source: /cvsroot/boost/boost/boost/mpl/assert.hpp,v $
14 // $Date: 2004/09/28 13:56:58 $
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>
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>
30 #include <boost/preprocessor/cat.hpp>
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
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
45 BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_OPEN
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&
55 # define AUX778076_ASSERT_ARG(x) x
58 template< bool C > struct assert { typedef void* type; };
59 template<> struct assert<false> { typedef AUX778076_ASSERT_ARG(assert) type; };
62 int assertion_failed( typename assert<C>::type );
67 static int failed( assert<false> );
71 struct assertion<true>
73 static int failed( void* );
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 {};
81 static assert_ const arg;
82 enum relations { equal = 1, not_equal, greater, greater_equal, less, less_equal };
86 #if !defined(BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES)
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 );
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>
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>
104 #else // BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES
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_ );
113 template< assert_::relations r, long x, long y > struct assert_relation {};
118 #if !defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER)
120 template< bool > struct assert_arg_pred_impl { typedef int type; };
121 template<> struct assert_arg_pred_impl<true> { typedef void* type; };
123 template< typename P > struct assert_arg_pred
125 typedef typename P::type p_type;
126 typedef typename assert_arg_pred_impl< p_type::value >::type type;
129 template< typename P > struct assert_arg_pred_not
131 typedef typename P::type p_type;
132 enum { p = !p_type::value };
133 typedef typename assert_arg_pred_impl<p>::type type;
136 template< typename Pred >
137 failed ************ (Pred::************
138 assert_arg( void (*)(Pred), typename assert_arg_pred<Pred>::type )
141 template< typename Pred >
142 failed ************ (boost::mpl::not_<Pred>::************
143 assert_not_arg( void (*)(Pred), typename assert_arg_pred_not<Pred>::type )
146 template< typename Pred >
147 AUX778076_ASSERT_ARG(assert<false>)
148 assert_arg( void (*)(Pred), typename assert_arg_pred_not<Pred>::type );
150 template< typename Pred >
151 AUX778076_ASSERT_ARG(assert<false>)
152 assert_not_arg( void (*)(Pred), typename assert_arg_pred<Pred>::type );
155 #else // BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER
157 template< bool c, typename Pred > struct assert_arg_type_impl
159 typedef failed ************ Pred::* mwcw83_wknd;
160 typedef mwcw83_wknd ************* type;
163 template< typename Pred > struct assert_arg_type_impl<true,Pred>
165 typedef AUX778076_ASSERT_ARG(assert<false>) type;
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 >
173 template< typename Pred >
174 typename assert_arg_type<Pred>::type
175 assert_arg(void (*)(Pred), int);
177 template< typename Pred >
178 typename assert_arg_type< boost::mpl::not_<Pred> >::type
179 assert_not_arg(void (*)(Pred), int);
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) );
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> );
191 #endif // BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER
193 #undef AUX778076_ASSERT_ARG
195 BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_CLOSE
198 // BOOST_MPL_ASSERT((pred<x,...>))
200 #define BOOST_MPL_ASSERT(pred) \
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 ) \
210 // BOOST_MPL_ASSERT_NOT((pred<x,...>))
212 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
213 # define BOOST_MPL_ASSERT_NOT(pred) \
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 ) \
223 # define BOOST_MPL_ASSERT_NOT(pred) \
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 ) \
234 // BOOST_MPL_ASSERT_RELATION(x, ==|!=|<=|<|>=|>, y)
236 #if defined(BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES)
238 # if !defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER)
239 # define BOOST_MPL_ASSERT_RELATION(x, rel, y) \
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 \
249 >::************)) 0 ) \
254 # define BOOST_MPL_ASSERT_RELATION(x, rel, y) \
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__)) \
271 #else // !BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES
273 # if defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER)
274 # define BOOST_MPL_ASSERT_RELATION(x, rel, y) \
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))() \
284 # define BOOST_MPL_ASSERT_RELATION(x, rel, y) \
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 ) \
297 // BOOST_MPL_ASSERT_MSG( (pred<x,...>::value), USER_PROVIDED_MESSAGE, (types<x,...>) )
299 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202))
300 # define BOOST_MPL_ASSERT_MSG( c, msg, types_ ) \
302 typedef struct BOOST_PP_CAT(msg,__LINE__) : boost::mpl::assert_ \
304 using boost::mpl::assert_::types; \
305 static boost::mpl::failed ************ (msg::************ assert_arg()) types_ \
307 } BOOST_PP_CAT(mpl_assert_arg,__LINE__); \
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() ) \
315 # define BOOST_MPL_ASSERT_MSG( c, msg, types_ ) \
317 typedef struct BOOST_PP_CAT(msg,__LINE__) : boost::mpl::assert_ \
319 static boost::mpl::failed ************ (msg::************ assert_arg()) types_ \
321 } BOOST_PP_CAT(mpl_assert_arg,__LINE__); \
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() ) \
330 #endif // BOOST_MPL_ASSERT_HPP_INCLUDED