Chris@16: Chris@16: #if !defined(BOOST_PP_IS_ITERATING) Chris@16: Chris@16: ///// header body Chris@16: Chris@16: #ifndef BOOST_MPL_BIND_HPP_INCLUDED Chris@16: #define BOOST_MPL_BIND_HPP_INCLUDED Chris@16: Chris@16: // Copyright Peter Dimov 2001 Chris@16: // Copyright Aleksey Gurtovoy 2001-2004 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: #if !defined(BOOST_MPL_PREPROCESSING_MODE) Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) Chris@16: # include Chris@16: # endif Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \ Chris@16: && !defined(BOOST_MPL_PREPROCESSING_MODE) Chris@16: Chris@16: # if defined(BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT) Chris@16: # define BOOST_MPL_PREPROCESSED_HEADER basic_bind.hpp Chris@16: # else Chris@16: # define BOOST_MPL_PREPROCESSED_HEADER bind.hpp Chris@16: # endif Chris@16: # include Chris@16: Chris@16: #else Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include 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@16: Chris@16: namespace boost { namespace mpl { Chris@16: Chris@16: // local macros, #undef-ined at the end of the header Chris@16: # define AUX778076_APPLY \ Chris@16: BOOST_PP_CAT(apply_wrap,BOOST_MPL_LIMIT_METAFUNCTION_ARITY) \ Chris@16: /**/ Chris@16: Chris@16: # if defined(BOOST_MPL_CFG_DMC_AMBIGUOUS_CTPS) Chris@16: # define AUX778076_DMC_PARAM() , int dummy_ Chris@16: # else Chris@16: # define AUX778076_DMC_PARAM() Chris@16: # endif Chris@16: Chris@16: # define AUX778076_BIND_PARAMS(param) \ Chris@16: BOOST_MPL_PP_PARAMS( \ Chris@16: BOOST_MPL_LIMIT_METAFUNCTION_ARITY \ Chris@16: , param \ Chris@16: ) \ Chris@16: /**/ Chris@16: Chris@16: # define AUX778076_BIND_DEFAULT_PARAMS(param, value) \ Chris@16: BOOST_MPL_PP_DEFAULT_PARAMS( \ Chris@16: BOOST_MPL_LIMIT_METAFUNCTION_ARITY \ Chris@16: , param \ Chris@16: , value \ Chris@16: ) \ Chris@16: /**/ Chris@16: Chris@16: # define AUX778076_BIND_N_PARAMS(n, param) \ Chris@16: BOOST_PP_COMMA_IF(n) BOOST_MPL_PP_PARAMS(n, param) \ Chris@16: /**/ Chris@16: Chris@16: # define AUX778076_BIND_N_SPEC_PARAMS(n, param, def) \ Chris@16: BOOST_PP_COMMA_IF(n) \ Chris@16: BOOST_MPL_PP_PARTIAL_SPEC_PARAMS(n, param, def) \ Chris@16: /**/ Chris@16: Chris@16: #if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES) Chris@16: # define AUX778076_BIND_NESTED_DEFAULT_PARAMS(param, value) \ Chris@16: AUX778076_BIND_DEFAULT_PARAMS(param, value) \ Chris@16: /**/ Chris@16: #else Chris@16: # define AUX778076_BIND_NESTED_DEFAULT_PARAMS(param, value) \ Chris@16: AUX778076_BIND_PARAMS(param) \ Chris@16: /**/ Chris@16: #endif Chris@16: Chris@16: namespace aux { Chris@16: Chris@16: #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) Chris@16: Chris@16: template< Chris@16: typename T, AUX778076_BIND_PARAMS(typename U) Chris@16: > Chris@16: struct resolve_bind_arg Chris@16: { Chris@16: typedef T type; Chris@16: }; Chris@16: Chris@16: # if !defined(BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT) Chris@16: Chris@16: template< Chris@16: typename T Chris@16: , typename Arg Chris@16: > Chris@16: struct replace_unnamed_arg Chris@16: { Chris@16: typedef Arg next; Chris@16: typedef T type; Chris@16: }; Chris@16: Chris@16: template< Chris@16: typename Arg Chris@16: > Chris@16: struct replace_unnamed_arg< arg<-1>,Arg > Chris@16: { Chris@16: typedef typename Arg::next next; Chris@16: typedef Arg type; Chris@16: }; Chris@16: Chris@16: # endif // BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT Chris@16: Chris@16: template< Chris@16: BOOST_MPL_AUX_NTTP_DECL(int, N), AUX778076_BIND_PARAMS(typename U) Chris@16: > Chris@16: struct resolve_bind_arg< arg,AUX778076_BIND_PARAMS(U) > Chris@16: { Chris@16: typedef typename AUX778076_APPLY, AUX778076_BIND_PARAMS(U)>::type type; Chris@16: }; Chris@16: Chris@16: #if !defined(BOOST_MPL_CFG_NO_BIND_TEMPLATE) Chris@16: template< Chris@16: typename F, AUX778076_BIND_PARAMS(typename T), AUX778076_BIND_PARAMS(typename U) Chris@16: > Chris@16: struct resolve_bind_arg< bind,AUX778076_BIND_PARAMS(U) > Chris@16: { Chris@16: typedef bind f_; Chris@16: typedef typename AUX778076_APPLY::type type; Chris@16: }; Chris@16: #endif Chris@16: Chris@16: #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Chris@16: Chris@16: // agurt, 15/jan/02: it's not a intended to be used as a function class, and Chris@16: // MSVC6.5 has problems with 'apply' name here (the code compiles, but doesn't Chris@16: // work), so I went with the 'result_' here, and in all other similar cases Chris@16: template< bool > Chris@16: struct resolve_arg_impl Chris@16: { Chris@16: template< typename T, AUX778076_BIND_PARAMS(typename U) > struct result_ Chris@16: { Chris@16: typedef T type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct resolve_arg_impl Chris@16: { Chris@16: template< typename T, AUX778076_BIND_PARAMS(typename U) > struct result_ Chris@16: { Chris@16: typedef typename AUX778076_APPLY< Chris@16: T Chris@16: , AUX778076_BIND_PARAMS(U) Chris@16: >::type type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: // for 'resolve_bind_arg' Chris@16: template< typename T > struct is_bind_template; Chris@16: Chris@16: template< Chris@16: typename T, AUX778076_BIND_PARAMS(typename U) Chris@16: > Chris@16: struct resolve_bind_arg Chris@16: : resolve_arg_impl< is_bind_template::value > Chris@16: ::template result_< T,AUX778076_BIND_PARAMS(U) > Chris@16: { Chris@16: }; Chris@16: Chris@16: # if !defined(BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT) Chris@16: Chris@16: template< typename T > Chris@16: struct replace_unnamed_arg_impl Chris@16: { Chris@16: template< typename Arg > struct result_ Chris@16: { Chris@16: typedef Arg next; Chris@16: typedef T type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct replace_unnamed_arg_impl< arg<-1> > Chris@16: { Chris@16: template< typename Arg > struct result_ Chris@16: { Chris@16: typedef typename next::type next; Chris@16: typedef Arg type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: template< typename T, typename Arg > Chris@16: struct replace_unnamed_arg Chris@16: : replace_unnamed_arg_impl::template result_ Chris@16: { Chris@16: }; Chris@16: Chris@16: # endif // BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT Chris@16: Chris@16: // agurt, 10/mar/02: the forward declaration has to appear before any of Chris@16: // 'is_bind_helper' overloads, otherwise MSVC6.5 issues an ICE on it Chris@16: template< BOOST_MPL_AUX_NTTP_DECL(int, arity_) > struct bind_chooser; Chris@16: Chris@16: aux::no_tag is_bind_helper(...); Chris@16: template< typename T > aux::no_tag is_bind_helper(protect*); Chris@16: Chris@16: // overload for "main" form Chris@16: // agurt, 15/mar/02: MSVC 6.5 fails to properly resolve the overload Chris@16: // in case if we use 'aux::type_wrapper< bind<...> >' here, and all Chris@16: // 'bind' instantiations form a complete type anyway Chris@16: #if !defined(BOOST_MPL_CFG_NO_BIND_TEMPLATE) Chris@16: template< Chris@16: typename F, AUX778076_BIND_PARAMS(typename T) Chris@16: > Chris@16: aux::yes_tag is_bind_helper(bind*); Chris@16: #endif Chris@16: Chris@16: template< BOOST_MPL_AUX_NTTP_DECL(int, N) > Chris@16: aux::yes_tag is_bind_helper(arg*); Chris@16: Chris@16: template< bool is_ref_ = true > Chris@16: struct is_bind_template_impl Chris@16: { Chris@16: template< typename T > struct result_ Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = false); Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct is_bind_template_impl Chris@16: { Chris@16: template< typename T > struct result_ Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = Chris@16: sizeof(aux::is_bind_helper(static_cast(0))) Chris@16: == sizeof(aux::yes_tag) Chris@16: ); Chris@16: }; Chris@16: }; Chris@16: Chris@16: template< typename T > struct is_bind_template Chris@16: : is_bind_template_impl< ::boost::detail::is_reference_impl::value > Chris@16: ::template result_ Chris@16: { Chris@16: }; Chris@16: Chris@16: #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Chris@16: Chris@16: } // namespace aux Chris@16: Chris@16: Chris@16: #define BOOST_PP_ITERATION_PARAMS_1 \ Chris@16: (3,(0, BOOST_MPL_LIMIT_METAFUNCTION_ARITY, )) Chris@16: #include BOOST_PP_ITERATE() Chris@16: Chris@16: #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ Chris@16: && !defined(BOOST_MPL_CFG_NO_TEMPLATE_TEMPLATE_PARAMETERS) Chris@16: /// if_/eval_if specializations Chris@16: # define AUX778076_SPEC_NAME if_ Chris@16: # define BOOST_PP_ITERATION_PARAMS_1 (3,(3, 3, )) Chris@16: # include BOOST_PP_ITERATE() Chris@16: Chris@16: #if !defined(BOOST_MPL_CFG_DMC_AMBIGUOUS_CTPS) Chris@16: # define AUX778076_SPEC_NAME eval_if Chris@16: # define BOOST_PP_ITERATION_PARAMS_1 (3,(3, 3, )) Chris@16: # include BOOST_PP_ITERATE() Chris@16: #endif Chris@16: #endif Chris@16: Chris@16: // real C++ version is already taken care of Chris@16: #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ Chris@16: && !defined(BOOST_MPL_CFG_NO_BIND_TEMPLATE) Chris@16: Chris@16: namespace aux { Chris@16: // apply_count_args Chris@16: #define AUX778076_COUNT_ARGS_PREFIX bind Chris@16: #define AUX778076_COUNT_ARGS_DEFAULT na Chris@16: #define AUX778076_COUNT_ARGS_ARITY BOOST_MPL_LIMIT_METAFUNCTION_ARITY Chris@16: #include Chris@16: } Chris@16: Chris@16: // bind Chris@16: template< Chris@16: typename F, AUX778076_BIND_PARAMS(typename T) AUX778076_DMC_PARAM() Chris@16: > Chris@16: struct bind Chris@16: : aux::bind_chooser< Chris@16: aux::bind_count_args::value Chris@16: >::template result_< F,AUX778076_BIND_PARAMS(T) >::type Chris@16: { Chris@16: }; Chris@16: Chris@16: BOOST_MPL_AUX_ARITY_SPEC( Chris@16: BOOST_PP_INC(BOOST_MPL_LIMIT_METAFUNCTION_ARITY) Chris@16: , bind Chris@16: ) Chris@16: Chris@16: BOOST_MPL_AUX_TEMPLATE_ARITY_SPEC( Chris@16: BOOST_PP_INC(BOOST_MPL_LIMIT_METAFUNCTION_ARITY) Chris@16: , bind Chris@16: ) Chris@16: Chris@16: Chris@16: #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Chris@16: Chris@16: # undef AUX778076_BIND_NESTED_DEFAULT_PARAMS Chris@16: # undef AUX778076_BIND_N_SPEC_PARAMS Chris@16: # undef AUX778076_BIND_N_PARAMS Chris@16: # undef AUX778076_BIND_DEFAULT_PARAMS Chris@16: # undef AUX778076_BIND_PARAMS Chris@16: # undef AUX778076_DMC_PARAM Chris@16: # undef AUX778076_APPLY Chris@16: Chris@16: }} Chris@16: Chris@16: #endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS Chris@16: #endif // BOOST_MPL_BIND_HPP_INCLUDED Chris@16: Chris@16: ///// iteration, depth == 1 Chris@16: Chris@16: // For gcc 4.4 compatability, we must include the Chris@16: // BOOST_PP_ITERATION_DEPTH test inside an #else clause. Chris@16: #else // BOOST_PP_IS_ITERATING Chris@16: #if BOOST_PP_ITERATION_DEPTH() == 1 Chris@16: Chris@16: # define i_ BOOST_PP_FRAME_ITERATION(1) Chris@16: Chris@16: #if defined(AUX778076_SPEC_NAME) Chris@16: Chris@16: // lazy metafunction specialization Chris@16: template< template< BOOST_MPL_PP_PARAMS(i_, typename T) > class F, typename Tag > Chris@16: struct BOOST_PP_CAT(quote,i_); Chris@16: Chris@16: template< BOOST_MPL_PP_PARAMS(i_, typename T) > struct AUX778076_SPEC_NAME; Chris@16: Chris@16: template< Chris@16: typename Tag AUX778076_BIND_N_PARAMS(i_, typename T) Chris@16: > Chris@16: struct BOOST_PP_CAT(bind,i_)< Chris@16: BOOST_PP_CAT(quote,i_) Chris@16: AUX778076_BIND_N_PARAMS(i_,T) Chris@16: > Chris@16: { Chris@16: template< Chris@16: AUX778076_BIND_NESTED_DEFAULT_PARAMS(typename U, na) Chris@16: > Chris@16: struct apply Chris@16: { Chris@16: private: Chris@16: typedef mpl::arg<1> n1; Chris@16: # define BOOST_PP_ITERATION_PARAMS_2 (3,(1, i_, )) Chris@16: # include BOOST_PP_ITERATE() Chris@16: Chris@16: typedef typename AUX778076_SPEC_NAME< Chris@16: typename t1::type Chris@16: , BOOST_MPL_PP_EXT_PARAMS(2, BOOST_PP_INC(i_), t) Chris@16: >::type f_; Chris@16: Chris@16: public: Chris@16: typedef typename f_::type type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: #undef AUX778076_SPEC_NAME Chris@16: Chris@16: #else // AUX778076_SPEC_NAME Chris@16: Chris@16: template< Chris@16: typename F AUX778076_BIND_N_PARAMS(i_, typename T) AUX778076_DMC_PARAM() Chris@16: > Chris@16: struct BOOST_PP_CAT(bind,i_) Chris@16: { Chris@16: template< Chris@16: AUX778076_BIND_NESTED_DEFAULT_PARAMS(typename U, na) Chris@16: > Chris@16: struct apply Chris@16: { Chris@16: private: Chris@16: # if !defined(BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT) Chris@16: Chris@16: typedef aux::replace_unnamed_arg< F,mpl::arg<1> > r0; Chris@16: typedef typename r0::type a0; Chris@16: typedef typename r0::next n1; Chris@16: typedef typename aux::resolve_bind_arg::type f_; Chris@16: /// Chris@16: # else Chris@16: typedef typename aux::resolve_bind_arg::type f_; Chris@16: Chris@16: # endif // BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT Chris@16: Chris@16: # if i_ > 0 Chris@16: # define BOOST_PP_ITERATION_PARAMS_2 (3,(1, i_, )) Chris@16: # include BOOST_PP_ITERATE() Chris@16: # endif Chris@16: Chris@16: public: Chris@16: Chris@16: # define AUX778076_ARG(unused, i_, t) \ Chris@16: BOOST_PP_COMMA_IF(i_) \ Chris@16: typename BOOST_PP_CAT(t,BOOST_PP_INC(i_))::type \ Chris@16: /**/ Chris@16: Chris@16: typedef typename BOOST_PP_CAT(apply_wrap,i_)< Chris@16: f_ Chris@16: BOOST_PP_COMMA_IF(i_) BOOST_MPL_PP_REPEAT(i_, AUX778076_ARG, t) Chris@16: >::type type; Chris@16: Chris@16: # undef AUX778076_ARG Chris@16: }; Chris@16: }; Chris@16: Chris@16: namespace aux { Chris@16: Chris@16: #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) Chris@16: Chris@16: template< Chris@16: typename F AUX778076_BIND_N_PARAMS(i_, typename T), AUX778076_BIND_PARAMS(typename U) Chris@16: > Chris@16: struct resolve_bind_arg< Chris@16: BOOST_PP_CAT(bind,i_),AUX778076_BIND_PARAMS(U) Chris@16: > Chris@16: { Chris@16: typedef BOOST_PP_CAT(bind,i_) f_; Chris@16: typedef typename AUX778076_APPLY::type type; Chris@16: }; Chris@16: Chris@16: #else Chris@16: Chris@16: template< Chris@16: typename F AUX778076_BIND_N_PARAMS(i_, typename T) Chris@16: > Chris@16: aux::yes_tag Chris@16: is_bind_helper(BOOST_PP_CAT(bind,i_)*); Chris@16: Chris@16: #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Chris@16: Chris@16: } // namespace aux Chris@16: Chris@16: BOOST_MPL_AUX_ARITY_SPEC(BOOST_PP_INC(i_), BOOST_PP_CAT(bind,i_)) Chris@16: BOOST_MPL_AUX_TEMPLATE_ARITY_SPEC(BOOST_PP_INC(i_), BOOST_PP_CAT(bind,i_)) Chris@16: Chris@16: # if !defined(BOOST_MPL_CFG_NO_BIND_TEMPLATE) Chris@16: # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) Chris@16: Chris@16: #if i_ == BOOST_MPL_LIMIT_METAFUNCTION_ARITY Chris@16: /// primary template (not a specialization!) Chris@16: template< Chris@16: typename F AUX778076_BIND_N_PARAMS(i_, typename T) AUX778076_DMC_PARAM() Chris@16: > Chris@16: struct bind Chris@16: : BOOST_PP_CAT(bind,i_) Chris@16: { Chris@16: }; Chris@16: #else Chris@16: template< Chris@16: typename F AUX778076_BIND_N_PARAMS(i_, typename T) AUX778076_DMC_PARAM() Chris@16: > Chris@16: struct bind< F AUX778076_BIND_N_SPEC_PARAMS(i_, T, na) > Chris@16: : BOOST_PP_CAT(bind,i_) Chris@16: { Chris@16: }; Chris@16: #endif Chris@16: Chris@16: # else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Chris@16: Chris@16: namespace aux { Chris@16: Chris@16: template<> Chris@16: struct bind_chooser Chris@16: { Chris@16: template< Chris@16: typename F, AUX778076_BIND_PARAMS(typename T) Chris@16: > Chris@16: struct result_ Chris@16: { Chris@16: typedef BOOST_PP_CAT(bind,i_)< F AUX778076_BIND_N_PARAMS(i_,T) > type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: } // namespace aux Chris@16: Chris@16: # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Chris@16: # endif // BOOST_MPL_CFG_NO_BIND_TEMPLATE Chris@16: Chris@16: #endif // AUX778076_SPEC_NAME Chris@16: Chris@16: # undef i_ Chris@16: Chris@16: ///// iteration, depth == 2 Chris@16: Chris@16: #elif BOOST_PP_ITERATION_DEPTH() == 2 Chris@16: Chris@16: # define j_ BOOST_PP_FRAME_ITERATION(2) Chris@16: # if !defined(BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT) Chris@16: Chris@16: typedef aux::replace_unnamed_arg< BOOST_PP_CAT(T,j_),BOOST_PP_CAT(n,j_) > BOOST_PP_CAT(r,j_); Chris@16: typedef typename BOOST_PP_CAT(r,j_)::type BOOST_PP_CAT(a,j_); Chris@16: typedef typename BOOST_PP_CAT(r,j_)::next BOOST_PP_CAT(n,BOOST_PP_INC(j_)); Chris@16: typedef aux::resolve_bind_arg BOOST_PP_CAT(t,j_); Chris@16: /// Chris@16: # else Chris@16: typedef aux::resolve_bind_arg< BOOST_PP_CAT(T,j_),AUX778076_BIND_PARAMS(U)> BOOST_PP_CAT(t,j_); Chris@16: Chris@16: # endif Chris@16: # undef j_ Chris@16: Chris@16: #endif // BOOST_PP_ITERATION_DEPTH() Chris@16: #endif // BOOST_PP_IS_ITERATING