12 #ifndef BOOST_MPL11_ITERABLE_HPP
13 #define BOOST_MPL11_ITERABLE_HPP
31 namespace boost {
namespace mpl11 {
32 namespace iterable_detail {
33 template <detail::std_size_t n,
typename iter,
34 bool = n == 0 || is_empty<iter>::value>
37 template <detail::std_
size_t n,
typename iter>
38 struct drop_impl<n, iter, true> : iter { };
40 template <detail::std_
size_t n,
typename iter>
41 struct drop_impl<n, iter, false>
42 : drop_impl<n-1, tail<iter>>
45 template <
typename iter>
47 static_assert(!is_empty<iter>::value,
48 "Invalid usage of `head` on an empty iterable.");
51 template <
typename iter>
53 static_assert(!is_empty<iter>::value,
54 "Invalid usage of `tail` on an empty iterable.");
57 template <
typename iter>
59 static_assert(!is_empty<iter>::value,
60 "Invalid usage of `last` on an empty iterable.");
63 template <
typename index,
typename iter>
65 static_assert(index::type::value >= 0,
66 "Invalid usage of `at` with a negative index.");
69 using Length = if_c<sequence_traits<typename Iter::type>::is_finite,
71 size_t<index::type::value + 1>
74 static_assert(index::type::value < Length::value,
75 "Invalid usage of `at` with an out-of-bounds index.");
79 template <
typename n,
typename iter>
81 static_assert(n::type::value >= 0,
82 "Invalid usage of `drop`: "
83 "The number of elements to drop must be non-negative.");
87 struct drop_while_pred {
88 using type = drop_while_pred;
89 template <
typename xs>
92 not_<typename p::type::template apply<head<xs>>>
97 template <
typename pred,
typename iterable>
99 : detail::left_folds::until<
100 iterable_detail::drop_while_pred<pred>::type::template apply
101 , bind<lift<tail>, arg<1>>::type::template apply
107 template <
typename iter>
110 Iterable<typename datatype<typename iter::type>::type>::
111 template head_impl<typename iter::type>
114 template <
typename iter>
117 Iterable<typename datatype<typename iter::type>::type>::
118 template tail_impl<typename iter::type>
121 template <
typename iter>
124 Iterable<typename datatype<typename iter::type>::type>::
125 template last_impl<typename iter::type>
128 template <
typename index,
typename iter>
131 Iterable<typename datatype<typename iter::type>::type>::
132 template at_impl<index, typename iter::type>
135 template <
typename n,
typename iter>
138 iterable_detail::drop_impl<n::type::value, iter>
141 template <
typename iter>
143 Iterable<typename datatype<typename iter::type>::type>::
144 template is_empty_impl<typename iter::type>
147 template <
typename iter>
149 Iterable<typename datatype<typename iter::type>::type>::
150 template length_impl<typename iter::type>
153 template <
typename Datatype,
typename>
154 struct Iterable : false_ { };
156 namespace iterable_detail {
160 template <
typename x,
typename _>
167 template <
typename Datatype>
168 struct with :
true_ {
169 template <
typename xs>
172 template <
typename index,
typename xs,
bool = index::type::value == 0>
177 template <
typename index,
typename xs>
178 struct at_impl<index, xs, false>
180 size_t<index::type::value - 1>,
181 typename tail<box<xs>>::type
185 template <
typename xs>
186 using length_impl = foldl<iterable_detail::plus_one, int_<0>, box<xs>>;
190 template <
typename X,
typename Y>
191 struct Orderable<X, Y, bool_<Iterable<X>::value && Iterable<Y>::value>>
192 : instantiate<Orderable>::template with<X, Y>
195 template <
typename xs,
typename ys,
196 bool xs_done = is_empty<box<xs>>::value,
197 bool ys_done = is_empty<box<ys>>::value
200 : bool_<xs_done && !ys_done>
204 template <
typename xs,
typename ys>
205 struct less_impl<xs, ys, false, false>
207 less<head<box<xs>>, head<box<ys>>>,
209 not_<less<head<box<ys>>, head<box<xs>>>>,
211 typename tail<box<xs>>::type,
212 typename tail<box<ys>>::type
219 template <
typename X,
typename Y>
220 struct Comparable<X, Y, bool_<Iterable<X>::value && Iterable<Y>::value>>
221 : instantiate<Comparable>::template with<X, Y>
223 template <
typename xs,
typename ys,
224 bool xs_done = is_empty<box<xs>>::value,
225 bool ys_done = is_empty<box<ys>>::value>
227 : bool_<xs_done && ys_done>
230 template <
typename xs,
typename ys>
231 struct equal_impl<xs, ys, false, false>
233 equal<head<box<xs>>, head<box<ys>>>,
235 typename tail<box<xs>>::type,
236 typename tail<box<ys>>::type
242 template <
typename Datatype>
243 struct Foldable<Datatype, typename Iterable<Datatype>::type>
244 : instantiate<Foldable>::template with<Datatype>
246 template <
typename f,
typename state,
typename iterable>
247 using foldl_impl = detail::left_folds::until<
248 is_empty, f::type::template
apply, state, box<iterable>
251 template <
typename f,
typename iterable>
252 using foldl1_impl = detail::left_folds::until<
254 f::type::template
apply,
259 template <
typename f,
typename state,
typename iterable>
260 using foldr_impl = detail::right_folds::until<
261 is_empty, f::type::template
apply, state, box<iterable>
266 #endif // !BOOST_MPL11_ITERABLE_HPP
Boxes its argument.
Definition: core.hpp:46
Defines the Integer datatype.
Holds default methods of typeclasses.
Definition: core.hpp:37
Defines the Comparable typeclass.
Defines boost::mpl11::detail::left_folds::until.
Manages configurable options of the library and defines utility macros.
Defines boost::mpl11::detail::std_size_t.
Defines the Logical module.
Definition: iterable.hpp:158
Forward declares the Iterable typeclass.
Represents the bottom value of most functional programming languages.
Definition: core.hpp:87
#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
Returns the first element of a non-empty iterable.
Definition: iterable.hpp:72
Defines boost::mpl11::detail::right_folds::until.
Invokes a metafunction class with the given arguments.
Definition: functional.hpp:39
Defines the Orderable typeclass.
Alias to bool_; provided for convenience.
Definition: integer.hpp:79
Left-associative fold of a structure using a binary operation.
Definition: foldable.hpp:62
Forwards to boost/mpl11/integer.hpp.
Defines the methods of the Foldable typeclass.
Returns the successor of the given object.
Definition: enumerable.hpp:22
Defines the Functional module.