instantiate.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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_INSTANTIATE_HPP_INCLUDED
  12. #define BOOST_TYPE_ERASURE_DETAIL_INSTANTIATE_HPP_INCLUDED
  13. #include <boost/mpl/transform.hpp>
  14. #include <boost/mpl/size.hpp>
  15. #include <boost/mpl/at.hpp>
  16. #include <boost/preprocessor/cat.hpp>
  17. #include <boost/preprocessor/iteration/iterate.hpp>
  18. #include <boost/preprocessor/repetition/repeat.hpp>
  19. #include <boost/preprocessor/repetition/enum.hpp>
  20. #include <boost/preprocessor/repetition/enum_params.hpp>
  21. #include <boost/type_erasure/detail/normalize.hpp>
  22. #include <boost/type_erasure/detail/rebind_placeholders.hpp>
  23. namespace boost {
  24. namespace type_erasure {
  25. namespace detail {
  26. #ifdef BOOST_TYPE_ERASURE_USE_MP11
  27. template<class L>
  28. struct make_instantiate_concept_impl;
  29. template<class T, T t>
  30. struct instantiate_concept;
  31. template<class T>
  32. using instantiate_concept_impl = instantiate_concept<decltype(&T::apply), &T::apply>;
  33. template<class... T>
  34. struct make_instantiate_concept_impl< ::boost::mp11::mp_list<T...> >
  35. {
  36. template<template<class> class F>
  37. using apply = void(F<T>...);
  38. };
  39. template<class Map>
  40. struct instantiate_concept_rebind_f
  41. {
  42. template<class T>
  43. using apply =
  44. typename ::boost::type_erasure::detail::rebind_placeholders<
  45. T,
  46. Map
  47. >::type;
  48. };
  49. template<class Concept, class Map>
  50. using make_instantiate_concept =
  51. ::boost::type_erasure::detail::make_instantiate_concept_impl<
  52. ::boost::mp11::mp_transform<
  53. ::boost::type_erasure::detail::instantiate_concept_rebind_f<
  54. typename ::boost::type_erasure::detail::add_deductions<
  55. ::boost::type_erasure::detail::make_mp_list<Map>,
  56. typename ::boost::type_erasure::detail::get_placeholder_normalization_map<
  57. Concept
  58. >::type
  59. >::type
  60. >::template apply,
  61. ::boost::type_erasure::detail::normalize_concept_t<Concept>
  62. >
  63. >;
  64. #define BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map) \
  65. ((void)(typename ::boost::type_erasure::detail::make_instantiate_concept<Concept, Map> \
  66. ::template apply< ::boost::type_erasure::detail::instantiate_concept_impl>*)0)
  67. #define BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, P0, T0) \
  68. ((void)(typename ::boost::type_erasure::detail::make_instantiate_concept< \
  69. Concept, ::boost::mpl::map1< ::boost::mpl::pair<P0, T0> > > \
  70. ::template apply< ::boost::type_erasure::detail::instantiate_concept_impl>*)0)
  71. #else
  72. template<int N>
  73. struct make_instantiate_concept_impl;
  74. template<class Concept>
  75. struct make_instantiate_concept {
  76. typedef typename ::boost::type_erasure::detail::normalize_concept<
  77. Concept>::type normalized;
  78. typedef typename ::boost::type_erasure::detail::make_instantiate_concept_impl<
  79. (::boost::mpl::size<normalized>::value)
  80. >::type type;
  81. };
  82. #define BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map) \
  83. (::boost::type_erasure::detail::make_instantiate_concept< \
  84. Concept \
  85. >::type::apply((Concept*)0, (Map*)0))
  86. #define BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, P0, T0) \
  87. (::boost::type_erasure::detail::make_instantiate_concept< \
  88. Concept \
  89. >::type::apply( \
  90. (Concept*)0, \
  91. (::boost::mpl::map1< ::boost::mpl::pair<P0, T0> >*)0))
  92. #define BOOST_PP_FILENAME_1 <boost/type_erasure/detail/instantiate.hpp>
  93. #define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPE_ERASURE_MAX_FUNCTIONS)
  94. #include BOOST_PP_ITERATE()
  95. #endif
  96. }
  97. }
  98. }
  99. #endif
  100. #else
  101. #define N BOOST_PP_ITERATION()
  102. #define BOOST_TYPE_ERASURE_INSTANTIATE_IMPL(z, n, data)\
  103. (void)&::boost::mpl::at_c<data, n>::type::apply;
  104. struct BOOST_PP_CAT(instantiate_concept, N) {
  105. template<class Concept, class Map>
  106. static void apply(Concept *, Map *) {
  107. #if N > 0
  108. typedef typename ::boost::type_erasure::detail::normalize_concept<
  109. Concept>::type normalized;
  110. typedef typename ::boost::type_erasure::detail::get_placeholder_normalization_map<
  111. Concept
  112. >::type placeholder_subs;
  113. typedef typename ::boost::mpl::transform<
  114. normalized,
  115. ::boost::type_erasure::detail::rebind_placeholders<
  116. ::boost::mpl::_1,
  117. typename ::boost::type_erasure::detail::add_deductions<
  118. Map,
  119. placeholder_subs
  120. >::type
  121. >
  122. >::type concept_sequence;
  123. #endif
  124. BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_INSTANTIATE_IMPL, concept_sequence)
  125. }
  126. };
  127. template<>
  128. struct make_instantiate_concept_impl<N>
  129. {
  130. typedef ::boost::type_erasure::detail::BOOST_PP_CAT(instantiate_concept, N) type;
  131. };
  132. #undef BOOST_TYPE_ERASURE_INSTANTIATE_IMPL
  133. #undef N
  134. #endif