mpl.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #ifndef BOOST_MP11_MPL_HPP_INCLUDED
  2. #define BOOST_MP11_MPL_HPP_INCLUDED
  3. // Copyright 2017 Peter Dimov.
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. //
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. #include <boost/mp11/list.hpp>
  10. #include <boost/mp11/algorithm.hpp>
  11. #include <tuple>
  12. namespace boost
  13. {
  14. namespace mpl
  15. {
  16. struct forward_iterator_tag;
  17. namespace aux
  18. {
  19. struct mp11_tag {};
  20. template<class L> struct mp11_iterator
  21. {
  22. using category = forward_iterator_tag;
  23. using type = mp11::mp_first<L>;
  24. using next = mp11_iterator<mp11::mp_rest<L>>;
  25. };
  26. } // namespace aux
  27. // at
  28. template< typename Tag > struct at_impl;
  29. template<> struct at_impl<aux::mp11_tag>
  30. {
  31. template<class L, class I> struct apply
  32. {
  33. using type = mp11::mp_at<L, I>;
  34. };
  35. };
  36. // back
  37. template< typename Tag > struct back_impl;
  38. template<> struct back_impl<aux::mp11_tag>
  39. {
  40. template<class L> struct apply
  41. {
  42. using N = mp11::mp_size<L>;
  43. using type = mp11::mp_at_c<L, N::value - 1>;
  44. };
  45. };
  46. // begin
  47. template< typename Tag > struct begin_impl;
  48. template<> struct begin_impl<aux::mp11_tag>
  49. {
  50. template<class L> struct apply
  51. {
  52. using type = aux::mp11_iterator<L>;
  53. };
  54. };
  55. // clear
  56. template< typename Tag > struct clear_impl;
  57. template<> struct clear_impl<aux::mp11_tag>
  58. {
  59. template<class L> struct apply
  60. {
  61. using type = mp11::mp_clear<L>;
  62. };
  63. };
  64. // end
  65. template< typename Tag > struct end_impl;
  66. template<> struct end_impl<aux::mp11_tag>
  67. {
  68. template<class L> struct apply
  69. {
  70. using type = aux::mp11_iterator<mp11::mp_clear<L>>;
  71. };
  72. };
  73. // front
  74. template< typename Tag > struct front_impl;
  75. template<> struct front_impl<aux::mp11_tag>
  76. {
  77. template<class L> struct apply
  78. {
  79. using type = mp11::mp_front<L>;
  80. };
  81. };
  82. // pop_front
  83. template< typename Tag > struct pop_front_impl;
  84. template<> struct pop_front_impl<aux::mp11_tag>
  85. {
  86. template<class L> struct apply
  87. {
  88. using type = mp11::mp_pop_front<L>;
  89. };
  90. };
  91. // push_back
  92. template< typename Tag > struct push_back_impl;
  93. template<> struct push_back_impl<aux::mp11_tag>
  94. {
  95. template<class L, class T> struct apply
  96. {
  97. using type = mp11::mp_push_back<L, T>;
  98. };
  99. };
  100. // push_front
  101. template< typename Tag > struct push_front_impl;
  102. template<> struct push_front_impl<aux::mp11_tag>
  103. {
  104. template<class L, class T> struct apply
  105. {
  106. using type = mp11::mp_push_front<L, T>;
  107. };
  108. };
  109. // sequence_tag
  110. template< typename Sequence > struct sequence_tag;
  111. template<class... T> struct sequence_tag<mp11::mp_list<T...>>
  112. {
  113. using type = aux::mp11_tag;
  114. };
  115. template<class... T> struct sequence_tag<std::tuple<T...>>
  116. {
  117. using type = aux::mp11_tag;
  118. };
  119. // size
  120. template< typename Tag > struct size_impl;
  121. template<> struct size_impl<aux::mp11_tag>
  122. {
  123. template<class L> struct apply
  124. {
  125. using type = mp11::mp_size<L>;
  126. };
  127. };
  128. } // namespace mpl
  129. } // namespace boost
  130. #endif // #ifndef BOOST_MP11_MPL_HPP_INCLUDED