extract_concept.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #if !defined(BOOST_PP_IS_ITERATING)
  11. #ifndef BOOST_TYPE_ERASURE_DETAIL_EXTRACT_CONCEPT_HPP_INCLUDED
  12. #define BOOST_TYPE_ERASURE_DETAIL_EXTRACT_CONCEPT_HPP_INCLUDED
  13. #include <boost/mpl/eval_if.hpp>
  14. #include <boost/mpl/identity.hpp>
  15. #include <boost/type_traits/remove_cv.hpp>
  16. #include <boost/type_traits/remove_reference.hpp>
  17. #include <boost/preprocessor/cat.hpp>
  18. #include <boost/preprocessor/inc.hpp>
  19. #include <boost/preprocessor/iteration/iterate.hpp>
  20. #include <boost/preprocessor/repetition/repeat.hpp>
  21. #include <boost/preprocessor/repetition/enum_params.hpp>
  22. #include <boost/type_erasure/is_placeholder.hpp>
  23. #include <boost/type_erasure/concept_of.hpp>
  24. #include <boost/type_erasure/config.hpp>
  25. namespace boost {
  26. namespace type_erasure {
  27. namespace detail {
  28. template<class T, class U>
  29. struct combine_concepts;
  30. template<class T>
  31. struct combine_concepts<T, T> { typedef T type; };
  32. template<class T>
  33. struct combine_concepts<T, void> { typedef T type; };
  34. template<class T>
  35. struct combine_concepts<void, T> { typedef T type; };
  36. template<>
  37. struct combine_concepts<void, void> { typedef void type; };
  38. #ifdef BOOST_TYPE_ERASURE_USE_MP11
  39. template<class T, class U>
  40. using combine_concepts_t = typename ::boost::type_erasure::detail::combine_concepts<T, U>::type;
  41. template<class T, class U>
  42. using extract_concept_or_void =
  43. ::boost::mp11::mp_eval_if_c<
  44. !::boost::type_erasure::is_placeholder<
  45. ::boost::remove_cv_t<
  46. ::boost::remove_reference_t<T>
  47. >
  48. >::value,
  49. void,
  50. ::boost::type_erasure::concept_of_t, U
  51. >;
  52. template<class L1, class L2>
  53. using extract_concept_t =
  54. ::boost::mp11::mp_fold<
  55. ::boost::mp11::mp_transform< ::boost::type_erasure::detail::extract_concept_or_void, L1, L2>,
  56. void,
  57. ::boost::type_erasure::detail::combine_concepts_t
  58. >;
  59. #else
  60. template<class T, class U>
  61. struct maybe_extract_concept
  62. {
  63. typedef typename ::boost::mpl::eval_if<
  64. ::boost::type_erasure::is_placeholder<
  65. typename ::boost::remove_cv<
  66. typename ::boost::remove_reference<T>::type
  67. >::type
  68. >,
  69. ::boost::type_erasure::concept_of<typename ::boost::remove_reference<U>::type>,
  70. ::boost::mpl::identity<void>
  71. >::type type;
  72. };
  73. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  74. template<class Args, class... U>
  75. struct extract_concept;
  76. template<class R, class T0, class... T, class U0, class... U>
  77. struct extract_concept<R(T0, T...), U0, U...>
  78. {
  79. typedef typename ::boost::type_erasure::detail::combine_concepts<
  80. typename ::boost::type_erasure::detail::maybe_extract_concept<
  81. T0, U0
  82. >::type,
  83. typename ::boost::type_erasure::detail::extract_concept<
  84. void(T...),
  85. U...
  86. >::type
  87. >::type type;
  88. };
  89. template<>
  90. struct extract_concept<void()>
  91. {
  92. typedef void type;
  93. };
  94. #else
  95. #define BOOST_PP_FILENAME_1 <boost/type_erasure/detail/extract_concept.hpp>
  96. #define BOOST_PP_ITERATION_LIMITS (1, BOOST_TYPE_ERASURE_MAX_ARITY)
  97. #include BOOST_PP_ITERATE()
  98. #endif
  99. #endif
  100. }
  101. }
  102. }
  103. #endif
  104. #else
  105. #define N BOOST_PP_ITERATION()
  106. #define BOOST_TYPE_ERASURE_EXTRACT_CONCEPT(z, n, data) \
  107. typedef typename ::boost::type_erasure::detail::combine_concepts< \
  108. typename ::boost::type_erasure::detail::maybe_extract_concept< \
  109. BOOST_PP_CAT(T, n), BOOST_PP_CAT(U, n) \
  110. >::type, \
  111. BOOST_PP_CAT(concept, n) \
  112. >::type BOOST_PP_CAT(concept, BOOST_PP_INC(n));
  113. template<
  114. BOOST_PP_ENUM_PARAMS(N, class T),
  115. BOOST_PP_ENUM_PARAMS(N, class U)>
  116. struct BOOST_PP_CAT(extract_concept, N)
  117. {
  118. typedef void concept0;
  119. BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_EXTRACT_CONCEPT, ~)
  120. typedef BOOST_PP_CAT(concept, N) type;
  121. };
  122. #undef BOOST_TYPE_ERASURE_EXTRACT_CONCEPT
  123. #undef N
  124. #endif