]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_erasure/include/boost/type_erasure/detail/adapt_to_vtable.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / type_erasure / include / boost / type_erasure / detail / adapt_to_vtable.hpp
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_ADAPT_TO_VTABLE_HPP_INCLUDED
14 #define BOOST_TYPE_ERASURE_DETAIL_ADAPT_TO_VTABLE_HPP_INCLUDED
15
16 #include <boost/detail/workaround.hpp>
17 #include <boost/utility/addressof.hpp>
18 #include <boost/mpl/if.hpp>
19 #include <boost/mpl/eval_if.hpp>
20 #include <boost/mpl/has_xxx.hpp>
21 #include <boost/type_traits/function_traits.hpp>
22 #include <boost/type_traits/remove_cv.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/preprocessor/repetition/enum_binary_params.hpp>
29 #include <boost/type_erasure/detail/get_signature.hpp>
30 #include <boost/type_erasure/detail/storage.hpp>
31 #include <boost/type_erasure/is_placeholder.hpp>
32 #include <boost/type_erasure/config.hpp>
33
34 namespace boost {
35 namespace type_erasure {
36
37 namespace detail {
38
39 template<class T, class Out>
40 struct get_placeholders;
41
42 template<class T, class Bindings>
43 struct rebind_placeholders;
44
45 template<class T, class Bindings>
46 struct rebind_placeholders_in_argument;
47
48 template<class PrimitiveConcept, class Sig>
49 struct vtable_adapter;
50
51 template<class PrimitiveConcept, class Sig, class Bindings>
52 struct rebind_placeholders<vtable_adapter<PrimitiveConcept, Sig>, Bindings>
53 {
54 typedef vtable_adapter<
55 typename rebind_placeholders<PrimitiveConcept, Bindings>::type,
56 typename rebind_placeholders_in_argument<Sig, Bindings>::type
57 > type;
58 };
59
60 template<class PrimitiveConcept, class Sig, class Out>
61 struct get_placeholders<vtable_adapter<PrimitiveConcept, Sig>, Out>
62 {
63 typedef typename get_placeholders<PrimitiveConcept, Out>::type type;
64 };
65
66 template<class T>
67 struct replace_param_for_vtable
68 {
69 typedef typename ::boost::mpl::if_<
70 ::boost::type_erasure::is_placeholder<typename ::boost::remove_cv<T>::type>,
71 const ::boost::type_erasure::detail::storage&,
72 T
73 >::type type;
74 };
75
76 template<class T>
77 struct replace_param_for_vtable<T&>
78 {
79 typedef typename ::boost::mpl::if_<
80 ::boost::type_erasure::is_placeholder<typename ::boost::remove_cv<T>::type>,
81 ::boost::type_erasure::detail::storage&,
82 T&
83 >::type type;
84 };
85
86 template<class T>
87 struct replace_param_for_vtable<const T&>
88 {
89 typedef typename ::boost::mpl::if_<
90 ::boost::type_erasure::is_placeholder<typename ::boost::remove_cv<T>::type>,
91 const ::boost::type_erasure::detail::storage&,
92 const T&
93 >::type type;
94 };
95
96 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
97
98 template<class T>
99 struct replace_param_for_vtable<T&&>
100 {
101 typedef typename ::boost::mpl::if_<
102 ::boost::type_erasure::is_placeholder<typename ::boost::remove_cv<T>::type>,
103 ::boost::type_erasure::detail::storage&&,
104 T&&
105 >::type type;
106 };
107
108 #endif
109
110 template<class T>
111 struct replace_result_for_vtable
112 {
113 typedef typename ::boost::mpl::if_<
114 ::boost::type_erasure::is_placeholder<typename ::boost::remove_cv<T>::type>,
115 ::boost::type_erasure::detail::storage,
116 T
117 >::type type;
118 };
119
120 template<class T>
121 struct replace_result_for_vtable<T&>
122 {
123 typedef typename ::boost::mpl::if_<
124 ::boost::type_erasure::is_placeholder<typename ::boost::remove_cv<T>::type>,
125 ::boost::type_erasure::detail::storage&,
126 T&
127 >::type type;
128 };
129
130 template<class T>
131 struct replace_result_for_vtable<const T&>
132 {
133 typedef typename ::boost::mpl::if_<
134 ::boost::type_erasure::is_placeholder<typename ::boost::remove_cv<T>::type>,
135 ::boost::type_erasure::detail::storage&,
136 const T&
137 >::type type;
138 };
139
140 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
141
142 template<class T>
143 struct replace_result_for_vtable<T&&>
144 {
145 typedef typename ::boost::mpl::if_<
146 ::boost::type_erasure::is_placeholder<typename ::boost::remove_cv<T>::type>,
147 ::boost::type_erasure::detail::storage&&,
148 T&&
149 >::type type;
150 };
151
152 #endif
153
154 template<class Sig>
155 struct get_vtable_signature;
156
157 BOOST_MPL_HAS_XXX_TRAIT_DEF(type)
158
159 template<class T>
160 struct is_internal_concept :
161 ::boost::type_erasure::detail::has_type<T>
162 {};
163
164 template<class PrimitiveConcept>
165 struct adapt_to_vtable
166 {
167 typedef ::boost::type_erasure::detail::vtable_adapter<
168 PrimitiveConcept,
169 typename ::boost::type_erasure::detail::get_vtable_signature<
170 typename ::boost::type_erasure::detail::get_signature<
171 PrimitiveConcept
172 >::type
173 >::type
174 > type;
175 };
176
177 template<class Concept>
178 struct maybe_adapt_to_vtable
179 {
180 typedef typename ::boost::mpl::eval_if<
181 ::boost::type_erasure::detail::is_internal_concept<Concept>,
182 ::boost::mpl::identity<Concept>,
183 ::boost::type_erasure::detail::adapt_to_vtable<Concept>
184 >::type type;
185 };
186
187 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
188 !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
189 !BOOST_WORKAROUND(BOOST_MSVC, == 1800)
190
191 template<class PrimitiveConcept, class Sig, class ConceptSig>
192 struct vtable_adapter_impl;
193
194 template<class PrimitiveConcept, class R, class... T, class R2, class... U>
195 struct vtable_adapter_impl<PrimitiveConcept, R(T...), R2(U...)>
196 {
197 typedef R (*type)(T...);
198 static R value(T... arg)
199 {
200 return PrimitiveConcept::apply(
201 ::boost::type_erasure::detail::extract<U>(std::forward<T>(arg))...);
202 }
203 };
204
205 template<class PrimitiveConcept, class... T, class R2, class... U>
206 struct vtable_adapter_impl<PrimitiveConcept, ::boost::type_erasure::detail::storage(T...), R2(U...)>
207 {
208 typedef ::boost::type_erasure::detail::storage (*type)(T...);
209 static ::boost::type_erasure::detail::storage value(T... arg)
210 {
211 return ::boost::type_erasure::detail::storage(
212 PrimitiveConcept::apply(::boost::type_erasure::detail::extract<U>(std::forward<T>(arg))...));
213 }
214 };
215
216 template<class PrimitiveConcept, class... T, class R2, class... U>
217 struct vtable_adapter_impl<PrimitiveConcept, ::boost::type_erasure::detail::storage&(T...), R2(U...)>
218 {
219 typedef ::boost::type_erasure::detail::storage (*type)(T...);
220 static ::boost::type_erasure::detail::storage value(T... arg)
221 {
222 ::boost::type_erasure::detail::storage result;
223 typename ::boost::remove_reference<R2>::type* p =
224 ::boost::addressof(
225 PrimitiveConcept::apply(::boost::type_erasure::detail::extract<U>(std::forward<T>(arg))...));
226 result.data = const_cast<void*>(static_cast<const void*>(p));
227 return result;
228 }
229 };
230
231 template<class PrimitiveConcept, class... T, class R2, class... U>
232 struct vtable_adapter_impl<PrimitiveConcept, ::boost::type_erasure::detail::storage&&(T...), R2(U...)>
233 {
234 typedef ::boost::type_erasure::detail::storage (*type)(T...);
235 static ::boost::type_erasure::detail::storage value(T... arg)
236 {
237 ::boost::type_erasure::detail::storage result;
238 R2 tmp = PrimitiveConcept::apply(::boost::type_erasure::detail::extract<U>(std::forward<T>(arg))...);
239 typename ::boost::remove_reference<R2>::type* p = ::boost::addressof(tmp);
240 result.data = const_cast<void*>(static_cast<const void*>(p));
241 return result;
242 }
243 };
244
245 template<class PrimitiveConcept, class Sig>
246 struct vtable_adapter
247 : vtable_adapter_impl<
248 PrimitiveConcept,
249 Sig,
250 typename ::boost::type_erasure::detail::get_signature<
251 PrimitiveConcept
252 >::type
253 >
254 {};
255
256 template<class R, class... T>
257 struct get_vtable_signature<R(T...)>
258 {
259 typedef typename ::boost::type_erasure::detail::replace_result_for_vtable<
260 R
261 >::type type(typename ::boost::type_erasure::detail::replace_param_for_vtable<T>::type...);
262 };
263
264 #else
265
266 #define BOOST_PP_FILENAME_1 <boost/type_erasure/detail/adapt_to_vtable.hpp>
267 #define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPE_ERASURE_MAX_ARITY)
268 #include BOOST_PP_ITERATE()
269
270 #endif
271
272 }
273 }
274 }
275
276 #endif
277
278 #else
279
280 #define N BOOST_PP_ITERATION()
281
282 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
283
284 #define BOOST_TYPE_ERASURE_EXTRACT(z, n, data) \
285 ::boost::type_erasure::detail::extract< \
286 typename traits:: \
287 BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)), _type) \
288 >(std::forward<BOOST_PP_CAT(T, n)>(BOOST_PP_CAT(arg, n)))
289
290 #else
291
292 #define BOOST_TYPE_ERASURE_EXTRACT(z, n, data) \
293 ::boost::type_erasure::detail::extract< \
294 typename traits:: \
295 BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)), _type) \
296 >(BOOST_PP_CAT(arg, n))
297
298 #endif
299
300 #define BOOST_TYPE_ERASURE_REPLACE_PARAM(z, n, data) \
301 typename ::boost::type_erasure::detail::replace_param_for_vtable< \
302 BOOST_PP_CAT(T, n)>::type
303
304 template<class PrimitiveConcept, class R
305 BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)>
306 struct vtable_adapter<PrimitiveConcept, R(BOOST_PP_ENUM_PARAMS(N, T))>
307 {
308 typedef R (*type)(BOOST_PP_ENUM_PARAMS(N, T));
309 static R value(BOOST_PP_ENUM_BINARY_PARAMS(N, T, arg))
310 {
311 typedef typename ::boost::function_traits<
312 typename ::boost::type_erasure::detail::get_signature<
313 PrimitiveConcept
314 >::type
315 > traits;
316 return PrimitiveConcept::apply(
317 BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_EXTRACT, ~));
318 }
319 };
320
321 template<class PrimitiveConcept
322 BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)>
323 struct vtable_adapter<PrimitiveConcept, ::boost::type_erasure::detail::storage(BOOST_PP_ENUM_PARAMS(N, T))>
324 {
325 typedef ::boost::type_erasure::detail::storage (*type)(BOOST_PP_ENUM_PARAMS(N, T));
326 static ::boost::type_erasure::detail::storage value(BOOST_PP_ENUM_BINARY_PARAMS(N, T, arg))
327 {
328 typedef typename ::boost::function_traits<
329 typename ::boost::type_erasure::detail::get_signature<
330 PrimitiveConcept
331 >::type
332 > traits;
333 return ::boost::type_erasure::detail::storage(
334 PrimitiveConcept::apply(
335 BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_EXTRACT, ~)));
336 }
337 };
338
339 template<class PrimitiveConcept
340 BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)>
341 struct vtable_adapter<PrimitiveConcept, ::boost::type_erasure::detail::storage&(BOOST_PP_ENUM_PARAMS(N, T))>
342 {
343 typedef ::boost::type_erasure::detail::storage (*type)(BOOST_PP_ENUM_PARAMS(N, T));
344 static ::boost::type_erasure::detail::storage value(BOOST_PP_ENUM_BINARY_PARAMS(N, T, arg))
345 {
346 typedef typename ::boost::function_traits<
347 typename ::boost::type_erasure::detail::get_signature<
348 PrimitiveConcept
349 >::type
350 > traits;
351 ::boost::type_erasure::detail::storage result;
352 typename ::boost::remove_reference<typename traits::result_type>::type* p =
353 ::boost::addressof(
354 PrimitiveConcept::apply(BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_EXTRACT, ~)));
355 result.data = const_cast<void*>(static_cast<const void*>(p));
356 return result;
357 }
358 };
359
360 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
361
362 template<class PrimitiveConcept
363 BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)>
364 struct vtable_adapter<PrimitiveConcept, ::boost::type_erasure::detail::storage&&(BOOST_PP_ENUM_PARAMS(N, T))>
365 {
366 typedef ::boost::type_erasure::detail::storage (*type)(BOOST_PP_ENUM_PARAMS(N, T));
367 static ::boost::type_erasure::detail::storage value(BOOST_PP_ENUM_BINARY_PARAMS(N, T, arg))
368 {
369 typedef typename ::boost::function_traits<
370 typename ::boost::type_erasure::detail::get_signature<
371 PrimitiveConcept
372 >::type
373 > traits;
374 ::boost::type_erasure::detail::storage result;
375 typename traits::result_type tmp =
376 PrimitiveConcept::apply(BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_EXTRACT, ~));
377 typename ::boost::remove_reference<typename traits::result_type>::type* p =
378 ::boost::addressof(tmp);
379 result.data = const_cast<void*>(static_cast<const void*>(p));
380 return result;
381 }
382 };
383
384 #endif
385
386 template<class R BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)>
387 struct get_vtable_signature<R(BOOST_PP_ENUM_PARAMS(N, T))>
388 {
389 typedef typename ::boost::type_erasure::detail::replace_result_for_vtable<
390 R
391 >::type type(BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_REPLACE_PARAM, ~));
392 };
393
394 #undef BOOST_TYPE_ERASURE_REPLACE_PARAM
395 #undef BOOST_TYPE_ERASURE_EXTRACT
396 #undef N
397
398 #endif