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