31 # include "ahFunctional.H" 44 template <
class Container>
66 template <
class Operation>
67 bool traverse(Operation & operation) noexcept(noexcept(operation))
69 for (
typename Container::Iterator it(*static_cast<Container*>(
this));
70 it.has_curr(); it.next_ne())
71 if (not operation(it.get_curr_ne()))
77 template <
class Operation>
78 bool traverse(Operation & operation)
const noexcept(noexcept(operation))
80 return const_cast<GenericTraverse*
>(
this)->traverse<Operation>(operation);
84 template <
class Operation>
85 bool traverse(Operation && operation)
const noexcept(noexcept(operation))
87 return traverse<Operation>(operation);
91 template <
class Operation>
92 bool traverse(Operation && operation) noexcept(noexcept(operation))
94 return traverse<Operation>(operation);
98 template <
class Container,
class Operation>
99 bool traverse(
const Container & c, Operation & op)
101 return c.traverse(op);
104 template <
class Container,
class Operation>
105 bool traverse(
const Container & c, Operation && op = Operation())
107 return traverse<Container, Operation>(c, op);
132 template <
class Container,
typename Type>
135 Container * me() noexcept {
return static_cast<Container*
>(
this); }
137 const Container * const_me()
const noexcept
139 return static_cast<const Container*
>(
this);
153 auto ret =
typename Container::Iterator(*const_me());
161 auto ret =
typename Container::Iterator(*const_me());
162 for (
size_t i = 0; i < pos; ++i)
170 Type & nth_ne(
const size_t n) noexcept
172 Type * ptr =
nullptr;
174 me()->traverse([&ptr, &i, &n] (Type & item)
185 const Type &
nth_ne(
const size_t n)
const noexcept
187 return base()->nth_ne(n);
206 Type &
nth(
const size_t n)
208 Type * ptr =
nullptr;
210 me()->traverse([&ptr, &i, &n] (Type & item)
219 throw std::out_of_range(
"index out of range");
225 const Type &
nth(
const size_t n)
const 227 return base()->nth(n);
252 template <
class Operation>
253 Type *
find_ptr(Operation & operation) noexcept(noexcept(operation))
255 Type * ptr =
nullptr;
256 me()->traverse([&ptr,&operation] (Type & item)
269 template <
class Operation>
271 noexcept(noexcept(operation))
273 return base()->find_ptr(operation);
277 template <
class Operation>
278 const Type *
find_ptr(Operation && operation)
const 279 noexcept(noexcept(operation))
281 return find_ptr<Operation>(operation);
285 template <
class Operation>
286 Type *
find_ptr(Operation && operation) noexcept(noexcept(operation))
288 return find_ptr(operation);
313 template <
class Operation>
314 size_t find_index(Operation & operation)
const noexcept(noexcept(operation))
317 const_me()->traverse([&i,&operation] (Type & item)
328 template <
class Operation>
329 size_t find_index(Operation && operation)
const noexcept(noexcept(operation))
331 return find_index<Operation>(operation);
354 template <
class Operation>
356 noexcept(noexcept(operation))
358 using TT = std::tuple<bool, Type>;
359 auto ptr = find_ptr(operation);
360 return ptr ? TT(
true, *ptr) : TT(
false, Type());
364 template <
class Operation>
365 std::tuple<bool, Type>
find_item(Operation & operation)
const 366 noexcept(noexcept(operation))
368 using TT = std::tuple<bool, Type>;
369 auto ptr = find_ptr(operation);
370 return ptr ? TT(
true, *ptr) : TT(
false, Type());
374 template <
class Operation>
375 std::tuple<bool, Type>
find_item(Operation && operation)
376 noexcept(noexcept(operation))
378 return find_item(operation);
382 template <
class Operation>
383 std::tuple<bool, Type>
find_item(Operation && operation)
const 384 noexcept(noexcept(operation))
386 return find_item(operation);
405 template <
class Container,
typename T>
421 l.for_each([
this] (
const T & item)
423 static_cast<Container*
>(
this)->append(item);
430 for (It it = b; it != e; ++it)
431 static_cast<Container*>(
this)->append(*it);
436 for (
const auto & item : l)
437 static_cast<Container*
>(
this)->append(item);
449 template <
class Container,
typename T>
452 Container * me() {
return static_cast<Container*
>(
this); }
459 const Container * const_me()
const noexcept
461 return static_cast<const Container*
>(
this);
484 template <
typename ...Args>
487 me()->append(T(args...));
491 template <
typename ...Args>
494 me()->append(T(args...));
515 template <
typename ...Args>
518 me()->insert(T(args...));
523 void nninsert(
size_t&) {}
524 void nnappend(
size_t&) {}
526 template <
typename ... Args>
527 void nninsert(
size_t & n,
const T & item, Args & ... args)
531 nninsert(n, args...);
534 template <
typename ... Args>
535 void nnappend(
size_t & n,
const T & item, Args & ... args)
539 nnappend(n, args...);
549 template <
typename ... Args>
553 nninsert(n, args...);
562 template <
typename ... Args>
566 nnappend(n, args...);
588 template <
class Operation>
589 void for_each(Operation & operation) noexcept(noexcept(operation))
591 me()->traverse([&operation] (
const T & item)
599 template <
class Operation>
600 void for_each(Operation & operation)
const noexcept(noexcept(operation))
602 base()->for_each(operation);
606 template <
class Operation>
607 void for_each(Operation && operation)
const noexcept(noexcept(operation))
613 template <
class Operation>
614 void for_each(Operation && operation) noexcept(noexcept(operation))
620 template <
class Operation>
621 void each(Operation & operation) noexcept(noexcept(operation))
627 template <
class Operation>
628 void each(Operation & operation)
const noexcept(noexcept(operation))
634 template <
class Operation>
635 void each(Operation && operation)
const noexcept(noexcept(operation))
641 template <
class Operation>
642 void each(Operation && operation) noexcept(noexcept(operation))
666 template <
class Operation>
667 void each(
size_t pos,
size_t slice, Operation & operation)
const 669 auto it = const_me()->get_it(pos);
670 for (
size_t i = pos;
true; i += slice)
672 operation(it.get_curr());
673 for (
size_t k = 0; k < slice; ++k)
676 if (not it.has_curr())
683 template <
class Operation>
684 void each(
size_t pos,
size_t slice, Operation && operation)
const 686 each(pos, slice, operation);
689 template <
class Operation>
690 void mutable_for_each(Operation & operation) noexcept(noexcept(operation))
692 me()->traverse([&operation] (T & item)
700 template <
class Operation>
703 mutable_for_each(operation);
718 template <
class Operation>
719 bool all(Operation & operation)
const noexcept(noexcept(operation))
721 return const_me()->traverse(operation);
725 template <
class Operation>
726 bool all(Operation && operation)
const noexcept(noexcept(operation))
728 return all(operation);
744 template <
class Operation>
745 bool exists(Operation & op)
const noexcept(noexcept(op))
747 return not const_me()->
748 traverse([&op] (
const T & i) {
return not op(i); });
752 template <
class Operation>
753 bool exists(Operation && op)
const noexcept(noexcept(op))
798 template <
typename __T = T,
class Operation = Dft_Map_Op<T, __T>>
802 const_me()->for_each([&ret_val, &op] (
const T & item)
804 ret_val.append(op(item));
810 template <
typename __T = T,
class Operation = Dft_Map_Op<__T, __T>>
829 template <
typename __T = T,
class Prop,
class Operation>
833 const_me()->for_each([&ret_val, &prop, &op] (
const T & item)
836 ret_val.append(op(item));
842 template <
typename __T = T,
class Prop,
class Operation>
845 return maps<__T, Prop, Operation>(prop, op);
850 return maps([] (
auto & item) {
return item; });
900 template <
typename __T = T,
class Op = Dft_Fold_Op<__T, T>>
901 __T
foldl(
const __T & init, Op & op)
const noexcept(noexcept(op))
904 const_me()->for_each([&ret_val, &op] (
const T & item)
906 ret_val = op(ret_val, item);
912 template <
typename __T = T,
class Op = Dft_Fold_Op<__T, T>>
913 __T
foldl(
const __T & init, Op && op = Op()) const noexcept(noexcept(op))
915 return foldl(init, op);
923 template <
class Operation>
924 T
fold(
const T & init, Operation & operation)
const 925 noexcept(noexcept(operation))
928 const_me()->for_each([&ret_val, &operation] (
const T & item)
930 ret_val = operation(ret_val, item);
936 template <
class Operation>
937 T
fold(
const T & init, Operation && operation)
const 938 noexcept(noexcept(operation))
940 return fold(init, operation);
966 template <
class Operation>
970 const_me()->for_each([&ret_val, &operation] (
const T & item)
973 ret_val.append(item);
979 template <
class Operation>
982 return filter(operation);
1008 template <
class Operation>
1012 const_me()->for_each([&ret_val, &operation] (
const T & item)
1014 if (operation(item))
1015 ret_val.append(&item);
1020 template <
class Operation>
1023 return ptr_filter(operation);
1045 template <
class Operation>
1048 using TT = std::tuple<T, size_t>;
1051 const_me()->for_each([&ret_val, &operation, &i] (
const T & item)
1053 if (operation(item))
1054 ret_val.append(TT(item, i));
1061 template <
class Operation>
1064 return pfilter(operation);
1084 template <
class Operation>
1088 const_me()->for_each([&ret_val, &op] (
const T & item)
1091 ret_val.first.append(item);
1093 ret_val.second.append(item);
1099 template <
class Operation>
1102 return partition(op);
1115 template <
class Operation>
1120 const_me()->for_each([&ret_val, &i, n] (
const T & item)
1123 ret_val.first.append(item);
1125 ret_val.second.append(item);
1143 template <
class Operation>
1147 const_me()->for_each([&r1, &r2, &op] (
const T & item)
1154 return std::tuple<DynList<T>,
DynList<T>>(r1, r2);
1158 template <
class Operation>
1161 return partition(op);
1178 const_me()->for_each([&count] (
const T &) { ++count; });
1192 const_me()->for_each([&ret] (
const T & i) { ret.insert(i); });
1212 const_me()->traverse([&i, &ret, n] (
const T & item)
1239 for (
auto it = const_me()->get_it(i); i <= j and it.has_curr();
1240 it.next_ne(), i += step)
1241 ret.append(it.get_curr_ne());
1261 const_me()->traverse([&i, &ret, n] (
const T & item)
1280 for (
size_t i = 0; i < n; ++i)
1289 template <
class Container,
typename T>
1301 return static_cast<const Container*
>(
this)->
1302 Container::template maps<T> ([] (
const T & key) {
return key; });
1314 template <
class Container,
typename T>
1322 template <
class Container>
1325 const Container * const_me()
const 1327 return static_cast<const Container*
>(
this);
1355 if (const_me()->size() != r.size())
1358 return const_me()->all([&r] (
const typename Container::Key_Type & k)
1359 {
return r.search(k) !=
nullptr; });
1363 bool operator == (
const Container & r)
const noexcept
1369 bool operator != (
const Container & r)
const noexcept
1371 return not equal_to(r);
1379 template <
class Container,
typename Key,
typename Data>
1382 const Container * const_me()
const 1384 return static_cast<const Container*
>(
this);
1402 template <
template <
typename>
class C =
DynList>
1406 const_me()->for_each([&ret_val] (
const Key & p)
1408 ret_val.append(p.first);
1426 template <
template <
typename>
class C =
DynList>
1430 const_me()->for_each([&ret_val] (
const std::pair<Key, Data> & p)
1432 ret_val.append(p.second);
1452 template <
template <
typename>
class C =
DynList>
1456 const_me()->for_each([&ret_val] (std::pair<Key, Data> & p)
1457 { ret_val.append(&p.second); });
1470 template <
template <
typename>
class C =
DynList>
1473 C<std::pair<Key, Data>> ret;
1474 const_me()->for_each([&ret] (std::pair<Key, Data> & p) { ret.append(p); });
1489 template <
template <
typename>
class C =
DynList>
1493 const_me()->for_each([&ret_val] (std::pair<Key, Data> & p)
1495 ret_val.append(std::pair<Key,Data*>(p.first,
1506 Data & operator () (
const Key & key)
1508 return this->find(key);
1516 const Data & operator () (
const Key & key)
const 1518 return this->find(key);
size_t length() const noexcept
Definition: ah-dry.H:1175
std::tuple< bool, Type > find_item(Operation &operation) noexcept(noexcept(operation))
Definition: ah-dry.H:355
const Type * find_ptr(Operation &&operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:278
C< std::pair< Key, Data * > > items_ptr() const
Definition: ah-dry.H:1490
__T foldl(const __T &init, Op &op) const noexcept(noexcept(op))
Definition: ah-dry.H:901
size_t ninsert(Args ... args)
Definition: ah-dry.H:550
DynList< T > items() const
Definition: ah-dry.H:1299
Definition: ah-dry.H:1323
DynList< T > drop(const size_t n) const
Definition: ah-dry.H:1257
C< Key > keys() const
Definition: ah-dry.H:1403
void for_each(Operation &&operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:607
DynList< std::tuple< T, size_t > > pfilter(Operation &&operation) const
Definition: ah-dry.H:1062
void emplace(Args &&... args)
Definition: ah-dry.H:485
bool traverse(Operation &&operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:85
auto get_it() const
Definition: ah-dry.H:151
SpecialCtors(const DynList< T > &l)
Build the container by inserting all item of list l
Definition: ah-dry.H:419
const Type & nth(const size_t n) const
Definition: ah-dry.H:225
bool exists(Operation &op) const noexcept(noexcept(op))
Definition: ah-dry.H:745
void for_each(Operation &&operation) noexcept(noexcept(operation))
Definition: ah-dry.H:614
void emplace_end(Args &&... args)
Definition: ah-dry.H:492
void mutable_drop(size_t n)
Definition: ah-dry.H:1278
auto get_it(size_t pos) const
Definition: ah-dry.H:159
void for_each(Operation &operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:600
DynList< T > filter(Operation &&operation) const
Definition: ah-dry.H:980
const Type * find_ptr(Operation &operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:270
void each(Operation &&operation) noexcept(noexcept(operation))
Definition: ah-dry.H:642
Type & nth(const size_t n)
Definition: ah-dry.H:206
size_t nappend(Args ... args)
Definition: ah-dry.H:563
void mutable_for_each(Operation &&operation) noexcept(noexcept(operation))
Definition: ah-dry.H:701
bool equal_to(const Container &r) const noexcept
Definition: ah-dry.H:1350
bool all(Operation &operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:719
void each(size_t pos, size_t slice, Operation &operation) const
Definition: ah-dry.H:667
size_t find_index(Operation &operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:314
auto get_itor() const
Definition: ah-dry.H:168
void each(Operation &operation) noexcept(noexcept(operation))
Definition: ah-dry.H:621
void for_each(Operation &operation) noexcept(noexcept(operation))
Definition: ah-dry.H:589
Recorre condicionalmente el contenedor y ejecuta una operation mientras ésta retorne true...
DynList< std::tuple< T, size_t > > pfilter(Operation &operation) const
Definition: ah-dry.H:1046
std::tuple< bool, Type > find_item(Operation &&operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:383
void each(size_t pos, size_t slice, Operation &&operation) const
Definition: ah-dry.H:684
bool exists(Operation &&op) const noexcept(noexcept(op))
Definition: ah-dry.H:753
std::tuple< bool, Type > find_item(Operation &operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:365
T fold(const T &init, Operation &operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:924
DynList< __T > maps(Operation &op) const
Definition: ah-dry.H:799
DynList< __T > maps_if(Prop prop, Operation &&op) const
Definition: ah-dry.H:843
Type * find_ptr(Operation &operation) noexcept(noexcept(operation))
Definition: ah-dry.H:253
Definition: ah-dry.H:1290
void each(Operation &&operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:635
std::tuple< DynList< T >, DynList< T > > tpartition(Operation &op) const
Definition: ah-dry.H:1144
std::pair< DynList< T >, DynList< T > > partition(Operation &op) const
Definition: ah-dry.H:1085
void emplace_ins(Args &&... args)
Definition: ah-dry.H:516
std::pair< DynList< T >, DynList< T > > partition(size_t n) const
Definition: ah-dry.H:1116
bool traverse(Operation &operation) noexcept(noexcept(operation))
Definition: ah-dry.H:67
C< std::pair< Key, Data > > items() const
Definition: ah-dry.H:1471
__T foldl(const __T &init, Op &&op=Op()) const noexcept(noexcept(op))
Definition: ah-dry.H:913
DynList< T > rev() const
Definition: ah-dry.H:1189
DynList< __T > maps(Operation &&op) const
Definition: ah-dry.H:811
const Type & nth_ne(const size_t n) const noexcept
Definition: ah-dry.H:185
std::tuple< DynList< T >, DynList< T > > tpartition(Operation &&op) const
Definition: ah-dry.H:1159
void each(Operation &operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:628
size_t find_index(Operation &&operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:329
std::tuple< bool, Type > find_item(Operation &&operation) noexcept(noexcept(operation))
Definition: ah-dry.H:375
C< Data * > values_ptr() const
Definition: ah-dry.H:1453
DynList< T > keys() const
Definition: ah-dry.H:1306
bool traverse(Operation &operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:78
T fold(const T &init, Operation &&operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:937
Definition: ah-dry.H:1380
std::pair< DynList< T >, DynList< T > > partition(Operation &&op) const
Definition: ah-dry.H:1100
Type * find_ptr(Operation &&operation) noexcept(noexcept(operation))
Definition: ah-dry.H:286
DynList< T > take(const size_t n) const
Definition: ah-dry.H:1208
DynList< const T * > ptr_filter(Operation &operation) const
Definition: ah-dry.H:1009
C< Data > values() const
Definition: ah-dry.H:1427
bool all(Operation &&operation) const noexcept(noexcept(operation))
Definition: ah-dry.H:726
DynList< __T > maps_if(Prop prop, Operation &op) const
Definition: ah-dry.H:830
DynList< T > take(size_t i, size_t j, size_t step=1) const
Definition: ah-dry.H:1234
bool traverse(Operation &&operation) noexcept(noexcept(operation))
Definition: ah-dry.H:92
DynList< T > filter(Operation &operation) const
Definition: ah-dry.H:967