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

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