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