1 // Boost.TypeErasure library
3 // Copyright 2011 Steven Watanabe
5 // Distributed under the Boost Software License Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
11 #if !defined(BOOST_PP_IS_ITERATING)
13 #ifndef BOOST_TYPE_ERASURE_DETAIL_REBIND_PLACEHOLDERS_HPP_INCLUDED
14 #define BOOST_TYPE_ERASURE_DETAIL_REBIND_PLACEHOLDERS_HPP_INCLUDED
16 #include <boost/mpl/eval_if.hpp>
17 #include <boost/mpl/identity.hpp>
18 #include <boost/mpl/at.hpp>
19 #include <boost/mpl/has_key.hpp>
20 #include <boost/mpl/not.hpp>
21 #include <boost/mpl/or.hpp>
22 #include <boost/mpl/assert.hpp>
23 #include <boost/preprocessor/cat.hpp>
24 #include <boost/preprocessor/iteration/iterate.hpp>
25 #include <boost/preprocessor/repetition/enum.hpp>
26 #include <boost/preprocessor/repetition/enum_params.hpp>
27 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
28 #include <boost/type_erasure/config.hpp>
29 #include <boost/type_erasure/is_placeholder.hpp>
32 namespace type_erasure {
39 template<class T, class Bindings>
40 struct rebind_placeholders
51 template<class T, class Bindings>
52 struct rebind_placeholders_in_argument
54 BOOST_MPL_ASSERT((boost::mpl::or_<
55 ::boost::mpl::not_< ::boost::type_erasure::is_placeholder<T> >,
56 ::boost::mpl::has_key<Bindings, T>
58 typedef typename ::boost::mpl::eval_if<
59 ::boost::type_erasure::is_placeholder<T>,
60 ::boost::mpl::at<Bindings, T>,
61 ::boost::type_erasure::detail::identity<T>
65 template<class T, class Bindings>
66 struct rebind_placeholders_in_argument<T&, Bindings>
68 typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
74 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
76 template<class T, class Bindings>
77 struct rebind_placeholders_in_argument<T&&, Bindings>
79 typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
87 template<class T, class Bindings>
88 struct rebind_placeholders_in_argument<const T, Bindings>
90 typedef const typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
96 template<class F, class Bindings>
97 struct rebind_placeholders_in_deduced
99 typedef typename ::boost::type_erasure::deduced<
100 typename ::boost::type_erasure::detail::rebind_placeholders<F, Bindings>::type
104 template<class F, class Bindings>
105 struct rebind_placeholders_in_argument<
106 ::boost::type_erasure::deduced<F>,
110 typedef typename ::boost::mpl::eval_if<
111 ::boost::mpl::has_key<Bindings, ::boost::type_erasure::deduced<F> >,
112 ::boost::mpl::at<Bindings, ::boost::type_erasure::deduced<F> >,
113 ::boost::type_erasure::detail::rebind_placeholders_in_deduced<
120 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
122 template<template<class...> class T, class... U, class Bindings>
123 struct rebind_placeholders<T<U...>, Bindings>
125 typedef T<typename rebind_placeholders_in_argument<U, Bindings>::type...> type;
128 template<class R, class... T, class Bindings>
129 struct rebind_placeholders_in_argument<R(T...), Bindings>
131 typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
134 >::type type(typename rebind_placeholders_in_argument<T, Bindings>::type...);
139 #define BOOST_PP_FILENAME_1 <boost/type_erasure/detail/rebind_placeholders.hpp>
140 #define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPE_ERASURE_MAX_ARITY)
141 #include BOOST_PP_ITERATE()
153 #define N BOOST_PP_ITERATION()
154 #define BOOST_TYPE_ERASURE_REBIND(z, n, data) \
155 typename rebind_placeholders_in_argument<BOOST_PP_CAT(data, n), Bindings>::type
159 template<template<BOOST_PP_ENUM_PARAMS(N, class T)> class T,
160 BOOST_PP_ENUM_PARAMS(N, class T), class Bindings>
161 struct rebind_placeholders<T<BOOST_PP_ENUM_PARAMS(N, T)>, Bindings>
163 typedef T<BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_REBIND, T)> type;
169 BOOST_PP_ENUM_TRAILING_PARAMS(N, class T), class Bindings>
170 struct rebind_placeholders_in_argument<R(BOOST_PP_ENUM_PARAMS(N, T)), Bindings>
172 typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
175 >::type type(BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_REBIND, T));
178 #undef BOOST_TYPE_ERASURE_REBIND