type_foldl1.hpp 3.8 KB

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