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