25 #ifndef ALGORITHM_HPP_INCLUDED
26 #define ALGORITHM_HPP_INCLUDED
35 #include <type_traits>
48 template <
class Beg,
class End,
class Init,
class Fun >
49 struct accumulate_impl : accumulate_impl<
50 typename next<Beg>::type,
52 typename apply<Fun, Init, typename deref<Beg>::type>::type,
59 template <
class End,
class Init,
class Fun>
60 struct accumulate_impl<End, End, Init, Fun>
72 template <
class Seq,
class Init,
class Fun = tmp::plus<_1,_2> >
74 typename begin<Seq>::type,
75 typename end<Seq>::type,
87 typename deref<typename begin<Seq>::type>::type,
88 if_<less<_1,_2>,_1,_2>
98 typename deref<typename begin<Seq>::type>::type,
99 if_<less<_1,_2>,_2,_1>
107 template <
class A,
class B>
110 struct type :
public A,
public B {};
114 struct inheriter<empty, B>
116 struct type :
public B {};
128 internal::inheriter<_1,_2>
140 template <
class Beg,
class End,
class Ins,
class Trans>
141 struct transform_impl : transform_impl<
142 typename next<Beg>::type,
146 typename Ins::operation,
150 typename deref<Beg>::type
153 typename Ins::operation
161 template <
class End,
class Ins,
class Trans>
162 struct transform_impl<End, End, Ins, Trans>
164 typedef typename Ins::state type;
175 template <
class Beg,
class End,
class Ins,
class Cond,
class Trans>
176 struct transform_if_ptr_impl : transform_if_ptr_impl<
177 typename next<Beg>::type,
180 typename std::conditional<
181 apply<Cond, Beg>::type::value,
183 typename Ins::operation,
185 typename apply<Trans, Beg>::type
189 typename Ins::operation
198 template <
class End,
class Ins,
class Cond,
class Trans>
199 struct transform_if_ptr_impl<End, End, Ins, Cond, Trans>
201 typedef typename Ins::state type;
211 template <
class Seq,
class Ins,
class Trans>
213 typename begin<Seq>::type,
214 typename end<Seq>::type,
226 template <
class Seq,
class Ins,
class Cond,
class Trans>
228 typename begin<Seq>::type,
229 typename end<Seq>::type,
240 template <
class Seq,
class Ins>
248 template <
class Seq,
class Ins,
class Cond>
256 template <
class Seq1,
class Seq2>
259 inserter<Seq1, push_back<_1, _2> >,
270 typename empty<Seq>::type,
276 template <
class Beg,
class End,
class Elem>
277 struct find_impl : std::conditional<
278 std::is_same<typename deref<Beg>::type, Elem>::type::value,
280 typename find_impl<typename next<Beg>::type, End, Elem>::type
283 template <
class End,
class Elem>
284 struct find_impl<End, End, Elem>
297 template <
class Seq,
class Elem>
298 struct find : internal::find_impl<
299 typename begin<Seq>::type,
300 typename end<Seq>::type,
310 template <
class Seq,
class Elem>
312 typename std::is_same<
313 typename find<Seq, Elem>::type,
314 typename end<Seq>::type
326 typename empty<Seq>::type,
327 if_<is_member<_1,_2>, _1, push_back<_1,_2> >
333 template <
class first,
class second,
class condition>
337 template <
class first,
class second>
338 struct swap_if<first, second, std::false_type>
340 typedef first first_t;
341 typedef second second_t;
345 template <
class first,
class second>
346 struct swap_if<first, second, std::true_type>
348 typedef second first_t;
349 typedef first second_t;
353 class Seq,
class Compare,
354 class siz =
typename less<integer<int, 1>,
typename size<Seq>::type>::type
359 typedef typename deref<typename begin<Seq>::type>::type first_t;
360 typedef typename deref<
361 typename begin<typename pop_front<Seq>::type>::type
363 typedef typename pop_front<typename pop_front<Seq>::type>::type trunc;
365 typedef typename apply<Compare, first_t, second_t>::type cond;
366 typedef typename swap_if<first_t, second_t, cond>::first_t new_first;
367 typedef typename swap_if<first_t, second_t, cond>::second_t new_second;
369 typedef typename push_front<trunc, new_second>::type processed;
371 typedef typename push_front<
372 typename bubble_cycle<processed, Compare>::type,
377 template <
class Seq,
class Compare>
378 struct bubble_cycle<Seq, Compare, std::false_type> : Seq {};
387 class Compare = less<_2, _1>,
388 class cnt =
typename size<Seq>::type
391 typename internal::bubble_cycle<Seq, Compare>::type,
393 typename prev<cnt>::type
397 template <
class Seq,
class Compare>
403 template <
class value,
unsigned N,
class Seq>
404 struct constant_sequence_impl :
push_back<
405 typename constant_sequence_impl<
411 template <
class value,
class Seq>
412 struct constant_sequence_impl<value, 0, Seq>
419 template <
class value,
unsigned N,
class Seq>
421 value, N, typename empty<Seq>::type
427 template <
class T,
int increment>
428 struct increment_type;
430 template <
class T,
int increment, T val>
431 struct increment_type<std::integral_constant<T, val>, increment>
432 :
public std::integral_constant<T, val + increment> {};
434 template <
class value,
unsigned N,
class Seq,
int increment>
435 struct arithmetic_sequence_impl : push_front<
436 typename arithmetic_sequence_impl<
437 typename increment_type<value, increment>::type, N-1, Seq, increment
442 template <
class value,
class Seq,
int increment>
443 struct arithmetic_sequence_impl<value, 0, Seq, increment>
456 template <
class value,
unsigned N,
class Seq,
int increment = 1>
458 value, N, typename empty<Seq>::type, increment