2 #if !defined(BOOST_PP_IS_ITERATING)
6 #ifndef BOOST_MPL_BIND_HPP_INCLUDED
7 #define BOOST_MPL_BIND_HPP_INCLUDED
9 // Copyright Peter Dimov 2001
10 // Copyright Aleksey Gurtovoy 2001-2004
12 // Distributed under the Boost Software License, Version 1.0.
13 // (See accompanying file LICENSE_1_0.txt or copy at
14 // http://www.boost.org/LICENSE_1_0.txt)
16 // See http://www.boost.org/libs/mpl for documentation.
19 // $Date: 2004-10-26 10:51:08 -0400 (Tue, 26 Oct 2004) $
22 #if !defined(BOOST_MPL_PREPROCESSING_MODE)
23 # include <boost/mpl/bind_fwd.hpp>
24 # include <boost/mpl/placeholders.hpp>
25 # include <boost/mpl/next.hpp>
26 # include <boost/mpl/protect.hpp>
27 # include <boost/mpl/apply_wrap.hpp>
28 # include <boost/mpl/limits/arity.hpp>
29 # include <boost/mpl/aux_/na.hpp>
30 # include <boost/mpl/aux_/arity_spec.hpp>
31 # include <boost/mpl/aux_/type_wrapper.hpp>
32 # include <boost/mpl/aux_/yes_no.hpp>
33 # if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
34 # include <boost/type_traits/is_reference.hpp>
38 #include <boost/mpl/aux_/config/bind.hpp>
39 #include <boost/mpl/aux_/config/static_constant.hpp>
40 #include <boost/mpl/aux_/config/use_preprocessed.hpp>
42 #if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
43 && !defined(BOOST_MPL_PREPROCESSING_MODE)
45 # if defined(BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT)
46 # define BOOST_MPL_PREPROCESSED_HEADER basic_bind.hpp
48 # define BOOST_MPL_PREPROCESSED_HEADER bind.hpp
50 # include <boost/mpl/aux_/include_preprocessed.hpp>
54 # include <boost/mpl/aux_/preprocessor/params.hpp>
55 # include <boost/mpl/aux_/preprocessor/default_params.hpp>
56 # include <boost/mpl/aux_/preprocessor/def_params_tail.hpp>
57 # include <boost/mpl/aux_/preprocessor/partial_spec_params.hpp>
58 # include <boost/mpl/aux_/preprocessor/ext_params.hpp>
59 # include <boost/mpl/aux_/preprocessor/repeat.hpp>
60 # include <boost/mpl/aux_/preprocessor/enum.hpp>
61 # include <boost/mpl/aux_/preprocessor/add.hpp>
62 # include <boost/mpl/aux_/config/dmc_ambiguous_ctps.hpp>
63 # include <boost/mpl/aux_/config/ctps.hpp>
64 # include <boost/mpl/aux_/config/ttp.hpp>
65 # include <boost/mpl/aux_/config/dtp.hpp>
66 # include <boost/mpl/aux_/nttp_decl.hpp>
68 # include <boost/preprocessor/iterate.hpp>
69 # include <boost/preprocessor/comma_if.hpp>
70 # include <boost/preprocessor/cat.hpp>
71 # include <boost/preprocessor/inc.hpp>
73 namespace boost { namespace mpl {
75 // local macros, #undef-ined at the end of the header
76 # define AUX778076_APPLY \
77 BOOST_PP_CAT(apply_wrap,BOOST_MPL_LIMIT_METAFUNCTION_ARITY) \
80 # if defined(BOOST_MPL_CFG_DMC_AMBIGUOUS_CTPS)
81 # define AUX778076_DMC_PARAM() , int dummy_
83 # define AUX778076_DMC_PARAM()
86 # define AUX778076_BIND_PARAMS(param) \
87 BOOST_MPL_PP_PARAMS( \
88 BOOST_MPL_LIMIT_METAFUNCTION_ARITY \
93 # define AUX778076_BIND_DEFAULT_PARAMS(param, value) \
94 BOOST_MPL_PP_DEFAULT_PARAMS( \
95 BOOST_MPL_LIMIT_METAFUNCTION_ARITY \
101 # define AUX778076_BIND_N_PARAMS(n, param) \
102 BOOST_PP_COMMA_IF(n) BOOST_MPL_PP_PARAMS(n, param) \
105 # define AUX778076_BIND_N_SPEC_PARAMS(n, param, def) \
106 BOOST_PP_COMMA_IF(n) \
107 BOOST_MPL_PP_PARTIAL_SPEC_PARAMS(n, param, def) \
110 #if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES)
111 # define AUX778076_BIND_NESTED_DEFAULT_PARAMS(param, value) \
112 AUX778076_BIND_DEFAULT_PARAMS(param, value) \
115 # define AUX778076_BIND_NESTED_DEFAULT_PARAMS(param, value) \
116 AUX778076_BIND_PARAMS(param) \
122 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
125 typename T, AUX778076_BIND_PARAMS(typename U)
127 struct resolve_bind_arg
132 # if !defined(BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT)
138 struct replace_unnamed_arg
147 struct replace_unnamed_arg< arg<-1>,Arg >
149 typedef typename Arg::next next;
153 # endif // BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT
156 BOOST_MPL_AUX_NTTP_DECL(int, N), AUX778076_BIND_PARAMS(typename U)
158 struct resolve_bind_arg< arg<N>,AUX778076_BIND_PARAMS(U) >
160 typedef typename AUX778076_APPLY<mpl::arg<N>, AUX778076_BIND_PARAMS(U)>::type type;
163 #if !defined(BOOST_MPL_CFG_NO_BIND_TEMPLATE)
165 typename F, AUX778076_BIND_PARAMS(typename T), AUX778076_BIND_PARAMS(typename U)
167 struct resolve_bind_arg< bind<F,AUX778076_BIND_PARAMS(T)>,AUX778076_BIND_PARAMS(U) >
169 typedef bind<F,AUX778076_BIND_PARAMS(T)> f_;
170 typedef typename AUX778076_APPLY<f_, AUX778076_BIND_PARAMS(U)>::type type;
174 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
176 // agurt, 15/jan/02: it's not a intended to be used as a function class, and
177 // MSVC6.5 has problems with 'apply' name here (the code compiles, but doesn't
178 // work), so I went with the 'result_' here, and in all other similar cases
180 struct resolve_arg_impl
182 template< typename T, AUX778076_BIND_PARAMS(typename U) > struct result_
189 struct resolve_arg_impl<true>
191 template< typename T, AUX778076_BIND_PARAMS(typename U) > struct result_
193 typedef typename AUX778076_APPLY<
195 , AUX778076_BIND_PARAMS(U)
200 // for 'resolve_bind_arg'
201 template< typename T > struct is_bind_template;
204 typename T, AUX778076_BIND_PARAMS(typename U)
206 struct resolve_bind_arg
207 : resolve_arg_impl< is_bind_template<T>::value >
208 ::template result_< T,AUX778076_BIND_PARAMS(U) >
212 # if !defined(BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT)
214 template< typename T >
215 struct replace_unnamed_arg_impl
217 template< typename Arg > struct result_
225 struct replace_unnamed_arg_impl< arg<-1> >
227 template< typename Arg > struct result_
229 typedef typename next<Arg>::type next;
234 template< typename T, typename Arg >
235 struct replace_unnamed_arg
236 : replace_unnamed_arg_impl<T>::template result_<Arg>
240 # endif // BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT
242 // agurt, 10/mar/02: the forward declaration has to appear before any of
243 // 'is_bind_helper' overloads, otherwise MSVC6.5 issues an ICE on it
244 template< BOOST_MPL_AUX_NTTP_DECL(int, arity_) > struct bind_chooser;
246 aux::no_tag is_bind_helper(...);
247 template< typename T > aux::no_tag is_bind_helper(protect<T>*);
249 // overload for "main" form
250 // agurt, 15/mar/02: MSVC 6.5 fails to properly resolve the overload
251 // in case if we use 'aux::type_wrapper< bind<...> >' here, and all
252 // 'bind' instantiations form a complete type anyway
253 #if !defined(BOOST_MPL_CFG_NO_BIND_TEMPLATE)
255 typename F, AUX778076_BIND_PARAMS(typename T)
257 aux::yes_tag is_bind_helper(bind<F,AUX778076_BIND_PARAMS(T)>*);
260 template< BOOST_MPL_AUX_NTTP_DECL(int, N) >
261 aux::yes_tag is_bind_helper(arg<N>*);
263 template< bool is_ref_ = true >
264 struct is_bind_template_impl
266 template< typename T > struct result_
268 BOOST_STATIC_CONSTANT(bool, value = false);
273 struct is_bind_template_impl<false>
275 template< typename T > struct result_
277 BOOST_STATIC_CONSTANT(bool, value =
278 sizeof(aux::is_bind_helper(static_cast<T*>(0)))
279 == sizeof(aux::yes_tag)
284 template< typename T > struct is_bind_template
285 : is_bind_template_impl< ::boost::detail::is_reference_impl<T>::value >
286 ::template result_<T>
290 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
295 #define BOOST_PP_ITERATION_PARAMS_1 \
296 (3,(0, BOOST_MPL_LIMIT_METAFUNCTION_ARITY, <boost/mpl/bind.hpp>))
297 #include BOOST_PP_ITERATE()
299 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
300 && !defined(BOOST_MPL_CFG_NO_TEMPLATE_TEMPLATE_PARAMETERS)
301 /// if_/eval_if specializations
302 # define AUX778076_SPEC_NAME if_
303 # define BOOST_PP_ITERATION_PARAMS_1 (3,(3, 3, <boost/mpl/bind.hpp>))
304 # include BOOST_PP_ITERATE()
306 #if !defined(BOOST_MPL_CFG_DMC_AMBIGUOUS_CTPS)
307 # define AUX778076_SPEC_NAME eval_if
308 # define BOOST_PP_ITERATION_PARAMS_1 (3,(3, 3, <boost/mpl/bind.hpp>))
309 # include BOOST_PP_ITERATE()
313 // real C++ version is already taken care of
314 #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
315 && !defined(BOOST_MPL_CFG_NO_BIND_TEMPLATE)
319 #define AUX778076_COUNT_ARGS_PREFIX bind
320 #define AUX778076_COUNT_ARGS_DEFAULT na
321 #define AUX778076_COUNT_ARGS_ARITY BOOST_MPL_LIMIT_METAFUNCTION_ARITY
322 #include <boost/mpl/aux_/count_args.hpp>
327 typename F, AUX778076_BIND_PARAMS(typename T) AUX778076_DMC_PARAM()
331 aux::bind_count_args<AUX778076_BIND_PARAMS(T)>::value
332 >::template result_< F,AUX778076_BIND_PARAMS(T) >::type
336 BOOST_MPL_AUX_ARITY_SPEC(
337 BOOST_PP_INC(BOOST_MPL_LIMIT_METAFUNCTION_ARITY)
341 BOOST_MPL_AUX_TEMPLATE_ARITY_SPEC(
342 BOOST_PP_INC(BOOST_MPL_LIMIT_METAFUNCTION_ARITY)
347 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
349 # undef AUX778076_BIND_NESTED_DEFAULT_PARAMS
350 # undef AUX778076_BIND_N_SPEC_PARAMS
351 # undef AUX778076_BIND_N_PARAMS
352 # undef AUX778076_BIND_DEFAULT_PARAMS
353 # undef AUX778076_BIND_PARAMS
354 # undef AUX778076_DMC_PARAM
355 # undef AUX778076_APPLY
359 #endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
360 #endif // BOOST_MPL_BIND_HPP_INCLUDED
362 ///// iteration, depth == 1
364 #elif BOOST_PP_ITERATION_DEPTH() == 1
366 # define i_ BOOST_PP_FRAME_ITERATION(1)
368 #if defined(AUX778076_SPEC_NAME)
370 // lazy metafunction specialization
371 template< template< BOOST_MPL_PP_PARAMS(i_, typename T) > class F, typename Tag >
372 struct BOOST_PP_CAT(quote,i_);
374 template< BOOST_MPL_PP_PARAMS(i_, typename T) > struct AUX778076_SPEC_NAME;
377 typename Tag AUX778076_BIND_N_PARAMS(i_, typename T)
379 struct BOOST_PP_CAT(bind,i_)<
380 BOOST_PP_CAT(quote,i_)<AUX778076_SPEC_NAME,Tag>
381 AUX778076_BIND_N_PARAMS(i_,T)
385 AUX778076_BIND_NESTED_DEFAULT_PARAMS(typename U, na)
390 typedef mpl::arg<1> n1;
391 # define BOOST_PP_ITERATION_PARAMS_2 (3,(1, i_, <boost/mpl/bind.hpp>))
392 # include BOOST_PP_ITERATE()
394 typedef typename AUX778076_SPEC_NAME<
396 , BOOST_MPL_PP_EXT_PARAMS(2, BOOST_PP_INC(i_), t)
400 typedef typename f_::type type;
404 #undef AUX778076_SPEC_NAME
406 #else // AUX778076_SPEC_NAME
409 typename F AUX778076_BIND_N_PARAMS(i_, typename T) AUX778076_DMC_PARAM()
411 struct BOOST_PP_CAT(bind,i_)
414 AUX778076_BIND_NESTED_DEFAULT_PARAMS(typename U, na)
419 # if !defined(BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT)
421 typedef aux::replace_unnamed_arg< F,mpl::arg<1> > r0;
422 typedef typename r0::type a0;
423 typedef typename r0::next n1;
424 typedef typename aux::resolve_bind_arg<a0,AUX778076_BIND_PARAMS(U)>::type f_;
427 typedef typename aux::resolve_bind_arg<F,AUX778076_BIND_PARAMS(U)>::type f_;
429 # endif // BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT
432 # define BOOST_PP_ITERATION_PARAMS_2 (3,(1, i_, <boost/mpl/bind.hpp>))
433 # include BOOST_PP_ITERATE()
438 # define AUX778076_ARG(unused, i_, t) \
439 BOOST_PP_COMMA_IF(i_) \
440 typename BOOST_PP_CAT(t,BOOST_PP_INC(i_))::type \
443 typedef typename BOOST_PP_CAT(apply_wrap,i_)<
445 BOOST_PP_COMMA_IF(i_) BOOST_MPL_PP_REPEAT(i_, AUX778076_ARG, t)
448 # undef AUX778076_ARG
454 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
457 typename F AUX778076_BIND_N_PARAMS(i_, typename T), AUX778076_BIND_PARAMS(typename U)
459 struct resolve_bind_arg<
460 BOOST_PP_CAT(bind,i_)<F AUX778076_BIND_N_PARAMS(i_,T)>,AUX778076_BIND_PARAMS(U)
463 typedef BOOST_PP_CAT(bind,i_)<F AUX778076_BIND_N_PARAMS(i_,T)> f_;
464 typedef typename AUX778076_APPLY<f_, AUX778076_BIND_PARAMS(U)>::type type;
470 typename F AUX778076_BIND_N_PARAMS(i_, typename T)
473 is_bind_helper(BOOST_PP_CAT(bind,i_)<F AUX778076_BIND_N_PARAMS(i_,T)>*);
475 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
479 BOOST_MPL_AUX_ARITY_SPEC(BOOST_PP_INC(i_), BOOST_PP_CAT(bind,i_))
480 BOOST_MPL_AUX_TEMPLATE_ARITY_SPEC(BOOST_PP_INC(i_), BOOST_PP_CAT(bind,i_))
482 # if !defined(BOOST_MPL_CFG_NO_BIND_TEMPLATE)
483 # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
485 #if i_ == BOOST_MPL_LIMIT_METAFUNCTION_ARITY
486 /// primary template (not a specialization!)
488 typename F AUX778076_BIND_N_PARAMS(i_, typename T) AUX778076_DMC_PARAM()
491 : BOOST_PP_CAT(bind,i_)<F AUX778076_BIND_N_PARAMS(i_,T) >
496 typename F AUX778076_BIND_N_PARAMS(i_, typename T) AUX778076_DMC_PARAM()
498 struct bind< F AUX778076_BIND_N_SPEC_PARAMS(i_, T, na) >
499 : BOOST_PP_CAT(bind,i_)<F AUX778076_BIND_N_PARAMS(i_,T) >
504 # else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
509 struct bind_chooser<i_>
512 typename F, AUX778076_BIND_PARAMS(typename T)
516 typedef BOOST_PP_CAT(bind,i_)< F AUX778076_BIND_N_PARAMS(i_,T) > type;
522 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
523 # endif // BOOST_MPL_CFG_NO_BIND_TEMPLATE
525 #endif // AUX778076_SPEC_NAME
529 ///// iteration, depth == 2
531 #elif BOOST_PP_ITERATION_DEPTH() == 2
533 # define j_ BOOST_PP_FRAME_ITERATION(2)
534 # if !defined(BOOST_MPL_CFG_NO_UNNAMED_PLACEHOLDER_SUPPORT)
536 typedef aux::replace_unnamed_arg< BOOST_PP_CAT(T,j_),BOOST_PP_CAT(n,j_) > BOOST_PP_CAT(r,j_);
537 typedef typename BOOST_PP_CAT(r,j_)::type BOOST_PP_CAT(a,j_);
538 typedef typename BOOST_PP_CAT(r,j_)::next BOOST_PP_CAT(n,BOOST_PP_INC(j_));
539 typedef aux::resolve_bind_arg<BOOST_PP_CAT(a,j_), AUX778076_BIND_PARAMS(U)> BOOST_PP_CAT(t,j_);
542 typedef aux::resolve_bind_arg< BOOST_PP_CAT(T,j_),AUX778076_BIND_PARAMS(U)> BOOST_PP_CAT(t,j_);
547 #endif // BOOST_PP_IS_ITERATING