25 # ifndef DSGCONTAINERALGORITHMS_H 26 # define DSGCONTAINERALGORITHMS_H 32 template<
class ContainerType,
typename T>
37 return *
static_cast<ContainerType *
>(
this);
40 const ContainerType & const_me()
const 42 return *
static_cast<const ContainerType *
>(
this);
48 return nth_ptr_it<T>(me().begin(), me().end(), i);
53 return nth_it<T>(me().begin(), me().end(), i);
58 return nth_it(const_me().begin(), const_me().end(), i);
64 for_each_it(const_me().begin(), const_me().end(), op);
70 for_each_it(const_me().begin(), const_me().end(), std::forward<Op>(op));
73 template <
class ContainerRet,
class Pred>
74 ContainerRet
filter(Pred & pred)
const 76 return filter_it<ContainerRet>(const_me().begin(), const_me().end(),
80 template <
class ContainerRet = SLList<T>,
class Pred>
81 ContainerRet
filter(Pred && pred = Pred())
const 83 return filter_it<ContainerRet>(const_me().begin(), const_me().end(),
84 std::forward<Pred>(pred));
87 template <
typename RetT = T,
class ContainerRet = SLList<RetT>,
class Op>
88 ContainerRet
map(Op & op)
const 90 return map_it<ContainerRet>(const_me().begin(), const_me().end(), op);
93 template <
class RetT = T,
class ContainerRet = SLList<RetT>,
class Op>
94 ContainerRet
map(Op && op = Op())
const 96 return map_it<ContainerRet>(const_me().begin(), const_me().end(),
97 std::forward<Op>(op));
100 template <
class RetT = T,
class ContainerRet = SLList<RetT>,
101 class Op,
class Pred>
102 ContainerRet
map_if(Op & op, Pred & pred)
const 104 return map_if_it<ContainerRet>(const_me().begin(), const_me().end(),
108 template <
class RetT = T,
class ContainerRet = SLList<RetT>,
109 class Op,
class Pred>
110 ContainerRet
map_if(Op & op, Pred && pred = Pred())
const 112 return map_if_it<ContainerRet>(const_me().begin(), const_me().end(),
113 op, std::forward<Pred>(pred));
116 template <
class RetT = T,
class ContainerRet = SLList<RetT>,
117 class Op,
class Pred>
118 ContainerRet
map_if(Op && op, Pred & pred)
const 120 return map_if_it<ContainerRet>(const_me().begin(), const_me().end(),
121 std::forward<Op>(op), pred);
124 template <
typename RetT = T,
class ContainerRet = SLList<RetT>,
125 class Op,
class Pred>
126 ContainerRet
map_if(Op && op = Op(), Pred && pred = Pred())
const 128 return map_if_it<ContainerRet>(const_me().begin(), const_me().end(),
129 std::forward<Op>(op),
130 std::forward<Pred>(pred));
133 template <
typename RetT = T,
class Op>
134 RetT
fold(
const RetT & init_val, Op & op)
const 136 return fold_it<RetT>(const_me().begin(), const_me().end(), init_val, op);
139 template <
typename RetT = T,
class Op>
140 RetT
fold(
const RetT & init_val, Op && op = Op())
const 142 return fold_it<RetT>(const_me().begin(), const_me().end(), init_val,
143 std::forward<Op>(op));
146 template <
typename RetT = T,
class Op>
147 RetT
fold(RetT && init_val, Op & op)
const 149 return fold_it<RetT>(const_me().begin(), const_me().end(),
150 std::forward<RetT>(init_val), op);
153 template <
typename RetT = T,
class Op>
154 RetT
fold(RetT && init_val, Op && op = Op())
const 156 return fold_it<RetT>(const_me().begin(), const_me().end(),
157 std::forward<RetT>(init_val), std::forward<Op>(op));
160 template <
class Pred>
161 bool all(Pred & pred)
const 163 return all_it(const_me().begin(), const_me().end(), pred);
166 template <
class Pred>
167 bool all(Pred && pred = Pred())
const 169 return all_it(const_me().begin(), const_me().end(),
170 std::forward<Pred>(pred));
173 template <
class Pred>
176 return exists_it(const_me().begin(), const_me().end(), pred);
179 template <
class Pred>
182 return exists_it(const_me().begin(), const_me().end(),
183 std::forward<Pred>(pred));
186 template <
class Pred>
189 return none_it(const_me().begin(), const_me().end(), pred);
192 template <
class Pred>
193 bool none(Pred && pred = Pred())
const 195 return none_it(const_me().begin(), const_me().end(),
196 std::forward<Pred>(pred));
199 template <
class Pred>
202 return search_ptr_it<T>(const_me().begin(), const_me().end(), pred);
205 template <
class Pred>
208 return search_ptr_it<T>(const_me().begin(), const_me().end(),
209 std::forward<Pred>(pred));
212 template <
class Pred>
218 template <
class Pred>
222 std::forward<Pred>(pred));
225 template <
class Pred>
231 template <
class Pred>
234 remove_if_it(me().begin(), me().end(), std::forward<Pred>(pred));
237 template <
class ContainerType2 = ContainerType,
class Eq>
238 bool equal(
const ContainerType2 & c, Eq & eq)
const 240 return equal_it(const_me().begin(), const_me().end(),
241 c.begin(), c.end(), eq);
244 template <
class ContainerType2 = ContainerType,
class Eq = std::equal_to<T>>
245 bool equal(
const ContainerType2 & c, Eq && eq = Eq())
const 247 return equal_it(const_me().begin(), const_me().end(),
248 c.begin(), c.end(), std::forward<Eq>(eq));
254 return is_sorted_it(const_me().begin(), const_me().end(), cmp);
257 template <
class Cmp = std::less<T>>
260 return is_sorted_it(const_me().begin(), const_me().end(),
261 std::forward<Cmp>(cmp));
264 template <
class ContainerType2 = ContainerType>
266 zip(
const ContainerType2 & c)
const 268 using T2 =
typename ContainerType2::KeyType;
270 return zip_it<T, T2>(const_me().begin(), const_me().end(),
274 template <
class ContainerType2 = ContainerType>
278 using T2 =
typename ContainerType2::KeyType;
280 return zip_eq_it<T, T2>(const_me().begin(), const_me().end(),
284 template <
class ContainerType2 = ContainerType>
288 using T2 =
typename ContainerType2::KeyType;
290 return zip_left_it<T, T2>(const_me().begin(), const_me().end(),
294 template <
class ContainerType2 = ContainerType>
298 using T2 =
typename ContainerType2::KeyType;
300 return zip_right_it<T, T2>(const_me().begin(), const_me().end(),
306 return to_array_it<T>(const_me().begin(), const_me().end());
311 return to_list_it<T>(const_me().begin(), const_me().end());
317 # endif // DSGCONTAINERALGORITHMS_H SLList< T > to_list() const
Definition: containeralgorithms.H:309
T * search_ptr(Pred &&pred=Pred()) const
Definition: containeralgorithms.H:206
RetT fold(const RetT &init_val, Op &&op=Op()) const
Definition: containeralgorithms.H:140
SLList< std::pair< T, typename ContainerType2::KeyType > > zip(const ContainerType2 &c) const
Definition: containeralgorithms.H:266
RetT fold(RetT &&init_val, Op &op) const
Definition: containeralgorithms.H:147
bool none(Pred &&pred=Pred()) const
Definition: containeralgorithms.H:193
bool none_it(const It &, const It &, Pred &)
Definition: italgorithms.H:325
T * nth_ptr(nat_t i)
Definition: containeralgorithms.H:46
bool equal(const ContainerType2 &c, Eq &eq) const
Definition: containeralgorithms.H:238
bool exists(Pred &pred) const
Definition: containeralgorithms.H:174
bool none(Pred &pred) const
Definition: containeralgorithms.H:187
T & nth(nat_t i)
Definition: containeralgorithms.H:51
void for_each(Op &op) const
Definition: containeralgorithms.H:62
void remove_if(Pred &pred)
Definition: containeralgorithms.H:226
bool exists(Pred &&pred=Pred()) const
Definition: containeralgorithms.H:180
bool equal_it(const It1 &, const It1 &, const It2 &, const It2 &, Eq &)
Definition: italgorithms.H:391
bool equal(const ContainerType2 &c, Eq &&eq=Eq()) const
Definition: containeralgorithms.H:245
ContainerRet map_if(Op &op, Pred &&pred=Pred()) const
Definition: containeralgorithms.H:110
RetT fold(RetT &&init_val, Op &&op=Op()) const
Definition: containeralgorithms.H:154
RetT & nth_it(const It &, const It &, nat_t)
Definition: italgorithms.H:172
RetT fold(const RetT &init_val, Op &op) const
Definition: containeralgorithms.H:134
bool is_sorted(Cmp &&cmp=Cmp()) const
Definition: containeralgorithms.H:258
SLList< std::pair< T, typename ContainerType2::KeyType > > zip_eq(const ContainerType2 &c) const
Definition: containeralgorithms.H:276
bool exists_it(const It &, const It &, Pred &)
Definition: italgorithms.H:310
bool remove_first_if(Pred &pred)
Definition: containeralgorithms.H:213
ContainerRet map_if(Op &&op=Op(), Pred &&pred=Pred()) const
Definition: containeralgorithms.H:126
ContainerRet map_if(Op &&op, Pred &pred) const
Definition: containeralgorithms.H:118
ContainerRet map(Op &&op=Op()) const
Definition: containeralgorithms.H:94
ContainerRet map(Op &op) const
Definition: containeralgorithms.H:88
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
bool all(Pred &&pred=Pred()) const
Definition: containeralgorithms.H:167
Definition: containeralgorithms.H:33
ContainerRet filter(Pred &&pred=Pred()) const
Definition: containeralgorithms.H:81
void remove_if_it(const It &, const It &, Pred &)
Definition: italgorithms.H:375
SLList< std::pair< T, typename ContainerType2::KeyType > > zip_left(const ContainerType2 &c) const
Definition: containeralgorithms.H:286
bool remove_first_if_it(const It &, const It &, Pred &)
Definition: italgorithms.H:356
ContainerRet map_if(Op &op, Pred &pred) const
Definition: containeralgorithms.H:102
void for_each(Op &&op=Op()) const
Definition: containeralgorithms.H:68
ContainerRet filter(Pred &pred) const
Definition: containeralgorithms.H:74
T * search_ptr(Pred &pred) const
Definition: containeralgorithms.H:200
unsigned long int nat_t
Definition: types.H:50
bool is_sorted(Cmp &cmp) const
Definition: containeralgorithms.H:252
bool remove_first_if(Pred &&pred=Pred())
Definition: containeralgorithms.H:219
SLList< std::pair< T, typename ContainerType2::KeyType > > zip_right(const ContainerType2 &c) const
Definition: containeralgorithms.H:296
bool all(Pred &pred) const
Definition: containeralgorithms.H:161
void remove_if(Pred &&pred=Pred())
Definition: containeralgorithms.H:232
const T & nth(nat_t i) const
Definition: containeralgorithms.H:56
DynArray< T > to_array() const
Definition: containeralgorithms.H:304
bool all_it(const It &, const It &, Pred &)
Definition: italgorithms.H:295