12 #ifndef BOOST_MPL11_LIST_HPP
13 #define BOOST_MPL11_LIST_HPP
33 namespace boost {
namespace mpl11 {
34 template <
typename ...xs>
37 using mpl_datatype = List;
40 template <
typename x,
typename xs>
43 using mpl_datatype = List;
47 struct Iterable<List> : instantiate<Iterable>::with<List> {
51 template <
typename x,
typename xs>
52 struct head_impl<cons<x, xs>>
56 template <
typename x,
typename ...xs>
57 struct head_impl<list<x, xs...>>
65 template <
typename x,
typename xs>
66 struct tail_impl<cons<x, xs>>
70 template <
typename x,
typename ...xs>
71 struct tail_impl<list<x, xs...>>
76 template <
typename n,
typename self>
78 : instantiate<mpl11::Iterable>::with<List>::at_impl<n, self>
81 template <
typename n,
typename ...xs>
82 struct at_impl<n, list<xs...>>
83 : detail::at_index::best<n::type::value, xs...>
88 struct is_empty_impl : false_ { };
92 struct Iterable<List>::is_empty_impl<list<>> : true_ { };
96 struct Functor<List> : instantiate<Functor>::with<List> {
97 template <
typename f,
typename xs>
100 template <
typename f,
typename ...xs>
101 struct fmap_impl<f, list<xs...>> {
102 using type = list<typename f::type::template apply<xs>...>;
105 template <
typename f,
typename x,
typename xs>
106 struct fmap_impl<f, cons<x, xs>> {
108 typename f::type::template
apply<x>,
114 template <
typename f,
typename x>
116 : cons<x, iterate<f, typename f::type::template apply<x>>>
119 template <
typename x>
124 namespace list_detail {
125 template <detail::std_size_t n,
typename xs,
126 bool = n == 0 || is_empty<xs>::value>
131 template <detail::std_
size_t n,
typename xs>
132 struct take_impl<n, xs, false>
133 : cons<head<xs>, take_impl<n-1, tail<xs>>>
136 template <
typename n,
typename xs>
138 static_assert(n::type::value >= 0,
139 "Invalid usage of `take`: "
140 "The number of elements to take must be non-negative.");
143 template <
typename xs,
typename from,
typename to>
144 struct slice_checks {
146 static constexpr
auto start = from::type::value;
147 static constexpr
auto stop = to::type::value;
149 static_assert(start >= 0,
150 "Invalid usage of `slice`: The start index must be non-negative.");
152 static_assert(start <= stop,
153 "Invalid usage of `slice`: "
154 "The start index must be less-than or equal to the stop index.");
157 using Length = if_c<sequence_traits<typename Iter::type>::is_finite,
162 static_assert(Stop <= Length::value,
163 "Invalid usage of `slice`: "
164 "The stop index is out of the bounds of the iterable.");
168 template <
typename xs>
170 static_assert(!is_empty<xs>::value,
171 "Invalid usage of `init` on an empty list.");
175 template <
typename n,
typename xs>
178 list_detail::take_impl<n::type::value, xs>
181 template <
typename xs,
typename from,
typename to>
184 take_c<to::type::value - from::type::value, drop<from, xs>>
187 template <
typename xs>
190 if_c<is_empty<tail<xs>>::value,
192 cons<head<xs>, init<tail<xs>>>
196 namespace list_detail {
197 template <
typename pred>
198 struct take_while_op {
199 using type = take_while_op;
200 template <
typename x,
typename xs>
208 template <
typename pred>
210 using type = filter_op;
211 template <
typename x,
typename xs>
220 template <
typename f,
typename state,
typename xs>
222 : if_c<is_empty<xs>::value,
226 scanl<f, apply<f, state, head<xs>>, tail<xs>>
231 template <
typename f>
236 template <
typename f,
typename xs>
237 struct zip_with<f, xs>
241 template <
typename f,
typename ...lists>
243 : if_<or_<is_empty<lists>...>,
246 typename f::type::template apply<head<lists>...>,
247 zip_with<f, tail<lists>...>
252 template <
typename ...xs>
254 : foldr<lift<concat>, list<>, list<xs...>>
257 template <
typename xs,
typename ys>
258 struct concat<xs, ys>
259 : foldr<lift<cons>, ys, xs>
262 namespace list_detail {
266 typename pivot = head<xs>,
267 typename rest = tail<xs>,
268 typename IsGreater = partial<pred, pivot>,
269 typename IsSmallerEq = compose<lift<not_>, IsGreater>,
270 typename SmallerEq = filter<IsSmallerEq, rest>,
271 typename Greater = filter<IsGreater, rest>
273 using sort_by_impl = concat<
274 sort_by<pred, SmallerEq>,
275 cons<pivot, sort_by<pred, Greater>>
279 template <
typename pred,
typename xs>
281 : if_c<or_<is_empty<xs>, is_empty<tail<xs>>>::value,
283 list_detail::sort_by_impl<pred, xs>
287 #ifndef BOOST_MPL11_NO_REWRITE_RULES
288 template <
typename f,
typename state,
typename ...xs>
289 struct foldl<f, state, list<xs...>>
290 : detail::left_folds::variadic<
291 f::type::template apply, state, xs...
295 template <
typename f,
typename state,
typename ...xs>
296 struct foldr<f, state, list<xs...>>
297 : detail::right_folds::variadic<
298 f::type::template apply, state, xs...
305 template <
typename ...xs,
typename ys>
306 struct length<foldr<lift<cons>, list<xs...>, ys>>
307 : size_t<length<ys>::value + sizeof...(xs)>
311 template <
typename index,
typename x>
312 struct at<index, repeat<x>> : x { };
313 #endif // end rewrite rules
316 #endif // !BOOST_MPL11_LIST_HPP
Defines the Integer datatype.
Defines the Iterable typeclass.
Manages configurable options of the library and defines utility macros.
Defines boost::mpl11::detail::std_size_t.
Defines boost::mpl11::detail::right_folds::variadic.
Defines the fmap method of the Functor typeclass.
Defines the Logical module.
Defines boost::mpl11::detail::left_folds::variadic.
#define BOOST_MPL11_IF_ASSERTIONS(...)
Macro expanding to its argument(s) if BOOST_MPL11_NO_ASSERTIONS is not defined, and to nothing otherw...
Definition: config.hpp:72
Invokes a metafunction class with the given arguments.
Definition: functional.hpp:39
Forward declares the boost::mpl11::List datatype.
Forwards to boost/mpl11/integer.hpp.
Defines the methods of the Foldable typeclass.
Defines the Functional module.
Defines boost::mpl11::detail::at_index::best.