]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.TypeErasure library |
2 | // | |
3 | // Copyright 2011 Steven Watanabe | |
4 | // | |
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) | |
8 | // | |
9 | // $Id$ | |
10 | ||
11 | #if !defined(BOOST_PP_IS_ITERATING) | |
12 | ||
13 | #ifndef BOOST_TYPE_ERASURE_DETAIL_REBIND_PLACEHOLDERS_HPP_INCLUDED | |
14 | #define BOOST_TYPE_ERASURE_DETAIL_REBIND_PLACEHOLDERS_HPP_INCLUDED | |
15 | ||
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> | |
30 | ||
31 | namespace boost { | |
32 | namespace type_erasure { | |
33 | ||
34 | template<class F> | |
35 | struct deduced; | |
36 | ||
37 | namespace detail { | |
38 | ||
39 | template<class T, class Bindings> | |
40 | struct rebind_placeholders | |
41 | { | |
42 | typedef void type; | |
43 | }; | |
44 | ||
45 | template<class T> | |
46 | struct identity | |
47 | { | |
48 | typedef T type; | |
49 | }; | |
50 | ||
51 | template<class T, class Bindings> | |
52 | struct rebind_placeholders_in_argument | |
53 | { | |
54 | BOOST_MPL_ASSERT((boost::mpl::or_< | |
55 | ::boost::mpl::not_< ::boost::type_erasure::is_placeholder<T> >, | |
56 | ::boost::mpl::has_key<Bindings, T> | |
57 | >)); | |
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> | |
62 | >::type type; | |
63 | }; | |
64 | ||
65 | template<class T, class Bindings> | |
66 | struct rebind_placeholders_in_argument<T&, Bindings> | |
67 | { | |
68 | typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument< | |
69 | T, | |
70 | Bindings | |
71 | >::type& type; | |
72 | }; | |
73 | ||
74 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES | |
75 | ||
76 | template<class T, class Bindings> | |
77 | struct rebind_placeholders_in_argument<T&&, Bindings> | |
78 | { | |
79 | typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument< | |
80 | T, | |
81 | Bindings | |
82 | >::type&& type; | |
83 | }; | |
84 | ||
85 | #endif | |
86 | ||
87 | template<class T, class Bindings> | |
88 | struct rebind_placeholders_in_argument<const T, Bindings> | |
89 | { | |
90 | typedef const typename ::boost::type_erasure::detail::rebind_placeholders_in_argument< | |
91 | T, | |
92 | Bindings | |
93 | >::type type; | |
94 | }; | |
95 | ||
96 | template<class F, class Bindings> | |
97 | struct rebind_placeholders_in_deduced | |
98 | { | |
99 | typedef typename ::boost::type_erasure::deduced< | |
100 | typename ::boost::type_erasure::detail::rebind_placeholders<F, Bindings>::type | |
101 | >::type type; | |
102 | }; | |
103 | ||
104 | template<class F, class Bindings> | |
105 | struct rebind_placeholders_in_argument< | |
106 | ::boost::type_erasure::deduced<F>, | |
107 | Bindings | |
108 | > | |
109 | { | |
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< | |
114 | F, | |
115 | Bindings | |
116 | > | |
117 | >::type type; | |
118 | }; | |
119 | ||
120 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
121 | ||
122 | template<template<class...> class T, class... U, class Bindings> | |
123 | struct rebind_placeholders<T<U...>, Bindings> | |
124 | { | |
125 | typedef T<typename rebind_placeholders_in_argument<U, Bindings>::type...> type; | |
126 | }; | |
127 | ||
128 | template<class R, class... T, class Bindings> | |
129 | struct rebind_placeholders_in_argument<R(T...), Bindings> | |
130 | { | |
131 | typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument< | |
132 | R, | |
133 | Bindings | |
134 | >::type type(typename rebind_placeholders_in_argument<T, Bindings>::type...); | |
135 | }; | |
136 | ||
137 | #else | |
138 | ||
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() | |
142 | ||
143 | #endif | |
144 | ||
145 | } | |
146 | } | |
147 | } | |
148 | ||
149 | #endif | |
150 | ||
151 | #else | |
152 | ||
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 | |
156 | ||
157 | #if N != 0 | |
158 | ||
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> | |
162 | { | |
163 | typedef T<BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_REBIND, T)> type; | |
164 | }; | |
165 | ||
166 | #endif | |
167 | ||
168 | template<class R | |
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> | |
171 | { | |
172 | typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument< | |
173 | R, | |
174 | Bindings | |
175 | >::type type(BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_REBIND, T)); | |
176 | }; | |
177 | ||
178 | #undef BOOST_TYPE_ERASURE_REBIND | |
179 | #undef N | |
180 | ||
181 | #endif |