Chris@16: Chris@16: #ifndef BOOST_MPL_ASSERT_HPP_INCLUDED Chris@16: #define BOOST_MPL_ASSERT_HPP_INCLUDED Chris@16: Chris@16: // Copyright Aleksey Gurtovoy 2000-2006 Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/mpl for documentation. Chris@16: Chris@101: // $Id$ Chris@101: // $Date$ Chris@101: // $Revision$ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include // make sure 'size_t' is placed into 'std' Chris@16: #include Chris@16: Chris@16: #if BOOST_WORKAROUND(BOOST_MSVC, == 1700) Chris@16: #include Chris@16: #endif Chris@16: Chris@16: #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610)) \ Chris@16: || (BOOST_MPL_CFG_GCC != 0) \ Chris@16: || BOOST_WORKAROUND(__IBMCPP__, <= 600) Chris@16: # define BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES Chris@16: #endif Chris@16: Chris@16: #if BOOST_WORKAROUND(__MWERKS__, < 0x3202) \ Chris@16: || BOOST_WORKAROUND(__EDG_VERSION__, <= 238) \ Chris@16: || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610)) \ Chris@16: || BOOST_WORKAROUND(__DMC__, BOOST_TESTED_AT(0x840)) Chris@16: # define BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER Chris@16: #endif Chris@16: Chris@16: // agurt, 10/nov/06: use enums for Borland (which cannot cope with static constants) Chris@16: // and GCC (which issues "unused variable" warnings when static constants are used Chris@16: // at a function scope) Chris@16: #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610)) \ Chris@101: || (BOOST_MPL_CFG_GCC != 0) || (BOOST_MPL_CFG_GPU != 0) Chris@16: # define BOOST_MPL_AUX_ASSERT_CONSTANT(T, expr) enum { expr } Chris@16: #else Chris@16: # define BOOST_MPL_AUX_ASSERT_CONSTANT(T, expr) BOOST_STATIC_CONSTANT(T, expr) Chris@16: #endif Chris@16: Chris@16: Chris@16: BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_OPEN Chris@16: Chris@16: struct failed {}; Chris@16: Chris@16: // agurt, 24/aug/04: MSVC 7.1 workaround here and below: return/accept Chris@16: // 'assert' by reference; can't apply it unconditionally -- apparently it Chris@16: // degrades the quality of GCC diagnostics Chris@16: #if BOOST_WORKAROUND(BOOST_MSVC, == 1310) Chris@16: # define AUX778076_ASSERT_ARG(x) x& Chris@16: #else Chris@16: # define AUX778076_ASSERT_ARG(x) x Chris@16: #endif Chris@16: Chris@16: template< bool C > struct assert { typedef void* type; }; Chris@16: template<> struct assert { typedef AUX778076_ASSERT_ARG(assert) type; }; Chris@16: Chris@16: template< bool C > Chris@16: int assertion_failed( typename assert::type ); Chris@16: Chris@16: template< bool C > Chris@16: struct assertion Chris@16: { Chris@16: static int failed( assert ); Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct assertion Chris@16: { Chris@16: static int failed( void* ); Chris@16: }; Chris@16: Chris@16: struct assert_ Chris@16: { Chris@16: #if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES) Chris@16: template< typename T1, typename T2 = na, typename T3 = na, typename T4 = na > struct types {}; Chris@16: #endif Chris@16: static assert_ const arg; Chris@16: enum relations { equal = 1, not_equal, greater, greater_equal, less, less_equal }; Chris@16: }; Chris@16: Chris@16: Chris@16: #if !defined(BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES) Chris@16: Chris@16: bool operator==( failed, failed ); Chris@16: bool operator!=( failed, failed ); Chris@16: bool operator>( failed, failed ); Chris@16: bool operator>=( failed, failed ); Chris@16: bool operator<( failed, failed ); Chris@16: bool operator<=( failed, failed ); Chris@16: Chris@16: #if defined(__EDG_VERSION__) Chris@16: template< bool (*)(failed, failed), long x, long y > struct assert_relation {}; Chris@16: # define BOOST_MPL_AUX_ASSERT_RELATION(x, y, r) assert_relation Chris@16: #else Chris@16: template< BOOST_MPL_AUX_NTTP_DECL(long, x), BOOST_MPL_AUX_NTTP_DECL(long, y), bool (*)(failed, failed) > Chris@16: struct assert_relation {}; Chris@16: # define BOOST_MPL_AUX_ASSERT_RELATION(x, y, r) assert_relation Chris@16: #endif Chris@16: Chris@16: #else // BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES Chris@16: Chris@16: boost::mpl::aux::weighted_tag<1>::type operator==( assert_, assert_ ); Chris@16: boost::mpl::aux::weighted_tag<2>::type operator!=( assert_, assert_ ); Chris@16: boost::mpl::aux::weighted_tag<3>::type operator>( assert_, assert_ ); Chris@16: boost::mpl::aux::weighted_tag<4>::type operator>=( assert_, assert_ ); Chris@16: boost::mpl::aux::weighted_tag<5>::type operator<( assert_, assert_ ); Chris@16: boost::mpl::aux::weighted_tag<6>::type operator<=( assert_, assert_ ); Chris@16: Chris@16: template< assert_::relations r, long x, long y > struct assert_relation {}; Chris@16: Chris@16: #endif Chris@16: Chris@16: #if BOOST_WORKAROUND(BOOST_MSVC, == 1700) Chris@16: Chris@16: template Chris@16: struct extract_assert_pred; Chris@16: Chris@16: template Chris@16: struct extract_assert_pred { typedef Pred type; }; Chris@16: Chris@16: template Chris@16: struct eval_assert { Chris@16: typedef typename extract_assert_pred::type P; Chris@16: typedef typename P::type p_type; Chris@16: typedef typename ::boost::mpl::if_c), Chris@16: failed ************ P::************ Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct eval_assert_not { Chris@16: typedef typename extract_assert_pred::type P; Chris@16: typedef typename P::type p_type; Chris@16: typedef typename ::boost::mpl::if_c), Chris@16: failed ************ ::boost::mpl::not_

::************ Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: template< typename T > Chris@16: T make_assert_arg(); Chris@16: Chris@16: #elif !defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER) Chris@16: Chris@16: template< bool > struct assert_arg_pred_impl { typedef int type; }; Chris@16: template<> struct assert_arg_pred_impl { typedef void* type; }; Chris@16: Chris@16: template< typename P > struct assert_arg_pred Chris@16: { Chris@16: typedef typename P::type p_type; Chris@16: typedef typename assert_arg_pred_impl< p_type::value >::type type; Chris@16: }; Chris@16: Chris@16: template< typename P > struct assert_arg_pred_not Chris@16: { Chris@16: typedef typename P::type p_type; Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( bool, p = !p_type::value ); Chris@16: typedef typename assert_arg_pred_impl

::type type; Chris@16: }; Chris@16: Chris@16: template< typename Pred > Chris@16: failed ************ (Pred::************ Chris@16: assert_arg( void (*)(Pred), typename assert_arg_pred::type ) Chris@16: ); Chris@16: Chris@16: template< typename Pred > Chris@16: failed ************ (boost::mpl::not_::************ Chris@16: assert_not_arg( void (*)(Pred), typename assert_arg_pred_not::type ) Chris@16: ); Chris@16: Chris@16: template< typename Pred > Chris@16: AUX778076_ASSERT_ARG(assert) Chris@16: assert_arg( void (*)(Pred), typename assert_arg_pred_not::type ); Chris@16: Chris@16: template< typename Pred > Chris@16: AUX778076_ASSERT_ARG(assert) Chris@16: assert_not_arg( void (*)(Pred), typename assert_arg_pred::type ); Chris@16: Chris@16: Chris@16: #else // BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER Chris@16: Chris@16: template< bool c, typename Pred > struct assert_arg_type_impl Chris@16: { Chris@16: typedef failed ************ Pred::* mwcw83_wknd; Chris@16: typedef mwcw83_wknd ************* type; Chris@16: }; Chris@16: Chris@16: template< typename Pred > struct assert_arg_type_impl Chris@16: { Chris@16: typedef AUX778076_ASSERT_ARG(assert) type; Chris@16: }; Chris@16: Chris@16: template< typename Pred > struct assert_arg_type Chris@16: : assert_arg_type_impl< BOOST_MPL_AUX_VALUE_WKND(BOOST_MPL_AUX_NESTED_TYPE_WKND(Pred))::value, Pred > Chris@16: { Chris@16: }; Chris@16: Chris@16: template< typename Pred > Chris@16: typename assert_arg_type::type Chris@16: assert_arg(void (*)(Pred), int); Chris@16: Chris@16: template< typename Pred > Chris@16: typename assert_arg_type< boost::mpl::not_ >::type Chris@16: assert_not_arg(void (*)(Pred), int); Chris@16: Chris@16: # if !defined(BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES) Chris@16: template< long x, long y, bool (*r)(failed, failed) > Chris@16: typename assert_arg_type_impl< false,BOOST_MPL_AUX_ASSERT_RELATION(x,y,r) >::type Chris@16: assert_rel_arg( BOOST_MPL_AUX_ASSERT_RELATION(x,y,r) ); Chris@16: # else Chris@16: template< assert_::relations r, long x, long y > Chris@16: typename assert_arg_type_impl< false,assert_relation >::type Chris@16: assert_rel_arg( assert_relation ); Chris@16: # endif Chris@16: Chris@16: #endif // BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER Chris@16: Chris@16: #undef AUX778076_ASSERT_ARG Chris@16: Chris@16: BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_CLOSE Chris@16: Chris@16: #if BOOST_WORKAROUND(BOOST_MSVC, == 1700) Chris@16: Chris@16: // BOOST_MPL_ASSERT((pred)) Chris@16: Chris@16: #define BOOST_MPL_ASSERT(pred) \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( \ Chris@16: std::size_t \ Chris@16: , BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \ Chris@16: boost::mpl::assertion_failed( \ Chris@16: boost::mpl::make_assert_arg< \ Chris@16: typename boost::mpl::eval_assert::type \ Chris@16: >() \ Chris@16: ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: /**/ Chris@16: Chris@16: // BOOST_MPL_ASSERT_NOT((pred)) Chris@16: Chris@16: #define BOOST_MPL_ASSERT_NOT(pred) \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( \ Chris@16: std::size_t \ Chris@16: , BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \ Chris@16: boost::mpl::assertion_failed( \ Chris@16: boost::mpl::make_assert_arg< \ Chris@16: typename boost::mpl::eval_assert_not::type \ Chris@16: >() \ Chris@16: ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: /**/ Chris@16: Chris@16: #else Chris@16: Chris@16: // BOOST_MPL_ASSERT((pred)) Chris@16: Chris@16: #define BOOST_MPL_ASSERT(pred) \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( \ Chris@16: std::size_t \ Chris@16: , BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \ Chris@16: boost::mpl::assertion_failed( \ Chris@16: boost::mpl::assert_arg( (void (*) pred)0, 1 ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: /**/ Chris@16: Chris@16: // BOOST_MPL_ASSERT_NOT((pred)) Chris@16: Chris@16: #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) Chris@16: # define BOOST_MPL_ASSERT_NOT(pred) \ Chris@16: enum { \ Chris@16: BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \ Chris@16: boost::mpl::assertion::failed( \ Chris@16: boost::mpl::assert_not_arg( (void (*) pred)0, 1 ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: }\ Chris@16: /**/ Chris@16: #else Chris@16: # define BOOST_MPL_ASSERT_NOT(pred) \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( \ Chris@16: std::size_t \ Chris@16: , BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \ Chris@16: boost::mpl::assertion_failed( \ Chris@16: boost::mpl::assert_not_arg( (void (*) pred)0, 1 ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: /**/ Chris@16: #endif Chris@16: Chris@16: #endif Chris@16: Chris@16: // BOOST_MPL_ASSERT_RELATION(x, ==|!=|<=|<|>=|>, y) Chris@16: Chris@16: #if defined(BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES) Chris@16: Chris@16: # if !defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER) Chris@16: // agurt, 9/nov/06: 'enum' below is a workaround for gcc 4.0.4/4.1.1 bugs #29522 and #29518 Chris@16: # define BOOST_MPL_ASSERT_RELATION_IMPL(counter, x, rel, y) \ Chris@16: enum { BOOST_PP_CAT(mpl_assert_rel_value,counter) = (x rel y) }; \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( \ Chris@16: std::size_t \ Chris@16: , BOOST_PP_CAT(mpl_assertion_in_line_,counter) = sizeof( \ Chris@16: boost::mpl::assertion_failed( \ Chris@16: (boost::mpl::failed ************ ( boost::mpl::assert_relation< \ Chris@16: boost::mpl::assert_::relations( sizeof( \ Chris@16: boost::mpl::assert_::arg rel boost::mpl::assert_::arg \ Chris@16: ) ) \ Chris@16: , x \ Chris@16: , y \ Chris@16: >::************)) 0 ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: /**/ Chris@16: # else Chris@16: # define BOOST_MPL_ASSERT_RELATION_IMPL(counter, x, rel, y) \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( \ Chris@16: std::size_t \ Chris@16: , BOOST_PP_CAT(mpl_assert_rel,counter) = sizeof( \ Chris@16: boost::mpl::assert_::arg rel boost::mpl::assert_::arg \ Chris@16: ) \ Chris@16: ); \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( bool, BOOST_PP_CAT(mpl_assert_rel_value,counter) = (x rel y) ); \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( \ Chris@16: std::size_t \ Chris@16: , BOOST_PP_CAT(mpl_assertion_in_line_,counter) = sizeof( \ Chris@16: boost::mpl::assertion_failed( \ Chris@16: boost::mpl::assert_rel_arg( boost::mpl::assert_relation< \ Chris@16: boost::mpl::assert_::relations(BOOST_PP_CAT(mpl_assert_rel,counter)) \ Chris@16: , x \ Chris@16: , y \ Chris@16: >() ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: /**/ Chris@16: # endif Chris@16: Chris@16: # define BOOST_MPL_ASSERT_RELATION(x, rel, y) \ Chris@16: BOOST_MPL_ASSERT_RELATION_IMPL(BOOST_MPL_AUX_PP_COUNTER(), x, rel, y) \ Chris@16: /**/ Chris@16: Chris@16: #else // !BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES Chris@16: Chris@16: # if defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER) Chris@16: # define BOOST_MPL_ASSERT_RELATION(x, rel, y) \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( \ Chris@16: std::size_t \ Chris@16: , BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \ Chris@16: boost::mpl::assertion_failed<(x rel y)>( boost::mpl::assert_rel_arg( \ Chris@16: boost::mpl::BOOST_MPL_AUX_ASSERT_RELATION(x,y,(&boost::mpl::operator rel))() \ Chris@16: ) ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: /**/ Chris@16: # else Chris@16: # define BOOST_MPL_ASSERT_RELATION(x, rel, y) \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( \ Chris@16: std::size_t \ Chris@16: , BOOST_PP_CAT(mpl_assertion_in_line_,BOOST_MPL_AUX_PP_COUNTER()) = sizeof( \ Chris@16: boost::mpl::assertion_failed<(x rel y)>( (boost::mpl::failed ************ ( \ Chris@16: boost::mpl::BOOST_MPL_AUX_ASSERT_RELATION(x,y,(&boost::mpl::operator rel))::************))0 ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: /**/ Chris@16: # endif Chris@16: Chris@16: #endif Chris@16: Chris@16: Chris@16: // BOOST_MPL_ASSERT_MSG( (pred::value), USER_PROVIDED_MESSAGE, (types) ) Chris@16: Chris@16: #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202)) Chris@16: # define BOOST_MPL_ASSERT_MSG_IMPL( counter, c, msg, types_ ) \ Chris@16: struct msg; \ Chris@16: typedef struct BOOST_PP_CAT(msg,counter) : boost::mpl::assert_ \ Chris@16: { \ Chris@16: using boost::mpl::assert_::types; \ Chris@16: static boost::mpl::failed ************ (msg::************ assert_arg()) types_ \ Chris@16: { return 0; } \ Chris@16: } BOOST_PP_CAT(mpl_assert_arg,counter); \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( \ Chris@16: std::size_t \ Chris@16: , BOOST_PP_CAT(mpl_assertion_in_line_,counter) = sizeof( \ Chris@16: boost::mpl::assertion<(c)>::failed( BOOST_PP_CAT(mpl_assert_arg,counter)::assert_arg() ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: /**/ Chris@16: #else Chris@16: # define BOOST_MPL_ASSERT_MSG_IMPL( counter, c, msg, types_ ) \ Chris@16: struct msg; \ Chris@16: typedef struct BOOST_PP_CAT(msg,counter) : boost::mpl::assert_ \ Chris@16: { \ Chris@16: static boost::mpl::failed ************ (msg::************ assert_arg()) types_ \ Chris@16: { return 0; } \ Chris@16: } BOOST_PP_CAT(mpl_assert_arg,counter); \ Chris@16: BOOST_MPL_AUX_ASSERT_CONSTANT( \ Chris@16: std::size_t \ Chris@16: , BOOST_PP_CAT(mpl_assertion_in_line_,counter) = sizeof( \ Chris@16: boost::mpl::assertion_failed<(c)>( BOOST_PP_CAT(mpl_assert_arg,counter)::assert_arg() ) \ Chris@16: ) \ Chris@16: ) \ Chris@16: /**/ Chris@16: #endif Chris@16: Chris@16: #define BOOST_MPL_ASSERT_MSG( c, msg, types_ ) \ Chris@16: BOOST_MPL_ASSERT_MSG_IMPL( BOOST_MPL_AUX_PP_COUNTER(), c, msg, types_ ) \ Chris@16: /**/ Chris@16: Chris@16: #endif // BOOST_MPL_ASSERT_HPP_INCLUDED