Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah-dry.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
44# ifndef AH_DRY_H
45# define AH_DRY_H
46
47# include "ahFunctional.H"
48# include <utility>
49# include <vector>
50# include <ah-errors.H>
51
63template <class Container>
65{
66private:
67 template <class Operation>
68 static constexpr bool traverse_is_noexcept() noexcept
69 {
70 return noexcept(std::declval<Operation&>()(
71 std::declval<typename Container::Item_Type&>()));
72 }
73
74public:
94 template <class Operation>
95 bool traverse(Operation & operation) noexcept(traverse_is_noexcept<Operation>())
96 {
97 for (typename Container::Iterator it(*static_cast<Container*>(this));
98 it.has_curr(); it.next())
99 if (not operation(it.get_curr()))
100 return false;
101 return true;
102 }
103
105 template <class Operation>
106 bool traverse(Operation & operation) const noexcept(traverse_is_noexcept<Operation>())
107 {
108 return const_cast<GenericTraverse*>(this)->traverse<Operation>(operation);
109 }
110
112 template <class Operation>
113 bool traverse(Operation && operation) const noexcept(traverse_is_noexcept<Operation>())
114 {
115 return traverse<Operation>(operation);
116 }
117
119 template <class Operation>
120 bool traverse(Operation && operation) noexcept(traverse_is_noexcept<Operation>())
121 {
122 return traverse<Operation>(operation);
123 }
124};
125
126template <class Container, class Operation>
127bool traverse(const Container & c, Operation & op)
128 noexcept(noexcept(c.traverse(op)))
129{
130 return c.traverse(op);
131}
132
133template <class Container, class Operation>
134bool traverse(const Container & c, Operation && op)
135 noexcept(noexcept(c.traverse(std::forward<Operation>(op))))
136{
137 return c.traverse(std::forward<Operation>(op));
138}
139
162template <class Container, typename Type>
164{
165 Container * me() noexcept { return static_cast<Container*>(this); }
166
167 const Container * const_me() const noexcept
168 {
169 return static_cast<const Container*>(this);
170 }
171
173 {
174 return const_cast<LocateFunctions*>(this);
175 }
176
177 template <class Operation>
178 static constexpr bool operation_is_noexcept() noexcept
179 {
180 return noexcept(std::declval<Operation&>()(std::declval<Type&>()));
181 }
182
183public:
184
190 auto get_it() const
191 {
192 return typename Container::Iterator(*const_me());
193 }
194
195 // auto get_it()
196 // {
197 // return typename Container::Iterator(*me());
198 // }
199
206 auto get_it(const size_t pos) const
207 {
208 auto ret = typename Container::Iterator(*const_me());
209 for (size_t i = 0; i < pos; ++i)
210 ret.next();
211 return ret;
212 }
213
218 auto get_itor() const { return get_it(); }
219
226 Type & nth_ne(const size_t n) noexcept
227 {
228 Type * ptr = nullptr;
229 size_t i = 0;
230 me()->traverse([&ptr, &i, &n] (Type & item)
231 {
232 if (i++ < n)
233 return true;
234 ptr = &item;
235 return false;
236 });
237 return *ptr;
238 }
239
246 const Type & nth_ne(const size_t n) const noexcept
247 {
248 return base()->nth_ne(n);
249 }
250
267 Type & nth(const size_t n)
268 {
269 Type * ptr = nullptr;
270 size_t i = 0;
271 me()->traverse([&ptr, &i, &n] (Type & item)
272 {
273 if (i++ < n)
274 return true;
275 ptr = &item;
276 return false;
277 });
278
279 ah_out_of_range_error_if(i != n + 1) << "index out of range";
280
281 return *ptr;
282 }
283
290 const Type & nth(const size_t n) const
291 {
292 return base()->nth(n);
293 }
294
317 template <class Operation>
318 Type * find_ptr(Operation & operation)
319 noexcept(operation_is_noexcept<Operation>())
320 {
321 Type * ptr = nullptr;
322 me()->traverse([&ptr,&operation] (Type & item)
323 {
324 if (operation(item))
325 {
326 ptr = &item;
327 return false;
328 }
329 return true;
330 });
331 return ptr;
332 }
333
339 template <class Operation>
340 const Type * find_ptr(Operation & operation) const
341 noexcept(operation_is_noexcept<Operation>())
342 {
343 return base()->find_ptr(operation);
344 }
345
351 template <class Operation>
352 const Type * find_ptr(Operation && operation) const
353 noexcept(operation_is_noexcept<Operation>())
354 {
355 return find_ptr<Operation>(operation);
356 }
357
363 template <class Operation>
364 Type * find_ptr(Operation && operation)
365 noexcept(operation_is_noexcept<Operation>())
366 {
367 return find_ptr<Operation>(operation);
368 }
369
392 template <class Operation>
393 size_t find_index(Operation & operation) const
394 noexcept(operation_is_noexcept<Operation>())
395 {
396 size_t i = 0;
397 const_me()->traverse([&i,&operation] (Type & item)
398 {
399 if (operation(item))
400 return false;
401 ++i;
402 return true;
403 });
404 return i;
405 }
406
412 template <class Operation>
413 size_t find_index(Operation && operation) const
414 noexcept(operation_is_noexcept<Operation>())
415 {
416 return find_index<Operation>(operation);
417 }
418
439 template <class Operation>
440 std::tuple<bool, Type> find_item(Operation & operation)
441 noexcept(operation_is_noexcept<Operation>())
442 {
443 using TT = std::tuple<bool, Type>;
444 auto ptr = find_ptr(operation);
445 return ptr ? TT(true, *ptr) : TT(false, Type());
446 }
447
449 template <class Operation>
450 std::tuple<bool, Type> find_item(Operation & operation) const
451 noexcept(operation_is_noexcept<Operation>())
452 {
453 using TT = std::tuple<bool, Type>;
454 auto ptr = find_ptr(operation);
455 return ptr ? TT(true, *ptr) : TT(false, Type());
456 }
457
459 template <class Operation>
460 std::tuple<bool, Type> find_item(Operation && operation)
461 noexcept(operation_is_noexcept<Operation>())
462 {
463 return find_item<Operation>(operation);
464 }
465
467 template <class Operation>
468 std::tuple<bool, Type> find_item(Operation && operation) const
469 noexcept(operation_is_noexcept<Operation>())
470 {
471 return find_item<Operation>(operation);
472 }
473};
474
490template <class Container, typename T>
492{
493 SpecialCtors() = default;
494
495 SpecialCtors(const SpecialCtors&) = default;
496
498
499 SpecialCtors & operator = (const SpecialCtors&) { return *this; }
500
501 SpecialCtors & operator = (SpecialCtors&&) noexcept { return *this; }
502
508 {
509 l.for_each([this] (const T & item)
510 {
511 static_cast<Container*>(this)->append(item);
512 });
513 }
514
520 template <class It>
521 SpecialCtors(It b, It e)
522 {
523 for (It it = b; it != e; ++it)
524 static_cast<Container*>(this)->append(*it);
525 }
526
531 SpecialCtors(std::initializer_list<T> l)
532 {
533 for (const auto & item : l)
534 static_cast<Container*>(this)->append(item);
535 }
536};
537
538
546template <class Container, typename T>
548{
549 Container * me() { return static_cast<Container*>(this); }
550
555
557 {
558 return static_cast<const Container*>(this);
559 }
560
561public:
562
581 template <typename ...Args>
582 void emplace(Args && ... args)
583 {
584 (void) me()->append(T(std::forward<Args>(args)...));
585 }
586
588 template <typename ...Args>
589 void emplace_end(Args && ... args)
590 {
591 (void) me()->append(T(std::forward<Args>(args)...));
592 }
593
612 template <typename ...Args>
613 void emplace_ins(Args && ... args)
614 {
615 (void) me()->insert(T(std::forward<Args>(args)...));
616 }
617
618private:
619
620 void nninsert(size_t&) {}
621 void nnappend(size_t&) {}
622
623 template <typename ... Args>
624 void nninsert(size_t & n, const T & item, Args & ... args)
625 {
626 (void) me()->insert(item);
627 ++n;
628 nninsert(n, args...);
629 }
630
631 template <typename ... Args>
632 void nnappend(size_t & n, const T & item, Args & ... args)
633 {
634 (void) me()->append(item);
635 ++n;
636 nnappend(n, args...);
637 }
638
639public:
640
646 template <typename ... Args>
647 size_t ninsert(Args ... args)
648 {
649 size_t n = 0;
650 nninsert(n, args...);
651 return n;
652 }
653
659 template <typename ... Args>
660 size_t nappend(Args ... args)
661 {
662 size_t n = 0;
663 nnappend(n, args...);
664 return n;
665 }
666
684 template <class Operation>
686 {
687 me()->traverse([&operation] (const T & item)
688 {
689 operation(item);
690 return true;
691 });
692 }
693
695 template <class Operation>
697 {
698 base()->for_each(operation);
699 }
700
702 template <class Operation>
704 {
706 }
707
709 template <class Operation>
714
716 template <class Operation>
718 {
720 }
721
723 template <class Operation>
725 {
727 }
728
730 template <class Operation>
731 void each(Operation && operation) const
732 {
734 }
735
737 template <class Operation>
742
763 template <class Operation>
764 void each(size_t pos, const size_t slice, Operation & operation) const
765 {
766 auto it = const_me()->get_it(pos);
767 while (true)
768 {
769 operation(it.get_curr());
770 for (size_t k = 0; k < slice; ++k)
771 {
772 it.next();
773 if (not it.has_curr())
774 return;
775 }
776 }
777 }
778
780 template <class Operation>
781 void each(const size_t pos, const size_t slice, Operation && operation) const
782 {
784 }
785
786 template <class Operation>
788 {
789 me()->traverse([&operation] (T & item)
790 {
791 operation(item);
792 return true;
793 });
794 }
795
797 template <class Operation>
802
815 template <class Operation>
816 bool all(Operation & operation) const
817 {
818 return const_me()->traverse(operation);
819 }
820
826 template <class Operation>
827 bool all(Operation && operation) const
828 {
830 }
831
845 template <class Operation>
846 bool exists(Operation & op) const
847 {
848 return not const_me()->
849 traverse([&op] (const T & i) { return not op(i); });
850 }
851
857 template <class Operation>
858 bool exists(Operation && op) const
859 {
860 return exists<Operation>(op);
861 }
862
903 template <typename __T = T, class Operation = Aleph::Dft_Map_Op<T, __T>>
905 {
907 const_me()->for_each([&ret_val, &op] (const T & item)
908 {
909 ret_val.append(op(item));
910 });
911 return ret_val;
912 }
913
920 template <typename __T = T, class Operation = Aleph::Dft_Map_Op<__T, __T>>
922
939 template <typename __T = T, class Prop, class Operation>
941 {
943 const_me()->for_each([&ret_val, &prop, &op] (const T & item)
944 {
945 if (prop(item))
946 ret_val.append(op(item));
947 });
948 return ret_val;
949 }
950
958 template <typename __T = T, class Prop, class Operation>
963
969 {
970 return maps([] (auto & item) { return item; });
971 }
972
977 std::vector<T> to_vector() const
978 {
979 std::vector<T> ret;
980 if constexpr (requires { const_me()->size(); })
981 ret.reserve(const_me()->size());
982 const_me()->for_each([&ret] (const T & item) { ret.push_back(item); });
983 return ret;
984 }
985
1033 template <typename __T = T, class Op = Aleph::Dft_Fold_Op<__T, T>>
1034 __T foldl(const __T & init, Op & op) const
1035 {
1036 __T ret_val = init;
1037 const_me()->for_each([&ret_val, &op] (const T & item)
1038 {
1039 ret_val = op(ret_val, item);
1040 });
1041 return ret_val;
1042 }
1043
1051 template <typename __T = T, class Op = Aleph::Dft_Fold_Op<__T, T>>
1052 __T foldl(const __T & init, Op && op = Op()) const
1053 {
1054 return foldl<__T, Op>(init, op);
1055 }
1056
1064 template <typename __T = T, class Op = Aleph::Dft_Fold_Op<__T, T>>
1065 __T fold_left(const __T & init, Op & op) const
1066 {
1067 return const_me()->template foldl<__T>(init, op);
1068 }
1069
1077 template <typename __T = T, class Op = Aleph::Dft_Fold_Op<__T, T>>
1078 __T fold_left(const __T & init, Op && op = Op()) const
1079 {
1080 return const_me()->template foldl<__T>(init, op);
1081 }
1082
1088 template <class Operation>
1089 T fold(const T & init, Operation & operation) const
1090 {
1091 auto ret_val = init;
1092 const_me()->for_each([&ret_val, &operation] (const T & item)
1093 {
1094 ret_val = operation(ret_val, item);
1095 });
1096 return ret_val;
1097 }
1098
1105 template <class Operation>
1106 T fold(const T & init, Operation && operation) const
1107 {
1108 return fold<Operation>(init, operation);
1109 }
1110
1134 template <class Operation>
1136 {
1138 const_me()->for_each([&ret_val, &operation] (const T & item)
1139 {
1140 if (operation(item))
1141 ret_val.append(item);
1142 });
1143 return ret_val;
1144 }
1145
1151 template <class Operation>
1156
1180 template <class Operation>
1182 {
1184 const_me()->for_each([&ret_val, &operation] (const T & item)
1185 {
1186 if (operation(item))
1187 ret_val.append(&item);
1188 });
1189 return ret_val;
1190 }
1191
1197 template <class Operation>
1202
1222 template <class Operation>
1224 {
1225 using TT = std::tuple<T, size_t>;
1227 size_t i = 0;
1228 const_me()->for_each([&ret_val, &operation, &i] (const T & item)
1229 {
1230 if (operation(item))
1231 ret_val.append(TT(item, i));
1232 ++i;
1233 });
1234 return ret_val;
1235 }
1236
1242 template <class Operation>
1247
1265 template <class Operation>
1266 std::pair<Aleph::DynList<T>, Aleph::DynList<T>> partition(Operation & op) const
1267 {
1268 std::pair<Aleph::DynList<T>, Aleph::DynList<T>> ret_val;
1269 const_me()->for_each([&ret_val, &op] (const T & item)
1270 {
1271 if (op(item))
1272 ret_val.first.append(item);
1273 else
1274 ret_val.second.append(item);
1275 });
1276 return ret_val;
1277 }
1278
1284 template <class Operation>
1285 std::pair<Aleph::DynList<T>, Aleph::DynList<T>> partition(Operation && op) const
1286 {
1287 return partition<Operation>(op);
1288 }
1289
1300 template <class Operation>
1301 std::pair<Aleph::DynList<T>, Aleph::DynList<T>> partition(size_t n) const
1302 {
1303 size_t i = 0;
1304 std::pair<Aleph::DynList<T>, Aleph::DynList<T>> ret_val;
1305 const_me()->for_each([&ret_val, &i, n] (const T & item)
1306 {
1307 if (i++ < n)
1308 ret_val.first.append(item);
1309 else
1310 ret_val.second.append(item);
1311 });
1312 return ret_val;
1313 }
1314
1321 std::pair<Aleph::DynList<T>, Aleph::DynList<T>> split_half() const
1322 {
1323 size_t i = 0;
1324 std::pair<Aleph::DynList<T>, Aleph::DynList<T>> ret_val;
1325 const_me()->for_each([&ret_val, &i] (const T & item)
1326 {
1327 if (i % 2 == 0)
1328 ret_val.first.append(item);
1329 else
1330 ret_val.second.append(item);
1331 i++;
1332 });
1333 return ret_val;
1334 }
1335
1349 template <class Operation>
1350 std::tuple<Aleph::DynList<T>, Aleph::DynList<T>> tpartition(Operation & op) const
1351 {
1353 const_me()->for_each([&r1, &r2, &op] (const T & item)
1354 {
1355 if (op(item))
1356 r1.append(item);
1357 else
1358 r2.append(item);
1359 });
1360 return std::tuple<Aleph::DynList<T>, Aleph::DynList<T>>(r1, r2);
1361 }
1362
1368 template <class Operation>
1369 std::tuple<Aleph::DynList<T>, Aleph::DynList<T>> tpartition(Operation && op) const
1370 {
1371 return tpartition<Operation>(op);
1372 }
1373
1386 {
1387 size_t count = 0;
1388 const_me()->for_each([&count] (const T &) { ++count; });
1389 return count;
1390 }
1391
1400 {
1402 const_me()->for_each([&ret] (const T & i) { ret.insert(i); });
1403 return ret;
1404 }
1405
1418 Aleph::DynList<T> take(const size_t n) const
1419 {
1420 size_t i = 0;
1422 const_me()->traverse([&i, &ret, n] (const T & item)
1423 {
1424 if (i++ >= n)
1425 return false;
1426 ret.append(item);
1427 return true;
1428 });
1429 return ret;
1430 }
1431
1444 Aleph::DynList<T> take(size_t i, const size_t j, const size_t step = 1) const
1445 {
1447 if (step == 0)
1448 return ret;
1449 for (auto it = const_me()->get_it(i); i <= j and it.has_curr();
1450 it.next_ne(), i += step)
1451 ret.append(it.get_curr());
1452 return ret;
1453 }
1454
1467 Aleph::DynList<T> drop(const size_t n) const
1468 {
1469 size_t i = 0;
1471 const_me()->traverse([&i, &ret, n] (const T & item)
1472 {
1473 if (i++ >= n)
1474 ret.append(item);
1475 return true;
1476 });
1477 return ret;
1478 }
1479
1488 void mutable_drop(const size_t n)
1489 {
1490 for (size_t i = 0; i < n; ++i)
1491 me()->remove();
1492 }
1493};
1494
1499template <class Container, typename T>
1501{
1510 {
1511 return static_cast<const Container*>(this)->
1512 Container::template maps<T> ([] (const T & key) { return key; });
1513 }
1514
1516 Aleph::DynList<T> keys() const { return items(); }
1517};
1518
1519
1524template <class Container, typename T>
1526
1527
1532template <class Container>
1534{
1535 const Container * const_me() const
1536 {
1537 return static_cast<const Container*>(this);
1538 }
1539
1540public:
1541
1560 bool equal_to(const Container & r) const noexcept
1561 {
1562 if (const_me() == &r) // Use const_me() to get correct pointer in case of multiple inheritance
1563 return true;
1564
1565 if (const_me()->size() != r.size())
1566 return false;
1567
1568 return const_me()->all([&r] (const typename Container::Key_Type & k)
1569 { return r.search(k) != nullptr; });
1570 }
1571
1573 bool operator == (const Container & r) const noexcept
1574 {
1575 return equal_to(r);
1576 }
1577
1579 bool operator != (const Container & r) const noexcept
1580 {
1581 return not equal_to(r);
1582 }
1583};
1584
1589template <class Container, typename Key, typename Data>
1591{
1592 const Container * const_me() const
1593 {
1594 return static_cast<const Container*>(this);
1595 }
1596
1597public:
1598
1612 template <template <typename> class C = Aleph::DynList>
1613 C<Key> keys() const
1614 {
1615 C<Key> ret_val;
1616 const_me()->for_each([&ret_val] (const Key & p)
1617 {
1618 ret_val.append(p.first);
1619 });
1620 return ret_val;
1621 }
1622
1636 template <template <typename> class C = Aleph::DynList>
1637 C<Data> values() const
1638 {
1639 C<Data> ret_val;
1640 const_me()->for_each([&ret_val] (const std::pair<Key, Data> & p)
1641 {
1642 ret_val.append(p.second);
1643 });
1644 return ret_val;
1645 }
1646
1662 template <template <typename> class C = Aleph::DynList>
1663 C<Data*> values_ptr() const
1664 {
1665 C<Data*> ret_val;
1666 const_me()->for_each([&ret_val] (std::pair<Key, Data> & p)
1667 { ret_val.append(&p.second); });
1668 return ret_val;
1669 }
1670
1680 template <template <typename> class C = Aleph::DynList>
1681 C<std::pair<Key, Data>> items() const
1682 {
1683 C<std::pair<Key, Data>> ret;
1684 const_me()->for_each([&ret] (std::pair<Key, Data> & p) { ret.append(p); });
1685 return ret;
1686 }
1687
1699 template <template <typename> class C = Aleph::DynList>
1700 C<std::pair<Key, Data*>> items_ptr() const
1701 {
1702 C<Data> ret_val;
1703 const_me()->for_each([&ret_val] (std::pair<Key, Data> & p)
1704 {
1705 ret_val.append(std::pair<Key,Data*>(p.first,
1706 p.second));
1707 });
1708 return ret_val;
1709 }
1710
1716 Data & operator () (const Key & key)
1717 {
1718 return this->find(key);
1719 }
1720
1726 const Data & operator () (const Key & key) const
1727 {
1728 return this->find(key);
1729 }
1730};
1731# endif // AH_DRY_H
bool traverse(const Container &c, Operation &op) noexcept(noexcept(c.traverse(op)))
Definition ah-dry.H:127
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Definition ah-errors.H:579
Functional programming utilities for Aleph-w containers.
Dynamic singly linked list with functional programming support.
Definition htlist.H:1423
T & append(const T &item)
Append a new item by copy.
Definition htlist.H:1562
Equality test for containers.
Definition ah-dry.H:1534
const Container * const_me() const
Definition ah-dry.H:1535
bool operator!=(const Container &r) const noexcept
Negation of equal_to()
Definition ah-dry.H:1579
bool operator==(const Container &r) const noexcept
Definition ah-dry.H:1573
bool equal_to(const Container &r) const noexcept
Test if elements of this are exactly contained in another container.
Definition ah-dry.H:1560
Common methods to the Aleph-w ( ) containers.
Definition ah-dry.H:548
void mutable_for_each(Operation &operation)
Definition ah-dry.H:787
Aleph::DynList< std::tuple< T, size_t > > pfilter(Operation &&operation) const
Overload of pfilter(Operation&) that accepts rvalues.
Definition ah-dry.H:1243
void each(Operation &operation)
Alias of for_each(Operation&).
Definition ah-dry.H:717
__T foldl(const __T &init, Op &op) const
Fold the elements of the container to a specific result.
Definition ah-dry.H:1034
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criteria.
Definition ah-dry.H:1135
Aleph::DynList< __T > maps(Operation &&op) const
Overload of maps(Operation&) that accepts rvalues.
Definition ah-dry.H:921
std::vector< T > to_vector() const
Convert container to std::vector.
Definition ah-dry.H:977
void nnappend(size_t &)
Definition ah-dry.H:621
Aleph::DynList< T > filter(Operation &&operation) const
Overload of filter(Operation&) that accepts rvalues.
Definition ah-dry.H:1152
__T foldl(const __T &init, Op &&op=Op()) const
Overload of foldl(const __T&, Op&) that accepts rvalues.
Definition ah-dry.H:1052
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(size_t n) const
Exclusive partition of container in the nth item.
Definition ah-dry.H:1301
Aleph::DynList< T > to_dynlist() const
Convert container to DynList.
Definition ah-dry.H:968
void emplace(Args &&... args)
Appends a new element into the container by constructing it in-place with the given args.
Definition ah-dry.H:582
void each(Operation &operation) const
Const alias of for_each(Operation&).
Definition ah-dry.H:724
size_t ninsert(Args ... args)
Insert n variadic items.
Definition ah-dry.H:647
__T fold_left(const __T &init, Op &&op=Op()) const
Overload of fold_left(const __T&, Op&) that accepts rvalues.
Definition ah-dry.H:1078
Aleph::DynList< __T > maps_if(Prop prop, Operation &op) const
Conditional mapping of the elements of the container.
Definition ah-dry.H:940
void nninsert(size_t &)
Definition ah-dry.H:620
FunctionalMethods< Container, T > * base() const noexcept
Definition ah-dry.H:551
Aleph::DynList< const T * > ptr_filter(Operation &&operation) const
Overload of ptr_filter(Operation&) that accepts rvalues.
Definition ah-dry.H:1198
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(Operation &op) const
Exclusive partition of container according to a filter criteria.
Definition ah-dry.H:1266
void each(const size_t pos, const size_t slice, Operation &&operation) const
Definition ah-dry.H:781
void emplace_ins(Args &&... args)
Insert a new element into the container by constructing it in-place with the given args.
Definition ah-dry.H:613
void mutable_for_each(Operation &&operation)
Definition ah-dry.H:798
Aleph::DynList< T > take(const size_t n) const
Return a list with the first n elements seen in the container during its traversal.
Definition ah-dry.H:1418
bool exists(Operation &op) const
Test for existence in the container of an element satisfying a criteria.
Definition ah-dry.H:846
void nninsert(size_t &n, const T &item, Args &... args)
Definition ah-dry.H:624
void each(Operation &&operation) const
Const alias of for_each(Operation&) that accepts rvalues.
Definition ah-dry.H:731
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition(Operation &op) const
Exclusive partition of container according to a filter criteria.
Definition ah-dry.H:1350
const Container * const_me() const noexcept
Definition ah-dry.H:556
void each(size_t pos, const size_t slice, Operation &operation) const
Traverse the container starting at pos taking one item every slice, performing a mutable operation on...
Definition ah-dry.H:764
size_t nappend(Args ... args)
Append n variadic items.
Definition ah-dry.H:660
bool all(Operation &operation) const
Check if all the elements of container satisfy a condition.
Definition ah-dry.H:816
Aleph::DynList< T > rev() const
Return a list with the elements of container in reverse order respect to its traversal order.
Definition ah-dry.H:1399
void emplace_end(Args &&... args)
Definition ah-dry.H:589
void nnappend(size_t &n, const T &item, Args &... args)
Definition ah-dry.H:632
bool all(Operation &&operation) const
Overload of all(Operation&) that accepts rvalues.
Definition ah-dry.H:827
bool exists(Operation &&op) const
Overload of exists(Operation&) that accepts rvalues.
Definition ah-dry.H:858
size_t length() const noexcept
Count the number of elements of a container.
Definition ah-dry.H:1385
void for_each(Operation &&operation) const
Overload of for_each(Operation&) const that accepts rvalues.
Definition ah-dry.H:703
Aleph::DynList< __T > maps_if(Prop prop, Operation &&op) const
Overload of maps_if(Prop, Operation&) that accepts rvalues.
Definition ah-dry.H:959
T fold(const T &init, Operation &&operation) const
Overload of fold(const T&, Operation&) that accepts rvalues.
Definition ah-dry.H:1106
void mutable_drop(const size_t n)
Drop the first n elements seen from container.
Definition ah-dry.H:1488
T fold(const T &init, Operation &operation) const
Simplified version of foldl() where the folded type is the same type of elements stored in the contai...
Definition ah-dry.H:1089
Aleph::DynList< std::tuple< T, size_t > > pfilter(Operation &operation) const
Filter the elements of a container according to a matching criteria and determine its positions respe...
Definition ah-dry.H:1223
Aleph::DynList< const T * > ptr_filter(Operation &operation) const
Filter the elements of a container according to a matching criteria and return a pointer to the match...
Definition ah-dry.H:1181
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:685
void each(Operation &&operation)
Alias of for_each(Operation&) that accepts rvalues.
Definition ah-dry.H:738
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Definition ah-dry.H:904
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition(Operation &&op) const
Overload of tpartition(Operation&) that accepts rvalues.
Definition ah-dry.H:1369
void for_each(Operation &operation) const
Const overload of for_each(Operation&).
Definition ah-dry.H:696
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(Operation &&op) const
Overload of partition(Operation&) that accepts rvalues.
Definition ah-dry.H:1285
Container * me()
Definition ah-dry.H:549
Aleph::DynList< T > take(size_t i, const size_t j, const size_t step=1) const
Return a list with elements seen in the container between i and j position respect to its traversal.
Definition ah-dry.H:1444
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > split_half() const
Split the container into two halves by alternating elements.
Definition ah-dry.H:1321
__T fold_left(const __T &init, Op &op) const
Alias for foldl with the same accumulator type.
Definition ah-dry.H:1065
void for_each(Operation &&operation)
Overload of for_each(Operation&) that accepts rvalues.
Definition ah-dry.H:710
Aleph::DynList< T > drop(const size_t n) const
Drop the first n elements seen in the container during its traversal.
Definition ah-dry.H:1467
Common sequential searching methods on containers.
Definition ah-dry.H:164
static constexpr bool operation_is_noexcept() noexcept
Definition ah-dry.H:178
size_t find_index(Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
Overload of find_index(Operation&) that accepts rvalues.
Definition ah-dry.H:413
std::tuple< bool, Type > find_item(Operation &operation) noexcept(operation_is_noexcept< Operation >())
Safe sequential searching of an item matching a criteria.
Definition ah-dry.H:440
Type * find_ptr(Operation &operation) noexcept(operation_is_noexcept< Operation >())
Find a pointer to an item in the container according to a searching criteria.
Definition ah-dry.H:318
auto get_itor() const
Alias of get_it().
Definition ah-dry.H:218
size_t find_index(Operation &operation) const noexcept(operation_is_noexcept< Operation >())
Find the position of an item in the container according to a searching criteria.
Definition ah-dry.H:393
Type * find_ptr(Operation &&operation) noexcept(operation_is_noexcept< Operation >())
Overload of find_ptr(Operation&) that accepts rvalues.
Definition ah-dry.H:364
Container * me() noexcept
Definition ah-dry.H:165
Type & nth_ne(const size_t n) noexcept
Return the n‑th element without bounds checking.
Definition ah-dry.H:226
const Type * find_ptr(Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
Overload of find_ptr(Operation&) const that accepts rvalues.
Definition ah-dry.H:352
LocateFunctions< Container, Type > * base() const
Definition ah-dry.H:172
const Type & nth(const size_t n) const
Const overload of nth(size_t).
Definition ah-dry.H:290
Type & nth(const size_t n)
Return the n-th item of container.
Definition ah-dry.H:267
std::tuple< bool, Type > find_item(Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
Definition ah-dry.H:468
const Type * find_ptr(Operation &operation) const noexcept(operation_is_noexcept< Operation >())
Const overload of find_ptr(Operation&).
Definition ah-dry.H:340
std::tuple< bool, Type > find_item(Operation &operation) const noexcept(operation_is_noexcept< Operation >())
Definition ah-dry.H:450
const Container * const_me() const noexcept
Definition ah-dry.H:167
std::tuple< bool, Type > find_item(Operation &&operation) noexcept(operation_is_noexcept< Operation >())
Definition ah-dry.H:460
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:190
auto get_it(const size_t pos) const
Return a properly initialized iterator positioned at the pos item on the container.
Definition ah-dry.H:206
const Type & nth_ne(const size_t n) const noexcept
Const overload of nth_ne(size_t).
Definition ah-dry.H:246
Common methods to mapping containers.
Definition ah-dry.H:1591
C< Key > keys() const
Return the domain set of container.
Definition ah-dry.H:1613
C< std::pair< Key, Data * > > items_ptr() const
Return a container with the entire mapping where the range could be modified.
Definition ah-dry.H:1700
C< Data > values() const
Return the range set of container.
Definition ah-dry.H:1637
C< std::pair< Key, Data > > items() const
Return a container with the entire mapping.
Definition ah-dry.H:1681
Data & operator()(const Key &key)
Return the image or element mapped to key.
Definition ah-dry.H:1716
const Container * const_me() const
Definition ah-dry.H:1592
C< Data * > values_ptr() const
Return a container of pointers to the elements of range set of container.
Definition ah-dry.H:1663
#define TT
Definition ran_array.c:29
Generic list of items stored in a container.
Definition ah-dry.H:1501
Aleph::DynList< T > keys() const
Definition ah-dry.H:1516
Aleph::DynList< T > items() const
Return a list of all the elements of a container sorted by traversal order.
Definition ah-dry.H:1509
Generic traversal of the container through its iterator.
Definition ah-dry.H:65
bool traverse(Operation &&operation) const noexcept(traverse_is_noexcept< Operation >())
Overload of traverse(Operation&) const that accepts rvalues.
Definition ah-dry.H:113
bool traverse(Operation &operation) const noexcept(traverse_is_noexcept< Operation >())
Const overload of traverse(Operation&).
Definition ah-dry.H:106
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.
Definition ah-dry.H:95
bool traverse(Operation &&operation) noexcept(traverse_is_noexcept< Operation >())
Overload of traverse(Operation&) that accepts rvalues.
Definition ah-dry.H:120
static constexpr bool traverse_is_noexcept() noexcept
Definition ah-dry.H:68
Special constructors common to Aleph-w ( ) containers.
Definition ah-dry.H:492
SpecialCtors(const SpecialCtors &)=default
SpecialCtors(SpecialCtors &&) noexcept
Definition ah-dry.H:497
SpecialCtors(std::initializer_list< T > l)
Construct the container from an initializer list.
Definition ah-dry.H:531
SpecialCtors & operator=(const SpecialCtors &)
Definition ah-dry.H:499
SpecialCtors(It b, It e)
Construct the container from a range of iterators.
Definition ah-dry.H:521
SpecialCtors(const Aleph::DynList< T > &l)
Build the container by inserting all items of list l.
Definition ah-dry.H:507
SpecialCtors()=default
DynList< int > l