summaryrefslogtreecommitdiff
path: root/boost/type_erasure/detail/check_call.hpp
blob: daa99311467e31b68e423706fffba96d8f11ec08 (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
// Boost.TypeErasure library
//
// Copyright 2012 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_CHECK_CALL_HPP_INCLUDED
#define BOOST_TYPE_ERASURE_DETAIL_CHECK_CALL_HPP_INCLUDED

#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/and.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/function_traits.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/type_erasure/placeholder_of.hpp>

namespace boost {
namespace type_erasure {
namespace detail {

template<class Sig, class Args>
struct check_call : ::boost::mpl::false_ {};

template<class T, class Enable = void>
struct qualified_placeholder
{
    typedef void type;
};

template<class T>
struct qualified_placeholder<T&, typename T::_boost_type_erasure_is_any>
{
    typedef typename ::boost::type_erasure::placeholder_of<T>::type placeholder;
    typedef typename ::boost::remove_reference<placeholder>::type unref;
    typedef typename ::boost::mpl::if_< ::boost::is_const<T>,
        const unref,
        unref
    >::type add_const;
    typedef typename ::boost::mpl::if_< ::boost::is_reference<placeholder>,
        placeholder,
        add_const&
    >::type type;
};

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES

template<class T>
struct qualified_placeholder<T&&, typename T::_boost_type_erasure_is_any>
{
    typedef typename ::boost::type_erasure::placeholder_of<T>::type placeholder;
    typedef placeholder&& type;
};

#endif

template<class P, class A>
struct check_placeholder_arg_impl : ::boost::mpl::false_ {};

template<class P>
struct check_placeholder_arg_impl<P, P&> : ::boost::mpl::true_ {};

template<class P>
struct check_placeholder_arg_impl<P, const P&> : ::boost::mpl::true_ {};

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES

template<class P>
struct check_placeholder_arg_impl<P, P&&> : ::boost::mpl::true_ {};

#endif

template<class P>
struct check_placeholder_arg_impl<P&, P&> : ::boost::mpl::true_ {};

template<class P>
struct check_placeholder_arg_impl<const P&, P&> : ::boost::mpl::true_ {};

template<class P>
struct check_placeholder_arg_impl<const P&, const P&> : ::boost::mpl::true_ {};

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES

template<class P>
struct check_placeholder_arg_impl<const P&, P&&> : ::boost::mpl::true_ {};

template<class P>
struct check_placeholder_arg_impl<P&&, P&&> : ::boost::mpl::true_ {};

#endif

template<class P, class Arg>
struct check_placeholder_arg :
    check_placeholder_arg_impl<
        P,
        typename ::boost::type_erasure::detail::qualified_placeholder<Arg>::type
    >::type
{};

#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
    ((defined(__GNUC__) && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6))) || \
    defined(__MINGW32__) || defined(__MINGW64__) || \
    BOOST_WORKAROUND(BOOST_MSVC, <= 1700))
#define BOOST_TYPE_ERASURE_BROKEN_RVALUE_IS_CONVERTIBLE
#endif

#ifdef BOOST_TYPE_ERASURE_USE_MP11

template<class P, class Arg>
using check_placeholder_arg_t =
    typename ::boost::type_erasure::detail::check_placeholder_arg_impl<
        P,
        typename ::boost::type_erasure::detail::qualified_placeholder<Arg>::type
    >::type;

template<class T, class Arg>
using check_nonplaceholder_arg_t = typename ::boost::is_convertible<Arg, T>::type;

template<class FormalArg, class ActualArg>
using check_arg_t =
    ::boost::type_erasure::detail::eval_if<
        ::boost::type_erasure::is_placeholder<
            ::boost::remove_cv_t<
                ::boost::remove_reference_t<FormalArg>
            >
        >::value,
        ::boost::type_erasure::detail::check_placeholder_arg_t,
        ::boost::type_erasure::detail::check_nonplaceholder_arg_t,
        FormalArg,
        ActualArg
    >;

// MSVC 14.1 ICE's if we use check_arg_t directly.
template<class FormalArg, class ActualArg>
struct check_arg
{
    typedef ::boost::type_erasure::detail::check_arg_t<FormalArg, ActualArg> type;
};

template<class R, class... T, class... U>
struct check_call<R(T...), void(U...)> {
    typedef ::boost::mp11::mp_all<
        typename ::boost::type_erasure::detail::check_arg<T, U>::type...
    > type;
};

#else

template<class FormalArg, class ActualArg>
struct check_arg
{
    typedef typename ::boost::mpl::eval_if<
        is_placeholder<
            typename ::boost::remove_cv<
                typename ::boost::remove_reference<FormalArg>::type
            >::type
        >,
        ::boost::type_erasure::detail::check_placeholder_arg<FormalArg, ActualArg>,
#ifdef BOOST_TYPE_ERASURE_BROKEN_RVALUE_IS_CONVERTIBLE
        ::boost::mpl::true_
#else
        ::boost::is_convertible<ActualArg, FormalArg>
#endif
    >::type type;
};

#ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES

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

#else

template<class... B>
struct and_;

template<class T1, class... T>
struct and_<T1, T...> : boost::mpl::eval_if_c<T1::type::value, and_<T...>, boost::mpl::false_>::type {};

template<class T1>
struct and_<T1> : T1::type {};

template<>
struct and_<> : boost::mpl::true_ {};

template<class R, class... T, class... U>
struct check_call<R(T...), void(U...)> {
    typedef typename ::boost::type_erasure::detail::and_<
        ::boost::type_erasure::detail::check_arg<T, U>...
    >::type type;
};

#endif

#endif

}
}
}

#endif

#else

#define N BOOST_PP_ITERATION()

#define BOOST_TYPE_ERASURE_CHECK_ARG(z, n, data)                \
    typedef typename ::boost::type_erasure::detail::check_arg<  \
        BOOST_PP_CAT(T, n),                                     \
        BOOST_PP_CAT(U, n)                                      \
    >::type BOOST_PP_CAT(check, n);                             \
    typedef typename ::boost::mpl::and_<                        \
        BOOST_PP_CAT(type, n),                                  \
        BOOST_PP_CAT(check, n)                                  \
    >::type BOOST_PP_CAT(type, BOOST_PP_INC(n));

template<
    class R
    BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
    BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
>
struct check_call<R(BOOST_PP_ENUM_PARAMS(N, T)), void(BOOST_PP_ENUM_BINARY_PARAMS(N, U, u))> {
    typedef ::boost::mpl::true_ type0;
    BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_CHECK_ARG, ~)
    typedef BOOST_PP_CAT(type, N) type;
};

#undef N

#endif