1 // Boost.TypeErasure library
3 // Copyright 2012 Steven Watanabe
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)
11 #if !defined(BOOST_PP_IS_ITERATING)
13 #ifndef BOOST_TYPE_ERASURE_DETAIL_CHECK_CALL_HPP_INCLUDED
14 #define BOOST_TYPE_ERASURE_DETAIL_CHECK_CALL_HPP_INCLUDED
16 #include <boost/mpl/eval_if.hpp>
17 #include <boost/mpl/bool.hpp>
18 #include <boost/mpl/and.hpp>
19 #include <boost/type_traits/is_convertible.hpp>
20 #include <boost/type_traits/remove_reference.hpp>
21 #include <boost/type_traits/remove_cv.hpp>
22 #include <boost/type_traits/is_reference.hpp>
23 #include <boost/type_traits/is_const.hpp>
24 #include <boost/type_traits/function_traits.hpp>
25 #include <boost/preprocessor/iteration/iterate.hpp>
26 #include <boost/preprocessor/repetition/enum_params.hpp>
27 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
28 #include <boost/preprocessor/repetition/repeat.hpp>
29 #include <boost/preprocessor/cat.hpp>
30 #include <boost/type_erasure/placeholder_of.hpp>
33 namespace type_erasure {
36 template<class Sig, class Args>
37 struct check_call : ::boost::mpl::false_ {};
39 template<class T, class Enable = void>
40 struct qualified_placeholder
46 struct qualified_placeholder<T&, typename T::_boost_type_erasure_is_any>
48 typedef typename ::boost::type_erasure::placeholder_of<T>::type placeholder;
49 typedef typename ::boost::remove_reference<placeholder>::type unref;
50 typedef typename ::boost::mpl::if_< ::boost::is_const<T>,
54 typedef typename ::boost::mpl::if_< ::boost::is_reference<placeholder>,
60 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
63 struct qualified_placeholder<T&&, typename T::_boost_type_erasure_is_any>
65 typedef typename ::boost::type_erasure::placeholder_of<T>::type placeholder;
66 typedef placeholder&& type;
71 template<class P, class A>
72 struct check_placeholder_arg_impl : ::boost::mpl::false_ {};
75 struct check_placeholder_arg_impl<P, P&> : ::boost::mpl::true_ {};
78 struct check_placeholder_arg_impl<P, const P&> : ::boost::mpl::true_ {};
80 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
83 struct check_placeholder_arg_impl<P, P&&> : ::boost::mpl::true_ {};
88 struct check_placeholder_arg_impl<P&, P&> : ::boost::mpl::true_ {};
91 struct check_placeholder_arg_impl<const P&, P&> : ::boost::mpl::true_ {};
94 struct check_placeholder_arg_impl<const P&, const P&> : ::boost::mpl::true_ {};
96 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
99 struct check_placeholder_arg_impl<const P&, P&&> : ::boost::mpl::true_ {};
102 struct check_placeholder_arg_impl<P&&, P&&> : ::boost::mpl::true_ {};
106 template<class P, class Arg>
107 struct check_placeholder_arg :
108 check_placeholder_arg_impl<
110 typename ::boost::type_erasure::detail::qualified_placeholder<Arg>::type
114 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
115 ((defined(__GNUC__) && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6))) || \
116 defined(__MINGW32__) || defined(__MINGW64__))
117 #define BOOST_TYPE_ERASURE_BROKEN_RVALUE_IS_CONVERTIBLE
120 template<class FormalArg, class ActualArg>
123 typedef typename ::boost::mpl::eval_if<
125 typename ::boost::remove_cv<
126 typename ::boost::remove_reference<FormalArg>::type
129 ::boost::type_erasure::detail::check_placeholder_arg<FormalArg, ActualArg>,
130 #ifdef BOOST_TYPE_ERASURE_BROKEN_RVALUE_IS_CONVERTIBLE
133 ::boost::is_convertible<ActualArg, FormalArg>
138 #define BOOST_PP_FILENAME_1 <boost/type_erasure/detail/check_call.hpp>
139 #define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPE_ERASURE_MAX_ARITY)
140 #include BOOST_PP_ITERATE()
150 #define N BOOST_PP_ITERATION()
152 #define BOOST_TYPE_ERASURE_CHECK_ARG(z, n, data) \
153 typedef typename ::boost::type_erasure::detail::check_arg< \
154 BOOST_PP_CAT(T, n), \
156 >::type BOOST_PP_CAT(check, n); \
157 typedef typename ::boost::mpl::and_< \
158 BOOST_PP_CAT(type, n), \
159 BOOST_PP_CAT(check, n) \
160 >::type BOOST_PP_CAT(type, BOOST_PP_INC(n));
164 BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
165 BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
167 struct check_call<R(BOOST_PP_ENUM_PARAMS(N, T)), void(BOOST_PP_ENUM_BINARY_PARAMS(N, U, u))> {
168 typedef ::boost::mpl::true_ type0;
169 BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_CHECK_ARG, ~)
170 typedef BOOST_PP_CAT(type, N) type;