type_foldr1.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*!
  2. @file
  3. Defines `boost::hana::detail::type_foldr1`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_DETAIL_TYPE_FOLDR1_HPP
  9. #define BOOST_HANA_DETAIL_TYPE_FOLDR1_HPP
  10. #include <boost/hana/config.hpp>
  11. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  12. template <unsigned n>
  13. struct type_foldr1_t;
  14. template <>
  15. struct type_foldr1_t<0> {
  16. template <
  17. template <typename ...> class f,
  18. typename state
  19. >
  20. using result = state;
  21. };
  22. template <>
  23. struct type_foldr1_t<1> {
  24. template <
  25. template <typename ...> class f,
  26. typename x1,
  27. typename state
  28. >
  29. using result = typename f<x1, state>::type;
  30. };
  31. template <>
  32. struct type_foldr1_t<2> {
  33. template <
  34. template <typename ...> class f,
  35. typename x1, typename x2,
  36. typename state
  37. >
  38. using result = typename f<x1, typename f<x2, state>::type>::type;
  39. };
  40. template <>
  41. struct type_foldr1_t<3> {
  42. template <
  43. template <typename ...> class f,
  44. typename x1, typename x2, typename x3,
  45. typename state
  46. >
  47. using result = typename f<
  48. x1,
  49. typename f<
  50. x2,
  51. typename f<
  52. x3,
  53. state
  54. >::type
  55. >::type
  56. >::type;
  57. };
  58. template <>
  59. struct type_foldr1_t<4> {
  60. template <
  61. template <typename ...> class f,
  62. typename x1, typename x2, typename x3, typename x4,
  63. typename state
  64. >
  65. using result = typename f<
  66. x1,
  67. typename f<
  68. x2,
  69. typename f<
  70. x3,
  71. typename f<
  72. x4,
  73. state
  74. >::type
  75. >::type
  76. >::type
  77. >::type;
  78. };
  79. template <>
  80. struct type_foldr1_t<5> {
  81. template <
  82. template <typename ...> class f,
  83. typename x1, typename x2, typename x3, typename x4, typename x5,
  84. typename state
  85. >
  86. using result = typename f<
  87. x1,
  88. typename f<
  89. x2,
  90. typename f<
  91. x3,
  92. typename f<
  93. x4,
  94. typename f<
  95. x5,
  96. state
  97. >::type
  98. >::type
  99. >::type
  100. >::type
  101. >::type;
  102. };
  103. template <>
  104. struct type_foldr1_t<6> {
  105. template <
  106. template <typename ...> class f,
  107. typename x1, typename x2, typename x3, typename x4, typename x5, typename x6,
  108. typename ...xs
  109. >
  110. using result =
  111. typename f<
  112. x1,
  113. typename f<
  114. x2,
  115. typename f<
  116. x3,
  117. typename f<
  118. x4,
  119. typename f<
  120. x5,
  121. typename type_foldr1_t<(sizeof...(xs) > 6 ? 6 : sizeof...(xs))>::
  122. template result<f, x6, xs...>
  123. >::type
  124. >::type
  125. >::type
  126. >::type
  127. >::type;
  128. };
  129. template <template <typename ...> class f, typename x1, typename ...xn>
  130. struct type_foldr1 {
  131. using type = typename type_foldr1_t<(sizeof...(xn) > 6 ? 6 : sizeof...(xn))>
  132. ::template result<f, x1, xn...>;
  133. };
  134. } BOOST_HANA_NAMESPACE_END
  135. #endif // !BOOST_HANA_DETAIL_TYPE_FOLDR1_HPP