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