25 # ifndef DSGITALGORITHMS_H 26 # define DSGITALGORITHMS_H 32 template <
typename T>
class DynArray;
35 template <
typename RetT,
class It>
38 template <
typename RetT,
class It>
41 template <
class It,
class Op>
44 template <
class It,
class Op>
45 void for_each_it(
const It &,
const It &, Op && op = Op());
47 template <
class It,
class ContainerRet,
class Pred>
48 ContainerRet
filter_it(
const It &,
const It &, Pred &);
50 template <
class ContainerRet,
class It,
class Pred>
51 ContainerRet
filter_it(
const It &,
const It &, Pred && pred = Pred());
53 template <
class ContainerRet,
class It,
class Op>
54 ContainerRet
map_it(
const It &,
const It &, Op &);
56 template <
class ContainerRet,
class It,
class Op>
57 ContainerRet
map_it(
const It &,
const It &, Op && op = Op());
59 template <
class ContainerRet,
class It,
class Op,
class Pred>
60 ContainerRet
map_if_it(
const It &,
const It &, Op &, Pred &);
62 template <
class ContainerRet,
class It,
class Op,
class Pred>
63 ContainerRet
map_if_it(
const It &,
const It &, Op &, Pred && pred = Pred());
65 template <
class ContainerRet,
class It,
class Op,
class Pred>
66 ContainerRet
map_if_it(
const It &,
const It &, Op &&, Pred &);
68 template <
class ContainerRet,
class It,
class Op,
class Pred>
69 ContainerRet
map_if_it(
const It &,
const It &, Op && op = Op(),
70 Pred && pred = Pred());
72 template <
typename RetT,
class It,
class Pred>
75 template <
typename RetT,
class It,
class Pred>
76 RetT *
search_ptr_it(
const It &,
const It &, Pred && pred = Pred());
78 template <
class It,
class Pred>
79 bool all_it(
const It &,
const It &, Pred &);
81 template <
class It,
class Pred>
82 bool all_it(
const It &,
const It &, Pred && pred = Pred());
84 template <
class It,
class Pred>
85 bool exists_it(
const It &,
const It &, Pred &);
87 template <
class It,
class Pred>
88 bool exists_it(
const It &,
const It &, Pred && pred = Pred());
90 template <
class It,
class Pred>
91 bool none_it(
const It &,
const It &, Pred &);
93 template <
class It,
class Pred>
94 bool none_it(
const It &,
const It &, Pred && pred = Pred());
96 template <
typename RetT,
class It,
class Op>
97 RetT
fold_it(
const It &,
const It &,
const RetT &, Op &);
99 template <
typename RetT,
class It,
class Op>
100 RetT
fold_it(
const It &,
const It &,
const RetT &, Op && op = Op());
102 template <
typename RetT,
class It,
class Op>
103 RetT
fold_it(
const It &,
const It &, RetT &&, Op &);
105 template <
typename RetT,
class It,
class Op>
106 RetT
fold_it(
const It &,
const It &, RetT &&, Op && op = Op());
108 template <
class It,
class Pred>
111 template <
class It,
class Pred>
114 template <
class It,
class Pred>
117 template <
class It,
class Pred>
118 void remove_if_it(
const It &,
const It &, Pred && pred = Pred());
120 template <
class It1,
class It2,
class Eq>
121 bool equal_it(
const It1 &,
const It1 &,
const It2 &,
const It2 &, Eq &);
123 template <
class It1,
class It2,
class Eq>
124 bool equal_it(
const It1 &,
const It1 &,
125 const It2 &,
const It2 &, Eq && eq = Eq());
127 template <
class It,
class Cmp>
130 template <
class It,
class Cmp>
131 bool is_sorted_it(
const It &,
const It &, Cmp && cmp = Cmp());
133 template <
typename T1,
typename T2,
class It1,
class It2>
135 zip_it(
const It1 &,
const It1 &,
const It2 &,
const It2 &);
137 template <
typename T1,
typename T2,
class It1,
class It2>
139 zip_eq_it(
const It1 &,
const It1 &,
const It2 &,
const It2 &);
141 template <
typename T1,
typename T2,
class It1,
class It2>
143 zip_left_it(
const It1 &,
const It1 &,
const It2 &,
const It2 &);
145 template <
typename T1,
typename T2,
class It1,
class It2>
147 zip_right_it(
const It1 &,
const It1 &,
const It2 &,
const It2 &);
149 template <
class ContainerType,
class It>
152 template <
typename T,
class It>
155 template <
typename T,
class It>
158 template <
typename RetT,
class It>
161 for (It i = a; i != b; ++i)
171 template <
typename RetT,
class It>
174 RetT * ret_val = nth_ptr_it<RetT, It>(a, b, pos);
176 if (ret_val ==
nullptr)
177 throw std::overflow_error(
"Index is to large");
182 template <
class It,
class Op>
185 for (It i = a; i != b; ++i)
189 template <
class It,
class Op>
192 for_each_it<It, Op>(a, b, op);
195 template <
class ContainerRet,
class It,
class Pred>
196 ContainerRet
filter_it(
const It & a,
const It & b, Pred & pred)
200 for (It i = a; i != b; ++i)
207 template <
class ContainerRet,
class It,
class Pred>
208 ContainerRet
filter_it(
const It & a,
const It & b, Pred && pred)
210 return filter_it<ContainerRet, It, Pred>(a, b, pred);
213 template <
class ContainerRet,
class It,
class Op>
214 ContainerRet
map_it(
const It & a,
const It & b, Op & op)
218 for (It i = a; i != b; ++i)
224 template <
class ContainerRet,
class It,
class Op>
225 ContainerRet
map_it(
const It & a,
const It & b, Op && op)
227 return map_it<ContainerRet, It, Op>(a, b, op);
230 template <
class ContainerRet,
class It,
class Op,
class Pred>
231 ContainerRet
map_if_it(
const It & a,
const It & b, Op & op, Pred & pred)
235 for (It i = a; i != b; ++i)
242 template <
class ContainerRet,
class It,
class Op,
class Pred>
243 ContainerRet
map_if_it(
const It & a,
const It & b, Op & op, Pred && pred)
245 return map_if_it<ContainerRet, It, Op, Pred>(a, b, op, pred);
248 template <
class ContainerRet,
class It,
class Op,
class Pred>
249 ContainerRet
map_if_it(
const It & a,
const It & b, Op && op, Pred & pred)
251 return map_if_it<ContainerRet, It, Op, Pred>(a, b, op, pred);
254 template <
class ContainerRet,
class It,
class Op,
class Pred>
255 ContainerRet
map_if_it(
const It & a,
const It & b, Op && op, Pred && pred)
257 return map_if_it<ContainerRet, It, Op, Pred>(a, b, op, pred);
260 template <
typename RetT,
class It,
class Op>
261 RetT
fold_it(
const It & a,
const It & b,
const RetT & init_value, Op & op)
263 RetT ret_val = init_value;
265 for (It i = a; i != b; ++i)
266 ret_val = op(*i, ret_val);
271 template <
typename RetT,
class It,
class Op>
272 RetT
fold_it(
const It & a,
const It & b,
const RetT & init_value, Op && op)
274 return fold_it<RetT, It, Op>(a, b, init_value, op);
277 template <
typename RetT,
class It,
class Op>
278 RetT
fold_it(
const It & a,
const It & b, RetT && init_value, Op & op)
280 RetT ret_val = std::move(init_value);
282 for (It i = a; i != b; ++i)
283 ret_val = op(*i, ret_val);
288 template <
typename RetT,
class It,
class Op>
289 RetT
fold_it(
const It & a,
const It & b, RetT && init_value, Op && op)
291 return fold_it<RetT, It, Op>(a, b, std::forward<RetT>(init_value), op);
294 template <
class It,
class Pred>
295 bool all_it(
const It & a,
const It & b, Pred & pred)
297 for (It i = a; i != b; ++i)
303 template <
class It,
class Pred>
304 bool all_it(
const It & a,
const It & b, Pred && pred)
306 return all_it<It, Pred>(a, b, pred);
309 template <
class It,
class Pred>
312 for (It i = a; i != b; ++i)
318 template <
class It,
class Pred>
319 bool exists_it(
const It & a,
const It & b, Pred && pred)
321 return exists_it<It, Pred>(a, b, pred);
324 template <
class It,
class Pred>
325 bool none_it(
const It & a,
const It & b, Pred & pred)
327 for (It i = a; i != b; ++i)
333 template <
class It,
class Pred>
334 bool none_it(
const It & a,
const It & b, Pred && pred)
336 return none_it<It, Pred>(a, b, pred);
339 template <
typename RetT,
class It,
class Pred>
342 for (It i = a; i != b; ++i)
349 template <
typename RetT,
class It,
class Pred>
352 return search_ptr_it<RetT, It, Pred>(a, b, pred);
355 template <
class It,
class Pred>
358 for (It i = a; i != b; ++i)
368 template <
class It,
class Pred>
371 return remove_first_if_it<It, Pred>(a, b, pred);
374 template <
class It,
class Pred>
377 for (It i = a; i != b; )
384 template <
class It,
class Pred>
387 remove_if_it<It, Pred>(a, b, pred);
390 template <
class It1,
class It2,
class Eq>
392 const It2 & a2,
const It2 & b2, Eq & eq)
397 for ( ; i1 != b1 and i2 != b2; ++i1, ++i2)
398 if (not eq(*i1, *i2))
401 return (i1 == b1 and i2 == b2);
404 template <
class It1,
class It2,
class Eq>
406 const It2 & a2,
const It2 & b2, Eq && eq)
408 return equal_it<It1, It2, Eq>(a1, b1, a2, b2, eq);
411 template <
class It,
class Cmp>
421 for ( ; j != b; ++i, ++j)
428 template <
class It,
class Cmp>
431 return is_sorted_it<It, Cmp>(a, b, cmp);
434 template <
typename T1,
typename T2,
class It1,
class It2>
436 zip_it(
const It1 & a1,
const It1 & b1,
const It2 & a2,
const It2 & b2)
443 for ( ; i1 != b1 and i2 != b2; ++i1, ++i2)
444 ret.
append(std::make_pair(*i1, *i2));
449 template <
typename T1,
typename T2,
class It1,
class It2>
451 zip_eq_it(
const It1 & a1,
const It1 & b1,
const It2 & a2,
const It2 & b2)
458 for ( ; i1 != b1 and i2 != b2; ++i1, ++i2)
459 ret.
append(std::make_pair(*i1, *i2));
461 if (i1 != b1 or i2 != b2)
462 throw std::length_error(
"Container sizes mismatch");
467 template <
typename T1,
typename T2,
class It1,
class It2>
469 zip_left_it(
const It1 & a1,
const It1 & b1,
const It2 & a2,
const It2 & b2)
476 for ( ; i1 != b1; ++i1)
478 ret.
append(std::make_pair(*i1, *i2));
489 template <
typename T1,
typename T2,
class It1,
class It2>
491 zip_right_it(
const It1 & a1,
const It1 & b1,
const It2 & a2,
const It2 & b2)
498 for ( ; i2 != b2; ++i2)
500 ret.
append(std::make_pair(*i1, *i2));
511 template <
class ContainerType,
class It>
516 for (It i = a; i != b; ++i)
522 template <
typename T,
class It>
525 return to_container<SLList<T>, It>(a, b);
528 template <
typename T,
class It>
531 return to_container<DynArray<T>, It>(a, b);
536 # endif // DSGITALGORITHMS_H SLList< std::pair< T1, T2 > > zip_left_it(const It1 &, const It1 &, const It2 &, const It2 &)
Definition: italgorithms.H:469
RetT * nth_ptr_it(const It &, const It &, nat_t)
Definition: italgorithms.H:159
T & append(const T &item)
Definition: list.H:265
bool none_it(const It &, const It &, Pred &)
Definition: italgorithms.H:325
DynArray< T > to_array_it(const It &, const It &)
Definition: italgorithms.H:529
bool equal_it(const It1 &, const It1 &, const It2 &, const It2 &, Eq &)
Definition: italgorithms.H:391
ContainerRet filter_it(const It &, const It &, Pred &)
Definition: italgorithms.H:196
ContainerRet map_if_it(const It &, const It &, Op &, Pred &)
Definition: italgorithms.H:231
RetT & nth_it(const It &, const It &, nat_t)
Definition: italgorithms.H:172
RetT fold_it(const It &, const It &, const RetT &, Op &)
Definition: italgorithms.H:261
SLList< std::pair< T1, T2 > > zip_eq_it(const It1 &, const It1 &, const It2 &, const It2 &)
Definition: italgorithms.H:451
bool exists_it(const It &, const It &, Pred &)
Definition: italgorithms.H:310
void for_each_it(const It &, const It &, Op &)
Definition: italgorithms.H:183
bool is_sorted_it(const It &, const It &, Cmp &)
Definition: italgorithms.H:412
Definition: italgorithms.H:33
ContainerType to_container(const It &, const It &)
Definition: italgorithms.H:512
SLList< std::pair< T1, T2 > > zip_it(const It1 &, const It1 &, const It2 &, const It2 &)
Definition: italgorithms.H:436
void remove_if_it(const It &, const It &, Pred &)
Definition: italgorithms.H:375
SLList< T > to_list_it(const It &, const It &)
Definition: italgorithms.H:523
ContainerRet map_it(const It &, const It &, Op &)
Definition: italgorithms.H:214
bool remove_first_if_it(const It &, const It &, Pred &)
Definition: italgorithms.H:356
unsigned long int nat_t
Definition: types.H:50
SLList< std::pair< T1, T2 > > zip_right_it(const It1 &, const It1 &, const It2 &, const It2 &)
Definition: italgorithms.H:491
RetT * search_ptr_it(const It &, const It &, Pred &)
Definition: italgorithms.H:340
bool all_it(const It &, const It &, Pred &)
Definition: italgorithms.H:295