summaryrefslogtreecommitdiff
path: root/boost/type_erasure/detail/rebind_placeholders.hpp
blob: 0d0ef7c8e4f9219c21dcc43c1549bc98c289e2e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
// Boost.TypeErasure library
//
// Copyright 2011 Steven Watanabe
//
// Distributed under the Boost Software License Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// $Id$

#if !defined(BOOST_PP_IS_ITERATING)

#ifndef BOOST_TYPE_ERASURE_DETAIL_REBIND_PLACEHOLDERS_HPP_INCLUDED
#define BOOST_TYPE_ERASURE_DETAIL_REBIND_PLACEHOLDERS_HPP_INCLUDED

#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/has_key.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
#include <boost/type_erasure/config.hpp>
#include <boost/type_erasure/detail/meta.hpp>
#include <boost/type_erasure/is_placeholder.hpp>

namespace boost {
namespace type_erasure {

template<class F>
struct deduced;

namespace detail {

template<class T, class Bindings>
struct rebind_placeholders
{
    typedef void type;
};

template<class T>
struct identity
{
    typedef T type;
};

template<class PrimitiveConcept, class Sig>
struct vtable_adapter;

#ifdef BOOST_TYPE_ERASURE_USE_MP11

template<class T, class Bindings>
using rebind_placeholders_t = typename rebind_placeholders<T, Bindings>::type;

template<class T, class Bindings>
using rebind_one_placeholder = ::boost::mp11::mp_second< ::boost::mp11::mp_map_find<Bindings, T> >;

template<class T>
struct rebind_placeholders_in_argument_impl
{
    template<class Bindings>
    using apply = ::boost::type_erasure::detail::eval_if<
        ::boost::mp11::mp_map_contains<Bindings, T>::value,
        ::boost::type_erasure::detail::rebind_one_placeholder,
        ::boost::type_erasure::detail::first,
        T,
        Bindings
    >;
};

template<class T, class Bindings>
using rebind_placeholders_in_argument_t = typename ::boost::type_erasure::detail::rebind_placeholders_in_argument_impl<T>::template apply<Bindings>;

template<class T, class Bindings>
using rebind_placeholders_in_argument = ::boost::mpl::identity< ::boost::type_erasure::detail::rebind_placeholders_in_argument_t<T, Bindings> >;

template<class T>
struct rebind_placeholders_in_argument_impl<T&>
{
    template<class Bindings>
    using apply = rebind_placeholders_in_argument_t<T, Bindings>&;
};

template<class T>
struct rebind_placeholders_in_argument_impl<T&&>
{
    template<class Bindings>
    using apply = rebind_placeholders_in_argument_t<T, Bindings>&&;
};

template<class T>
struct rebind_placeholders_in_argument_impl<const T>
{
    template<class Bindings>
    using apply = rebind_placeholders_in_argument_t<T, Bindings> const;
};

template<class F, class Bindings>
using rebind_placeholders_in_deduced =
    typename ::boost::type_erasure::deduced<
        ::boost::type_erasure::detail::rebind_placeholders_t<F, Bindings>
    >::type;

template<class F, class Bindings>
using rebind_deduced_placeholder =
    ::boost::mp11::mp_second<
        ::boost::mp11::mp_map_find<Bindings, ::boost::type_erasure::deduced<F> >
    >;

template<class F>
struct rebind_placeholders_in_argument_impl<
    ::boost::type_erasure::deduced<F>
> 
{
    template<class Bindings>
    using apply = ::boost::type_erasure::detail::eval_if<
        ::boost::mp11::mp_map_contains<Bindings, ::boost::type_erasure::deduced<F> >::value,
        ::boost::type_erasure::detail::rebind_deduced_placeholder,
        ::boost::type_erasure::detail::rebind_placeholders_in_deduced,
        F,
        Bindings
    >;
};

template<class R, class... T>
struct rebind_placeholders_in_argument_impl<R(T...)>
{
    template<class Bindings>
    using apply =
        rebind_placeholders_in_argument_t<R, Bindings>
            (rebind_placeholders_in_argument_t<T, Bindings>...);
};

template<class R, class C, class... T>
struct rebind_placeholders_in_argument_impl<R (C::*)(T...)>
{
    template<class Bindings>
    using apply =
        rebind_placeholders_in_argument_t<R, Bindings>
            (rebind_placeholders_in_argument_t<C, Bindings>::*)
            (rebind_placeholders_in_argument_t<T, Bindings>...);
};

template<class R, class C, class... T>
struct rebind_placeholders_in_argument_impl<R (C::*)(T...) const>
{
    template<class Bindings>
    using apply =
        rebind_placeholders_in_argument_t<R, Bindings>
            (rebind_placeholders_in_argument_t<C, Bindings>::*)
            (rebind_placeholders_in_argument_t<T, Bindings>...) const;
};

template<template<class...> class T, class... U, class Bindings>
struct rebind_placeholders<T<U...>, Bindings>
{
    typedef ::boost::type_erasure::detail::make_mp_list<Bindings> xBindings;
    typedef T<rebind_placeholders_in_argument_t<U, xBindings>...> type;
};

template<class PrimitiveConcept, class Sig, class Bindings>
struct rebind_placeholders<vtable_adapter<PrimitiveConcept, Sig>, Bindings>
{
    typedef ::boost::type_erasure::detail::make_mp_list<Bindings> xBindings;
    typedef vtable_adapter<
        rebind_placeholders_t<PrimitiveConcept, xBindings>,
        rebind_placeholders_in_argument_t<Sig, xBindings>
    > type;
};

#else

template<class T, class Bindings>
struct rebind_placeholders_in_argument
{
    BOOST_MPL_ASSERT((boost::mpl::or_<
        ::boost::mpl::not_< ::boost::type_erasure::is_placeholder<T> >,
        ::boost::mpl::has_key<Bindings, T>
    >));
    typedef typename ::boost::mpl::eval_if<
        ::boost::type_erasure::is_placeholder<T>,
        ::boost::mpl::at<Bindings, T>,
        ::boost::type_erasure::detail::identity<T>
    >::type type;
};

template<class PrimitiveConcept, class Sig, class Bindings>
struct rebind_placeholders<vtable_adapter<PrimitiveConcept, Sig>, Bindings>
{
    typedef vtable_adapter<
        typename rebind_placeholders<PrimitiveConcept, Bindings>::type,
        typename rebind_placeholders_in_argument<Sig, Bindings>::type
    > type;
};

template<class T, class Bindings>
struct rebind_placeholders_in_argument<T&, Bindings>
{
    typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
        T,
        Bindings
    >::type& type;
};

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES

template<class T, class Bindings>
struct rebind_placeholders_in_argument<T&&, Bindings>
{
    typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
        T,
        Bindings
    >::type&& type;
};

#endif

template<class T, class Bindings>
struct rebind_placeholders_in_argument<const T, Bindings>
{
    typedef const typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
        T,
        Bindings
    >::type type;
};

template<class F, class Bindings>
struct rebind_placeholders_in_deduced
{
    typedef typename ::boost::type_erasure::deduced<
        typename ::boost::type_erasure::detail::rebind_placeholders<F, Bindings>::type
    >::type type;
};

template<class F, class Bindings>
struct rebind_placeholders_in_argument<
    ::boost::type_erasure::deduced<F>,
    Bindings
> 
{
    typedef typename ::boost::mpl::eval_if<
        ::boost::mpl::has_key<Bindings, ::boost::type_erasure::deduced<F> >,
        ::boost::mpl::at<Bindings, ::boost::type_erasure::deduced<F> >,
        ::boost::type_erasure::detail::rebind_placeholders_in_deduced<
            F,
            Bindings
        >
    >::type type;
};

#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)

template<template<class...> class T, class... U, class Bindings>
struct rebind_placeholders<T<U...>, Bindings>
{
    typedef T<typename rebind_placeholders_in_argument<U, Bindings>::type...> type;
};

template<class R, class... T, class Bindings>
struct rebind_placeholders_in_argument<R(T...), Bindings>
{
    typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
        R,
        Bindings
    >::type type(typename rebind_placeholders_in_argument<T, Bindings>::type...);
};

template<class R, class C, class... T, class Bindings>
struct rebind_placeholders_in_argument<R (C::*)(T...), Bindings>
{
    typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
        R,
        Bindings
    >::type (rebind_placeholders_in_argument<C, Bindings>::type::*type)
        (typename rebind_placeholders_in_argument<T, Bindings>::type...);
};

template<class R, class C, class... T, class Bindings>
struct rebind_placeholders_in_argument<R (C::*)(T...) const, Bindings>
{
    typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
        R,
        Bindings
    >::type (rebind_placeholders_in_argument<C, Bindings>::type::*type)
        (typename rebind_placeholders_in_argument<T, Bindings>::type...) const;
};

#else

#define BOOST_PP_FILENAME_1 <boost/type_erasure/detail/rebind_placeholders.hpp>
#define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPE_ERASURE_MAX_ARITY)
#include BOOST_PP_ITERATE()

#endif

#endif

}
}
}

#endif

#else

#define N BOOST_PP_ITERATION()
#define BOOST_TYPE_ERASURE_REBIND(z, n, data)                           \
    typename rebind_placeholders_in_argument<BOOST_PP_CAT(data, n), Bindings>::type

#if N != 0

template<template<BOOST_PP_ENUM_PARAMS(N, class T)> class T,
    BOOST_PP_ENUM_PARAMS(N, class T), class Bindings>
struct rebind_placeholders<T<BOOST_PP_ENUM_PARAMS(N, T)>, Bindings>
{
    typedef T<BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_REBIND, T)> type;
};

#endif

template<class R
    BOOST_PP_ENUM_TRAILING_PARAMS(N, class T), class Bindings>
struct rebind_placeholders_in_argument<R(BOOST_PP_ENUM_PARAMS(N, T)), Bindings>
{
    typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
        R,
        Bindings
    >::type type(BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_REBIND, T));
};

#undef BOOST_TYPE_ERASURE_REBIND
#undef N

#endif