check_call.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // Boost.TypeErasure library
  2. //
  3. // Copyright 2012 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. #if !defined(BOOST_PP_IS_ITERATING)
  11. #ifndef BOOST_TYPE_ERASURE_DETAIL_CHECK_CALL_HPP_INCLUDED
  12. #define BOOST_TYPE_ERASURE_DETAIL_CHECK_CALL_HPP_INCLUDED
  13. #include <boost/mpl/eval_if.hpp>
  14. #include <boost/mpl/bool.hpp>
  15. #include <boost/mpl/and.hpp>
  16. #include <boost/type_traits/is_convertible.hpp>
  17. #include <boost/type_traits/remove_reference.hpp>
  18. #include <boost/type_traits/remove_cv.hpp>
  19. #include <boost/type_traits/is_reference.hpp>
  20. #include <boost/type_traits/is_const.hpp>
  21. #include <boost/type_traits/function_traits.hpp>
  22. #include <boost/preprocessor/iteration/iterate.hpp>
  23. #include <boost/preprocessor/repetition/enum_params.hpp>
  24. #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
  25. #include <boost/preprocessor/repetition/repeat.hpp>
  26. #include <boost/preprocessor/cat.hpp>
  27. #include <boost/type_erasure/placeholder_of.hpp>
  28. namespace boost {
  29. namespace type_erasure {
  30. namespace detail {
  31. template<class Sig, class Args>
  32. struct check_call : ::boost::mpl::false_ {};
  33. template<class T, class Enable = void>
  34. struct qualified_placeholder
  35. {
  36. typedef void type;
  37. };
  38. template<class T>
  39. struct qualified_placeholder<T&, typename T::_boost_type_erasure_is_any>
  40. {
  41. typedef typename ::boost::type_erasure::placeholder_of<T>::type placeholder;
  42. typedef typename ::boost::remove_reference<placeholder>::type unref;
  43. typedef typename ::boost::mpl::if_< ::boost::is_const<T>,
  44. const unref,
  45. unref
  46. >::type add_const;
  47. typedef typename ::boost::mpl::if_< ::boost::is_reference<placeholder>,
  48. placeholder,
  49. add_const&
  50. >::type type;
  51. };
  52. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  53. template<class T>
  54. struct qualified_placeholder<T&&, typename T::_boost_type_erasure_is_any>
  55. {
  56. typedef typename ::boost::type_erasure::placeholder_of<T>::type placeholder;
  57. typedef placeholder&& type;
  58. };
  59. #endif
  60. template<class P, class A>
  61. struct check_placeholder_arg_impl : ::boost::mpl::false_ {};
  62. template<class P>
  63. struct check_placeholder_arg_impl<P, P&> : ::boost::mpl::true_ {};
  64. template<class P>
  65. struct check_placeholder_arg_impl<P, const P&> : ::boost::mpl::true_ {};
  66. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  67. template<class P>
  68. struct check_placeholder_arg_impl<P, P&&> : ::boost::mpl::true_ {};
  69. #endif
  70. template<class P>
  71. struct check_placeholder_arg_impl<P&, P&> : ::boost::mpl::true_ {};
  72. template<class P>
  73. struct check_placeholder_arg_impl<const P&, P&> : ::boost::mpl::true_ {};
  74. template<class P>
  75. struct check_placeholder_arg_impl<const P&, const P&> : ::boost::mpl::true_ {};
  76. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  77. template<class P>
  78. struct check_placeholder_arg_impl<const P&, P&&> : ::boost::mpl::true_ {};
  79. template<class P>
  80. struct check_placeholder_arg_impl<P&&, P&&> : ::boost::mpl::true_ {};
  81. #endif
  82. template<class P, class Arg>
  83. struct check_placeholder_arg :
  84. check_placeholder_arg_impl<
  85. P,
  86. typename ::boost::type_erasure::detail::qualified_placeholder<Arg>::type
  87. >::type
  88. {};
  89. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
  90. ((defined(__GNUC__) && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6))) || \
  91. defined(__MINGW32__) || defined(__MINGW64__) || \
  92. BOOST_WORKAROUND(BOOST_MSVC, <= 1700))
  93. #define BOOST_TYPE_ERASURE_BROKEN_RVALUE_IS_CONVERTIBLE
  94. #endif
  95. #ifdef BOOST_TYPE_ERASURE_USE_MP11
  96. template<class P, class Arg>
  97. using check_placeholder_arg_t =
  98. typename ::boost::type_erasure::detail::check_placeholder_arg_impl<
  99. P,
  100. typename ::boost::type_erasure::detail::qualified_placeholder<Arg>::type
  101. >::type;
  102. template<class T, class Arg>
  103. using check_nonplaceholder_arg_t = typename ::boost::is_convertible<Arg, T>::type;
  104. template<class FormalArg, class ActualArg>
  105. using check_arg_t =
  106. ::boost::type_erasure::detail::eval_if<
  107. ::boost::type_erasure::is_placeholder<
  108. ::boost::remove_cv_t<
  109. ::boost::remove_reference_t<FormalArg>
  110. >
  111. >::value,
  112. ::boost::type_erasure::detail::check_placeholder_arg_t,
  113. ::boost::type_erasure::detail::check_nonplaceholder_arg_t,
  114. FormalArg,
  115. ActualArg
  116. >;
  117. // MSVC 14.1 ICE's if we use check_arg_t directly.
  118. template<class FormalArg, class ActualArg>
  119. struct check_arg
  120. {
  121. typedef ::boost::type_erasure::detail::check_arg_t<FormalArg, ActualArg> type;
  122. };
  123. template<class R, class... T, class... U>
  124. struct check_call<R(T...), void(U...)> {
  125. typedef ::boost::mp11::mp_all<
  126. typename ::boost::type_erasure::detail::check_arg<T, U>::type...
  127. > type;
  128. };
  129. #else
  130. template<class FormalArg, class ActualArg>
  131. struct check_arg
  132. {
  133. typedef typename ::boost::mpl::eval_if<
  134. is_placeholder<
  135. typename ::boost::remove_cv<
  136. typename ::boost::remove_reference<FormalArg>::type
  137. >::type
  138. >,
  139. ::boost::type_erasure::detail::check_placeholder_arg<FormalArg, ActualArg>,
  140. #ifdef BOOST_TYPE_ERASURE_BROKEN_RVALUE_IS_CONVERTIBLE
  141. ::boost::mpl::true_
  142. #else
  143. ::boost::is_convertible<ActualArg, FormalArg>
  144. #endif
  145. >::type type;
  146. };
  147. #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
  148. #define BOOST_PP_FILENAME_1 <boost/type_erasure/detail/check_call.hpp>
  149. #define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPE_ERASURE_MAX_ARITY)
  150. #include BOOST_PP_ITERATE()
  151. #else
  152. template<class... B>
  153. struct and_;
  154. template<class T1, class... T>
  155. struct and_<T1, T...> : boost::mpl::eval_if_c<T1::type::value, and_<T...>, boost::mpl::false_>::type {};
  156. template<class T1>
  157. struct and_<T1> : T1::type {};
  158. template<>
  159. struct and_<> : boost::mpl::true_ {};
  160. template<class R, class... T, class... U>
  161. struct check_call<R(T...), void(U...)> {
  162. typedef typename ::boost::type_erasure::detail::and_<
  163. ::boost::type_erasure::detail::check_arg<T, U>...
  164. >::type type;
  165. };
  166. #endif
  167. #endif
  168. }
  169. }
  170. }
  171. #endif
  172. #else
  173. #define N BOOST_PP_ITERATION()
  174. #define BOOST_TYPE_ERASURE_CHECK_ARG(z, n, data) \
  175. typedef typename ::boost::type_erasure::detail::check_arg< \
  176. BOOST_PP_CAT(T, n), \
  177. BOOST_PP_CAT(U, n) \
  178. >::type BOOST_PP_CAT(check, n); \
  179. typedef typename ::boost::mpl::and_< \
  180. BOOST_PP_CAT(type, n), \
  181. BOOST_PP_CAT(check, n) \
  182. >::type BOOST_PP_CAT(type, BOOST_PP_INC(n));
  183. template<
  184. class R
  185. BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
  186. BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
  187. >
  188. struct check_call<R(BOOST_PP_ENUM_PARAMS(N, T)), void(BOOST_PP_ENUM_BINARY_PARAMS(N, U, u))> {
  189. typedef ::boost::mpl::true_ type0;
  190. BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_CHECK_ARG, ~)
  191. typedef BOOST_PP_CAT(type, N) type;
  192. };
  193. #undef N
  194. #endif