69template <
class Container>
73 template <
class Operation>
76 return noexcept(std::declval<Operation &>()(std::declval<typename Container::Item_Type &>()));
99 template <
class Operation>
101 bool traverse(Operation &operation)
noexcept(traverse_is_noexcept<Operation>())
103 for (
typename Container::Iterator it(*
static_cast<Container *
>(
this)); it.has_curr(); it.next())
104 if (not operation(it.get_curr()))
110 template <
class Operation>
112 bool traverse(Operation &operation)
const noexcept(traverse_is_noexcept<Operation>())
114 return const_cast<GenericTraverse *
>(
this)->traverse<Operation>(operation);
120 template <
class Operation>
122 bool traverse(Operation &&operation)
const noexcept(traverse_is_noexcept<Operation>())
124 return traverse<Operation>(operation);
130 template <
class Operation>
132 bool traverse(Operation &&operation)
noexcept(traverse_is_noexcept<Operation>())
134 return traverse<Operation>(operation);
150template <
class Container,
class Operation>
153 return c.traverse(op);
170template <
class Container,
class Operation>
173 return c.traverse(op);
198template <
class Container,
typename Type>
208 return static_cast<const Container *
>(
this);
216 template <
class Operation>
219 return noexcept(std::declval<Operation &>()(std::declval<Type &>()));
230 return typename Container::Iterator(*
const_me());
246 auto ret =
typename Container::Iterator(*
const_me());
247 for (
size_t i = 0; i < pos; ++i)
271 me()->traverse([&ptr, &i, &n](Type &item)
287 const Type &
nth_ne(
const size_t n)
const noexcept
289 return base()->nth_ne(n);
312 me()->traverse([&ptr, &i, &n](Type &item)
331 const Type &
nth(
const size_t n)
const
333 return base()->nth(n);
357 template <
class Operation>
359 Type *
find_ptr(Operation &operation)
noexcept(operation_is_noexcept<Operation>())
362 me()->traverse([&ptr, &operation](Type &item)
379 template <
class Operation>
381 const Type *
find_ptr(Operation &operation)
const noexcept(operation_is_noexcept<Operation>())
383 return base()->find_ptr(operation);
397 template <
class Operation>
399 const Type *
find_ptr(Operation &&operation)
const noexcept(operation_is_noexcept<Operation>())
401 return find_ptr<Operation>(operation);
415 template <
class Operation>
417 Type *
find_ptr(Operation &&operation)
noexcept(operation_is_noexcept<Operation>())
419 return find_ptr<Operation>(operation);
444 template <
class Operation>
446 size_t find_index(Operation &operation)
const noexcept(operation_is_noexcept<Operation>())
449 const_me()->traverse([&i, &operation](
const Type &item)
470 template <
class Operation>
472 size_t find_index(Operation &&operation)
const noexcept(operation_is_noexcept<Operation>())
474 return find_index<Operation>(operation);
497 template <
class Operation>
499 std::tuple<bool, Type>
find_item(Operation &operation)
noexcept(operation_is_noexcept<Operation>())
501 using TT = std::tuple<bool, Type>;
503 return ptr ?
TT(
true, *ptr) :
TT(
false, Type());
507 template <
class Operation>
509 std::tuple<bool, Type>
find_item(Operation &operation)
const
510 noexcept(operation_is_noexcept<Operation>())
512 using TT = std::tuple<bool, Type>;
514 return ptr ?
TT(
true, *ptr) :
TT(
false, Type());
528 template <
class Operation>
530 std::tuple<bool, Type>
find_item(Operation &&operation)
noexcept(operation_is_noexcept<Operation>())
532 return find_item<Operation>(operation);
546 template <
class Operation>
548 std::tuple<bool, Type>
find_item(Operation &&operation)
const
549 noexcept(operation_is_noexcept<Operation>())
551 return find_item<Operation>(operation);
561 template <
class Operation>
563 bool contains_if(Operation &&operation)
const noexcept(operation_is_noexcept<Operation>())
565 return find_ptr(operation) !=
nullptr;
598template <
class Container,
typename T>
622 static_cast<Container *
>(
this)->append(item);
634 for (
It it = b; it != e; ++it)
635 static_cast<Container *
>(
this)->append(*it);
644 for (
const auto &item :
l)
645 static_cast<Container *
>(
this)->append(item);
656template <
class Container,
typename T>
671 return static_cast<const Container *
>(
this);
693 template <
typename... Args>
696 (void)
me()->append(T(std::forward<Args>(args)...));
700 template <
typename... Args>
703 (void)
me()->append(T(std::forward<Args>(args)...));
724 template <
typename... Args>
727 (void)
me()->insert(T(std::forward<Args>(args)...));
734 template <
typename... Args>
735 void nninsert(
size_t &n,
const T &item, Args &...args)
737 (void)
me()->insert(item);
742 template <
typename... Args>
743 void nnappend(
size_t &n,
const T &item, Args &...args)
745 (void)
me()->append(item);
756 template <
typename... Args>
769 template <
typename... Args>
794 template <
class Operation>
798 me()->traverse([&operation](
const T &item)
806 template <
class Operation>
810 base()->for_each(operation);
823 template <
class Operation>
827 for_each<Operation>(operation);
840 template <
class Operation>
844 for_each<Operation>(operation);
848 template <
class Operation>
850 void each(Operation &operation)
856 template <
class Operation>
858 void each(Operation &operation)
const
873 template <
class Operation>
875 void each(Operation &&operation)
const
877 for_each<Operation>(operation);
890 template <
class Operation>
892 void each(Operation &&operation)
894 for_each<Operation>(operation);
917 template <
class Operation>
918 void each(
size_t pos,
const size_t slice, Operation &operation)
const
925 operation(it.get_curr());
926 for (
size_t k = 0;
k < slice; ++
k)
929 if (not it.has_curr())
936 template <
class Operation>
937 void each(
const size_t pos,
const size_t slice, Operation &&operation)
const
939 each<Operation>(pos, slice, operation);
951 template <
class Operation>
955 me()->traverse([&operation](T &item)
963 template <
class Operation>
967 mutable_for_each<Operation>(operation);
982 template <
class Operation>
984 bool all(Operation &operation)
const
986 return const_me()->traverse(operation);
1000 template <
class Operation>
1002 bool all(Operation &&operation)
const
1004 return all<Operation>(operation);
1020 template <
class Operation>
1024 return not
const_me()->traverse([&op](
const T &i)
1041 template <
class Operation>
1045 return exists<Operation>(op);
1088 template <
typename __T = T,
class Operation = Aleph::Dft_Map_Op<T, __T>>
1093 const_me()->for_each([&ret_val, &op](
const T &item)
1095 ret_val.
append(op(item));
1112 template <
typename __T = T,
class Operation = Aleph::Dft_Map_Op<__T, __T>>
1116 return maps<__T, Operation>(op);
1135 template <
typename __T = T,
class Prop,
class Operation>
1141 const_me()->for_each([&ret_val, &prop, &op](
const T &item)
1144 ret_val.
append(op(item));
1163 template <
typename __T = T,
class Prop,
class Operation>
1168 return maps_if<__T, Prop, Operation>(prop, op);
1180 template <
typename __T = T,
class Operation = Aleph::Dft_Map_Op<T, __T>>
1184 return maps<__T, Operation>(op);
1195 template <
typename __T = T,
class Operation = Aleph::Dft_Map_Op<__T, __T>>
1199 return maps<__T, Operation>(op);
1209 template <
typename __T = T,
class Prop,
class Operation>
1214 return maps_if<__T, Prop, Operation>(prop, op);
1227 template <
typename __T = T,
class Prop,
class Operation>
1232 return maps_if<__T, Prop, Operation>(prop, op);
1241 return maps([](
auto &item)
1254 if constexpr (
requires {
const_me()->size(); })
1256 const_me()->for_each([&ret](
const T &item)
1258 ret.push_back(item);
1310 template <
typename __T = T,
class Op = Aleph::Dft_Fold_Op<__T, T>>
1311 requires requires(__T &acc, Op &op,
const T &item) { acc = op(acc, item); }
1312 __T
foldl(
const __T &init, Op &op)
const
1315 const_me()->for_each([&ret_val, &op](
const T &item)
1317 ret_val = op(ret_val, item);
1335 template <
typename __T = T,
class Op = Aleph::Dft_Fold_Op<__T, T>>
1336 requires requires(__T &acc, Op &op,
const T &item) { acc = op(acc, item); }
1337 __T
foldl(
const __T &init, Op &&op = Op())
const
1339 return foldl<__T, Op>(init, op);
1349 template <
typename __T = T,
class Op = Aleph::Dft_Fold_Op<__T, T>>
1350 requires requires(__T &acc, Op &op,
const T &item) { acc = op(acc, item); }
1353 return const_me()->template foldl<__T>(init, op);
1369 template <
typename __T = T,
class Op = Aleph::Dft_Fold_Op<__T, T>>
1370 requires requires(__T &acc, Op &op,
const T &item) { acc = op(acc, item); }
1373 return const_me()->template foldl<__T>(init, op);
1381 template <
class Operation>
1382 requires requires(T &acc, Operation &op,
const T &item) { acc = op(acc, item); }
1383 T
fold(
const T &init, Operation &operation)
const
1385 auto ret_val = init;
1386 const_me()->for_each([&ret_val, &operation](
const T &item)
1388 ret_val = operation(ret_val, item);
1405 template <
class Operation>
1406 requires requires(T &acc, Operation &op,
const T &item) { acc = op(acc, item); }
1407 T
fold(
const T &init, Operation &&operation)
const
1409 return fold<Operation>(init, operation);
1435 template <
class Operation>
1440 const_me()->for_each([&ret_val, &operation](
const T &item)
1442 if (operation(item))
1459 template <
class Operation>
1463 return filter<Operation>(operation);
1489 template <
class Operation>
1494 const_me()->for_each([&ret_val, &operation](
const T &item)
1496 if (operation(item))
1513 template <
class Operation>
1517 return ptr_filter<Operation>(operation);
1539 template <
class Operation>
1543 using TT = std::tuple<T, size_t>;
1546 const_me()->for_each([&ret_val, &operation, &i](
const T &item)
1548 if (operation(item))
1566 template <
class Operation>
1570 return pfilter<Operation>(operation);
1590 template <
class Operation>
1595 const_me()->for_each([&ret_val, &op](
const T &item)
1598 ret_val.first.append(item);
1600 ret_val.second.append(item);
1616 template <
class Operation>
1620 return partition<Operation>(op);
1637 const_me()->for_each([&ret_val, &i, n](
const T &item)
1640 ret_val.first.append(item);
1642 ret_val.second.append(item);
1657 const_me()->for_each([&ret_val, &i](
const T &item)
1660 ret_val.first.append(item);
1662 ret_val.second.append(item);
1681 template <
class Operation>
1686 const_me()->for_each([&r1, &r2, &op](
const T &item)
1707 template <
class Operation>
1711 return tpartition<Operation>(op);
1728 const_me()->for_each([&count](
const T &)
1745 const_me()->for_each([&ret](
const T &i)
1768 const_me()->traverse([&i, &ret, n](
const T &item)
1795 for (
auto it =
const_me()->get_it(i); i <= j
and it.has_curr(); it.next_ne(), i += step)
1796 ret.
append(it.get_curr());
1816 const_me()->traverse([&i, &ret, n](
const T &item)
1835 for (
size_t i = 0; i < n; ++i)
1844template <
class Container,
typename T>
1856 return static_cast<const Container *
>(
this)->Container::template maps<T>([](
const T &key)
1873template <
class Container,
typename T>
1889template <
class Container>
1894 return static_cast<const Container *
>(
this);
1918 auto it2 =
r.get_it();
1920 while (it1.has_curr())
1922 if (not(it1.get_curr() == it2.get_curr()))
1957template <
class Container>
1962 return static_cast<const Container *
>(
this);
1992 return const_me()->all([&
r](
const typename Container::Key_Type &
k)
1994 return r.search(
k) !=
nullptr;
2015template <
class Container,
typename Key,
typename Data>
2020 return static_cast<const Container *
>(
this);
2046 const_me()->for_each([&ret_val](
const Key &p)
2048 ret_val.append(p.first);
2070 const_me()->for_each([&ret_val](
const std::pair<Key, Data> &p)
2072 ret_val.append(p.second);
2096 const_me()->for_each([&ret_val](std::pair<Key, Data> &p)
2098 ret_val.append(&p.second);
2115 C<std::pair<Key, Data>> ret;
2116 const_me()->for_each([&ret](std::pair<Key, Data> &p)
2137 C<std::pair<Key, Data *>> ret_val;
2138 const_me()->for_each([&ret_val](std::pair<Key, Data> &p)
2140 ret_val.append(std::pair<Key, Data *>(p.first, &p.second));
2156 return me()->find(key);
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
bool traverse(const Container &c, Operation &op) noexcept(noexcept(c.traverse(op)))
Invoke c.traverse(op) as a free function (lvalue operation).
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.
Functional programming utilities for Aleph-w containers.
Doubly-linked list (defined in tpl_dynList.H).
T & insert(const T &item)
T & append(const T &item)
Mixin providing equality comparison for sequence containers.
bool operator==(const Container &r) const
Equality operator.
bool operator!=(const Container &r) const
Inequality operator.
bool equal_to(const Container &r) const
Equality test between this and r.
const Container * const_me() const noexcept
Equality test for containers.
const Container * const_me() const
bool operator!=(const Container &r) const noexcept
Negation of equal_to()
bool operator==(const Container &r) const noexcept
bool equal_to(const Container &r) const noexcept
Test if elements of this are exactly contained in another container.
Common methods to the Aleph-w ( ) containers.
Aleph::DynList< const T * > ptr_filter(Operation &&operation) const
Overload of ptr_filter() that accepts rvalues.
Aleph::DynList< std::tuple< T, size_t > > pfilter(Operation &&operation) const
Overload of pfilter() that accepts rvalues.
void emplace_end(Args &&...args)
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criterion.
std::vector< T > to_vector() const
Convert container to std::vector.
Aleph::DynList< __T > maps_if(Prop prop, Operation &op) const
void each(Operation &&operation)
Alias of each() that accepts rvalues.
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(size_t n) const
Exclusive partition of container in the nth item.
Aleph::DynList< __T > map_if(Prop prop, Operation &&op) const
bool exists(Operation &op) const
Test for existence in the container of an element satisfying a criterion.
Aleph::DynList< T > to_dynlist() const
Convert container to DynList.
void each(Operation &operation)
Alias of for_each(Operation&).
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...
Aleph::DynList< std::tuple< T, size_t > > pfilter(Operation &operation) const
Filter the elements of a container according to a matching criterion and determine its positions resp...
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition(Operation &op) const
Exclusive partition of container according to a filter criterion.
Aleph::DynList< __T > maps(Operation &&op) const
Overload of maps() that accepts rvalues.
FunctionalMethods< Container, T > * base() const noexcept
size_t ninsert(Args... args)
Insert n variadic items.
void each(const size_t pos, const size_t slice, Operation &&operation) const
__T foldl(const __T &init, Op &op) const
Fold the elements of the container to a specific result.
void emplace_ins(Args &&...args)
Insert a new element into the container by constructing it in-place with the given args.
bool all(Operation &&operation) const
Overload of all() that accepts rvalues.
void each(Operation &operation) const
Const alias of for_each(Operation&).
Aleph::DynList< __T > map(Operation &&op) const
Overload of map() that accepts rvalues.
Aleph::DynList< T > take(const size_t n) const
Return a list with the first n elements seen in the container during its traversal.
static void nnappend(size_t &)
Aleph::DynList< __T > maps_if(Prop prop, Operation &&op) const
Aleph::DynList< const T * > ptr_filter(Operation &operation) const
Filter the elements of a container according to a matching criterion and return a pointer to the matc...
const Container * const_me() const noexcept
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...
Aleph::DynList< T > rev() const
Return a list with the elements of container in reverse order respect to its traversal order.
void mutable_for_each(Operation &operation)
Apply a mutable operation to each element of the container.
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition(Operation &&op) const
Overload of tpartition() that accepts rvalues.
static void nninsert(size_t &)
__T fold_left(const __T &init, Op &&op=Op()) const
Overload of fold_left() that accepts rvalues.
Aleph::DynList< T > filter(Operation &&operation) const
Overload of filter() that accepts rvalues.
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(Operation &&op) const
Overload of partition() that accepts rvalues.
Aleph::DynList< __T > map(Operation &op) const
Synonym of maps().
size_t length() const noexcept
Count the number of elements of a container.
__T foldl(const __T &init, Op &&op=Op()) const
Overload of foldl() that accepts rvalues.
size_t nappend(Args... args)
Append n variadic items.
void nninsert(size_t &n, const T &item, Args &...args)
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
void for_each(Operation &&operation) const
Overload of for_each() const that accepts rvalues.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
void each(Operation &&operation) const
Const alias of each() that accepts rvalues.
Aleph::DynList< __T > map_if(Prop prop, Operation &op) const
void mutable_drop(const size_t n)
Drop the first n elements seen from container.
bool all(Operation &operation) const
Check if all the elements of the container satisfy a condition.
T fold(const T &init, Operation &&operation) const
Overload of fold() that accepts rvalues.
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.
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > split_half() const
Split the container into two halves by alternating elements.
void for_each(Operation &operation) const
Const overload of for_each(Operation&).
void emplace(Args &&...args)
Appends a new element into the container by constructing it in-place with the given args.
void nnappend(size_t &n, const T &item, Args &...args)
and
Conditional mapping of the elements of the container.
Aleph::DynList< T > drop(const size_t n) const
Drop the first n elements seen in the container during its traversal.
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(Operation &op) const
Exclusive partition of container according to a filter criterion.
bool exists(Operation &&op) const
Overload of exists() that accepts rvalues.
__T fold_left(const __T &init, Op &op) const
Alias for foldl with the same accumulator type.
void for_each(Operation &&operation)
Overload of for_each() that accepts rvalues.
void mutable_for_each(Operation &&operation)
Common sequential searching methods on containers.
static constexpr bool operation_is_noexcept() noexcept
auto get_itor() const
Alias of get_it().
std::tuple< bool, Type > find_item(Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
Overload of find_item() const that accepts rvalues.
const Type * find_ptr(Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
Overload of find_ptr() const that accepts rvalues.
Container * me() noexcept
Type & nth_ne(const size_t n) noexcept
Return the n‑th element without bounds checking.
std::tuple< bool, Type > find_item(Operation &operation) noexcept(operation_is_noexcept< Operation >())
Safe sequential searching of an item matching a criterion.
std::tuple< bool, Type > find_item(Operation &operation) const noexcept(operation_is_noexcept< Operation >())
bool contains(const Type &item) const
Test if an item is present in the container using equality.
LocateFunctions< Container, Type > * base() const
Type * find_ptr(Operation &operation) noexcept(operation_is_noexcept< Operation >())
Find a pointer to an item in the container according to a searching criterion.
const Type & nth(const size_t n) const
Const overload of nth(size_t).
Type & nth(const size_t n)
Return the n-th item of the container.
const Container * const_me() const noexcept
Type * find_ptr(Operation &&operation) noexcept(operation_is_noexcept< Operation >())
Overload of find_ptr() that accepts rvalues.
std::tuple< bool, Type > find_item(Operation &&operation) noexcept(operation_is_noexcept< Operation >())
Overload of find_item() that accepts rvalues.
size_t find_index(Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
Overload of find_index() that accepts rvalues.
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 criterion.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
auto get_it(const size_t pos) const
Return a properly initialized iterator positioned at the pos item on the container.
const Type * find_ptr(Operation &operation) const noexcept(operation_is_noexcept< Operation >())
Const overload of find_ptr(Operation&).
bool contains_if(Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
Test if an item satisfying a criterion is present in the container.
const Type & nth_ne(const size_t n) const noexcept
Const overload of nth_ne(size_t).
Common methods to mapping containers.
C< Key > keys() const
Return the domain set of container.
C< std::pair< Key, Data * > > items_ptr() const
Return a container with the entire mapping where the range could be modified.
C< Data > values() const
Return the range set of container.
C< std::pair< Key, Data > > items() const
Return a container with the entire mapping.
Data & operator()(const Key &key)
Return the image or element mapped to key.
const Container * const_me() const
C< Data * > values_ptr() const
Return a container of pointers to the elements of range set of container.
f(args...) is a valid call expression, exactly as written.
f(args...) is a valid call whose result is usable as a condition.
Main namespace for Aleph-w library functions.
Generic list of items stored in a container.
Aleph::DynList< T > keys() const
Aleph::DynList< T > items() const
Return a list of all the elements of a container sorted by traversal order.
Generic traversal of the container through its iterator.
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.
bool traverse(Operation &&operation) noexcept(traverse_is_noexcept< Operation >())
Overload of traverse(Operation&) that accepts rvalues.
bool traverse(Operation &operation) const noexcept(traverse_is_noexcept< Operation >())
Const overload of traverse(Operation&).
bool traverse(Operation &&operation) const noexcept(traverse_is_noexcept< Operation >())
Overload of traverse(Operation&) const that accepts rvalues.
static constexpr bool traverse_is_noexcept() noexcept
Special constructors common to Aleph-w ( ) containers.
SpecialCtors(const SpecialCtors &)=default
SpecialCtors(SpecialCtors &&) noexcept
SpecialCtors(std::initializer_list< T > l)
Construct the container from an initializer list.
SpecialCtors(It b, It e)
Construct the container from a range of iterators.
SpecialCtors(const Aleph::DynList< T > &l)
Build the container by inserting all items of the list l.
SpecialCtors & operator=(const SpecialCtors &)=default
Filter_Iterator< DynList< int >, DynList< int >::Iterator, Par > It