Chris@16: Chris@16: #if !defined(BOOST_PP_IS_ITERATING) Chris@16: Chris@16: ///// header body Chris@16: Chris@16: //----------------------------------------------------------------------------- Chris@16: // boost variant/detail/substitute.hpp header file Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: //----------------------------------------------------------------------------- Chris@16: // Chris@16: // Copyright (c) 2003 Chris@16: // Eric Friedman Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP Chris@16: #define BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP Chris@16: Chris@16: #include "boost/mpl/aux_/config/ctps.hpp" Chris@16: Chris@16: #include "boost/variant/detail/substitute_fwd.hpp" Chris@101: #include "boost/variant/variant_fwd.hpp" // for BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES Chris@16: #include "boost/mpl/aux_/lambda_arity_param.hpp" Chris@16: #include "boost/mpl/aux_/preprocessor/params.hpp" Chris@16: #include "boost/mpl/aux_/preprocessor/repeat.hpp" Chris@16: #include "boost/mpl/int_fwd.hpp" Chris@16: #include "boost/mpl/limits/arity.hpp" Chris@16: #include "boost/preprocessor/cat.hpp" Chris@16: #include "boost/preprocessor/empty.hpp" Chris@16: #include "boost/preprocessor/arithmetic/inc.hpp" Chris@16: #include "boost/preprocessor/iterate.hpp" Chris@16: Chris@16: namespace boost { Chris@16: namespace detail { namespace variant { Chris@16: Chris@16: #if !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE) Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // (detail) metafunction substitute Chris@16: // Chris@16: // Substitutes one type for another in the given type expression. Chris@16: // Chris@16: Chris@16: // Chris@16: // primary template Chris@16: // Chris@16: template < Chris@16: typename T, typename Dest, typename Source Chris@16: BOOST_MPL_AUX_LAMBDA_ARITY_PARAM( Chris@16: typename Arity /* = ... (see substitute_fwd.hpp) */ Chris@16: ) Chris@16: > Chris@16: struct substitute Chris@16: { Chris@16: typedef T type; Chris@16: }; Chris@16: Chris@16: // Chris@16: // tag substitution specializations Chris@16: // Chris@16: Chris@16: #define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(CV_) \ Chris@16: template \ Chris@16: struct substitute< \ Chris@16: CV_ Source \ Chris@16: , Dest \ Chris@16: , Source \ Chris@16: BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>) \ Chris@16: > \ Chris@16: { \ Chris@16: typedef CV_ Dest type; \ Chris@16: }; \ Chris@16: /**/ Chris@16: Chris@16: BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG( BOOST_PP_EMPTY() ) Chris@16: BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(const) Chris@16: BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(volatile) Chris@16: BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(const volatile) Chris@16: Chris@16: #undef BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG Chris@16: Chris@16: // Chris@16: // pointer specializations Chris@16: // Chris@16: #define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(CV_) \ Chris@16: template \ Chris@16: struct substitute< \ Chris@16: T * CV_ \ Chris@16: , Dest \ Chris@16: , Source \ Chris@16: BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>) \ Chris@16: > \ Chris@16: { \ Chris@16: typedef typename substitute< \ Chris@16: T, Dest, Source \ Chris@16: >::type * CV_ type; \ Chris@16: }; \ Chris@16: /**/ Chris@16: Chris@16: BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER( BOOST_PP_EMPTY() ) Chris@16: BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(const) Chris@16: BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(volatile) Chris@16: BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(const volatile) Chris@16: Chris@16: #undef BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER Chris@16: Chris@16: // Chris@16: // reference specializations Chris@16: // Chris@16: template Chris@16: struct substitute< Chris@16: T& Chris@16: , Dest Chris@16: , Source Chris@16: BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>) Chris@16: > Chris@16: { Chris@16: typedef typename substitute< Chris@16: T, Dest, Source Chris@16: >::type & type; Chris@16: }; Chris@16: Chris@16: // Chris@16: // template expression (i.e., F<...>) specializations Chris@16: // Chris@16: Chris@101: #if !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES) Chris@101: template < Chris@101: template class F Chris@101: , typename... Ts Chris@101: , typename Dest Chris@101: , typename Source Chris@101: BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(typename Arity) Chris@101: > Chris@101: struct substitute< Chris@101: F Chris@101: , Dest Chris@101: , Source Chris@101: BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity) Chris@101: > Chris@101: { Chris@101: typedef F::type...> type; Chris@101: }; Chris@101: #endif // !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES) Chris@101: Chris@16: #define BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF_IMPL(N) \ Chris@16: typedef typename substitute< \ Chris@16: BOOST_PP_CAT(U,N), Dest, Source \ Chris@16: >::type BOOST_PP_CAT(u,N); \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF(z, N, _) \ Chris@16: BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF_IMPL( BOOST_PP_INC(N) ) \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PP_ITERATION_LIMITS (0,BOOST_MPL_LIMIT_METAFUNCTION_ARITY) Chris@16: #define BOOST_PP_FILENAME_1 "boost/variant/detail/substitute.hpp" Chris@16: #include BOOST_PP_ITERATE() Chris@16: Chris@16: #undef BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF_IMPL Chris@16: #undef BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF Chris@16: Chris@16: #endif // !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE) Chris@16: Chris@16: }} // namespace detail::variant Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP Chris@16: Chris@16: ///// iteration, depth == 1 Chris@16: Chris@16: #elif BOOST_PP_ITERATION_DEPTH() == 1 Chris@16: #define i BOOST_PP_FRAME_ITERATION(1) Chris@16: Chris@16: #if i > 0 Chris@16: Chris@16: // Chris@16: // template specializations Chris@16: // Chris@16: template < Chris@16: template < BOOST_MPL_PP_PARAMS(i,typename P) > class T Chris@16: , BOOST_MPL_PP_PARAMS(i,typename U) Chris@16: , typename Dest Chris@16: , typename Source Chris@16: > Chris@16: struct substitute< Chris@16: T< BOOST_MPL_PP_PARAMS(i,U) > Chris@16: , Dest Chris@16: , Source Chris@16: BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<( i )>) Chris@16: > Chris@16: { Chris@16: private: Chris@16: BOOST_MPL_PP_REPEAT(i, BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF, _) Chris@16: Chris@16: public: Chris@16: typedef T< BOOST_MPL_PP_PARAMS(i,u) > type; Chris@16: }; Chris@16: Chris@16: // Chris@16: // function specializations Chris@16: // Chris@16: template < Chris@16: typename R Chris@16: , BOOST_MPL_PP_PARAMS(i,typename U) Chris@16: , typename Dest Chris@16: , typename Source Chris@16: > Chris@16: struct substitute< Chris@16: R (*)( BOOST_MPL_PP_PARAMS(i,U) ) Chris@16: , Dest Chris@16: , Source Chris@16: BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>) Chris@16: > Chris@16: { Chris@16: private: Chris@16: typedef typename substitute< R, Dest, Source >::type r; Chris@16: BOOST_MPL_PP_REPEAT(i, BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF, _) Chris@16: Chris@16: public: Chris@16: typedef r (*type)( BOOST_MPL_PP_PARAMS(i,u) ); Chris@16: }; Chris@16: Chris@16: #elif i == 0 Chris@16: Chris@16: // Chris@16: // zero-arg function specialization Chris@16: // Chris@16: template < Chris@16: typename R, typename Dest, typename Source Chris@16: > Chris@16: struct substitute< Chris@16: R (*)( void ) Chris@16: , Dest Chris@16: , Source Chris@16: BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>) Chris@16: > Chris@16: { Chris@16: private: Chris@16: typedef typename substitute< R, Dest, Source >::type r; Chris@16: Chris@16: public: Chris@16: typedef r (*type)( void ); Chris@16: }; Chris@16: Chris@16: #endif // i Chris@16: Chris@16: #undef i Chris@16: #endif // BOOST_PP_IS_ITERATING