52namespace Aleph {
template <
class>
class Array; }
65template <
class Container>
69 template <
class Operation>
72 return noexcept(std::declval<Operation&>()(
73 std::declval<typename Container::Item_Type&>()));
96 template <
class Operation>
97 bool traverse(Operation & operation)
noexcept(traverse_is_noexcept<Operation>())
99 for (
typename Container::Iterator it(*
static_cast<Container*
>(
this));
100 it.has_curr(); it.next())
101 if (not operation(it.get_curr()))
107 template <
class Operation>
108 bool traverse(Operation & operation)
const noexcept(traverse_is_noexcept<Operation>())
110 return const_cast<GenericTraverse*
>(
this)->traverse<Operation>(operation);
116 template <
class Operation>
117 bool traverse(Operation && operation)
const noexcept(traverse_is_noexcept<Operation>())
119 return traverse<Operation>(operation);
125 template <
class Operation>
126 bool traverse(Operation && operation)
noexcept(traverse_is_noexcept<Operation>())
128 return traverse<Operation>(operation);
144template <
class Container,
class Operation>
146 noexcept(
noexcept(c.traverse(op)))
148 return c.traverse(op);
165template <
class Container,
class Operation>
167 noexcept(
noexcept(c.traverse(op)))
169 return c.traverse(op);
194template <
class Container,
typename Type>
201 return static_cast<const Container*
>(
this);
209 template <
class Operation>
212 return noexcept(std::declval<Operation&>()(std::declval<Type&>()));
224 return typename Container::Iterator(*
const_me());
240 auto ret =
typename Container::Iterator(*
const_me());
241 for (
size_t i = 0; i < pos; ++i)
260 Type * ptr =
nullptr;
262 me()->traverse([&ptr, &i, &n] (Type & item)
278 const Type &
nth_ne(
const size_t n)
const noexcept
280 return base()->nth_ne(n);
299 Type &
nth(
const size_t n)
301 Type * ptr =
nullptr;
303 me()->traverse([&ptr, &i, &n] (Type & item)
322 const Type &
nth(
const size_t n)
const
324 return base()->nth(n);
348 template <
class Operation>
350 noexcept(operation_is_noexcept<Operation>())
352 Type * ptr =
nullptr;
353 me()->traverse([&ptr,&operation] (Type & item)
370 template <
class Operation>
372 noexcept(operation_is_noexcept<Operation>())
374 return base()->find_ptr(operation);
388 template <
class Operation>
389 const Type *
find_ptr(Operation && operation)
const
390 noexcept(operation_is_noexcept<Operation>())
392 return find_ptr<Operation>(operation);
406 template <
class Operation>
408 noexcept(operation_is_noexcept<Operation>())
410 return find_ptr<Operation>(operation);
435 template <
class Operation>
437 noexcept(operation_is_noexcept<Operation>())
440 const_me()->traverse([&i,&operation] (Type & item)
461 template <
class Operation>
463 noexcept(operation_is_noexcept<Operation>())
465 return find_index<Operation>(operation);
488 template <
class Operation>
490 noexcept(operation_is_noexcept<Operation>())
492 using TT = std::tuple<bool, Type>;
494 return ptr ?
TT(
true, *ptr) :
TT(
false, Type());
498 template <
class Operation>
499 std::tuple<bool, Type>
find_item(Operation & operation)
const
500 noexcept(operation_is_noexcept<Operation>())
502 using TT = std::tuple<bool, Type>;
504 return ptr ?
TT(
true, *ptr) :
TT(
false, Type());
518 template <
class Operation>
519 std::tuple<bool, Type>
find_item(Operation && operation)
520 noexcept(operation_is_noexcept<Operation>())
522 return find_item<Operation>(operation);
536 template <
class Operation>
537 std::tuple<bool, Type>
find_item(Operation && operation)
const
538 noexcept(operation_is_noexcept<Operation>())
540 return find_item<Operation>(operation);
550 template <
class Operation>
552 noexcept(operation_is_noexcept<Operation>())
554 return find_ptr(operation) !=
nullptr;
565 return contains_if([&item] (
const Type & x) {
return x == item; });
584template <
class Container,
typename T>
605 static_cast<Container*
>(
this)->append(item);
617 for (
It it = b; it != e; ++it)
618 static_cast<Container*
>(
this)->append(*it);
627 for (
const auto & item :
l)
628 static_cast<Container*
>(
this)->append(item);
640template <
class Container,
typename T>
652 return static_cast<const Container*
>(
this);
675 template <
typename ...Args>
678 (void)
me()->append(T(std::forward<Args>(args)...));
682 template <
typename ...Args>
685 (void)
me()->append(T(std::forward<Args>(args)...));
706 template <
typename ...Args>
709 (void)
me()->insert(T(std::forward<Args>(args)...));
717 template <
typename ... Args>
718 void nninsert(
size_t & n,
const T & item, Args & ... args)
720 (void)
me()->insert(item);
725 template <
typename ... Args>
726 void nnappend(
size_t & n,
const T & item, Args & ... args)
728 (void)
me()->append(item);
740 template <
typename ... Args>
753 template <
typename ... Args>
778 template <
class Operation>
781 me()->traverse([&operation] (
const T & item)
789 template <
class Operation>
792 base()->for_each(operation);
805 template <
class Operation>
808 for_each<Operation>(operation);
821 template <
class Operation>
824 for_each<Operation>(operation);
828 template <
class Operation>
829 void each(Operation & operation)
835 template <
class Operation>
836 void each(Operation & operation)
const
851 template <
class Operation>
852 void each(Operation && operation)
const
854 for_each<Operation>(operation);
867 template <
class Operation>
868 void each(Operation && operation)
870 for_each<Operation>(operation);
893 template <
class Operation>
894 void each(
size_t pos,
const size_t slice, Operation & operation)
const
901 operation(it.get_curr());
902 for (
size_t k = 0;
k < slice; ++
k)
905 if (not it.has_curr())
912 template <
class Operation>
913 void each(
const size_t pos,
const size_t slice, Operation && operation)
const
915 each<Operation>(pos, slice, operation);
927 template <
class Operation>
930 me()->traverse([&operation] (T & item)
938 template <
class Operation>
941 mutable_for_each<Operation>(operation);
956 template <
class Operation>
957 bool all(Operation & operation)
const
959 return const_me()->traverse(operation);
973 template <
class Operation>
974 bool all(Operation && operation)
const
976 return all<Operation>(operation);
992 template <
class Operation>
996 traverse([&op] (
const T & i) {
return not op(i); });
1010 template <
class Operation>
1013 return exists<Operation>(op);
1056 template <
typename __T = T,
class Operation = Aleph::Dft_Map_Op<T, __T>>
1060 const_me()->for_each([&ret_val, &op] (
const T & item)
1062 ret_val.
append(op(item));
1079 template <
typename __T = T,
class Operation = Aleph::Dft_Map_Op<__T, __T>>
1098 template <
typename __T = T,
class Prop,
class Operation>
1102 const_me()->for_each([&ret_val, &prop, &op] (
const T & item)
1105 ret_val.
append(op(item));
1124 template <
typename __T = T,
class Prop,
class Operation>
1127 return maps_if<__T, Prop, Operation>(prop, op);
1136 return maps([] (
auto & item) {
return item; });
1146 if constexpr (
requires {
const_me()->size(); })
1148 const_me()->for_each([&ret] (
const T & item) { ret.push_back(item); });
1199 template <
typename __T = T,
class Op = Aleph::Dft_Fold_Op<__T, T>>
1200 __T
foldl(
const __T & init, Op & op)
const
1203 const_me()->for_each([&ret_val, &op] (
const T & item)
1205 ret_val = op(ret_val, item);
1223 template <
typename __T = T,
class Op = Aleph::Dft_Fold_Op<__T, T>>
1224 __T
foldl(
const __T & init, Op && op = Op())
const
1226 return foldl<__T, Op>(init, op);
1236 template <
typename __T = T,
class Op = Aleph::Dft_Fold_Op<__T, T>>
1239 return const_me()->template foldl<__T>(init, op);
1255 template <
typename __T = T,
class Op = Aleph::Dft_Fold_Op<__T, T>>
1258 return const_me()->template foldl<__T>(init, op);
1266 template <
class Operation>
1267 T
fold(
const T & init, Operation & operation)
const
1269 auto ret_val = init;
1270 const_me()->for_each([&ret_val, &operation] (
const T & item)
1272 ret_val = operation(ret_val, item);
1289 template <
class Operation>
1290 T
fold(
const T & init, Operation && operation)
const
1292 return fold<Operation>(init, operation);
1318 template <
class Operation>
1322 const_me()->for_each([&ret_val, &operation] (
const T & item)
1324 if (operation(item))
1341 template <
class Operation>
1344 return filter<Operation>(operation);
1370 template <
class Operation>
1374 const_me()->for_each([&ret_val, &operation] (
const T & item)
1376 if (operation(item))
1393 template <
class Operation>
1396 return ptr_filter<Operation>(operation);
1418 template <
class Operation>
1421 using TT = std::tuple<T, size_t>;
1424 const_me()->for_each([&ret_val, &operation, &i] (
const T & item)
1426 if (operation(item))
1444 template <
class Operation>
1447 return pfilter<Operation>(operation);
1467 template <
class Operation>
1471 const_me()->for_each([&ret_val, &op] (
const T & item)
1474 ret_val.first.append(item);
1476 ret_val.second.append(item);
1492 template <
class Operation>
1495 return partition<Operation>(op);
1512 const_me()->for_each([&ret_val, &i, n] (
const T & item)
1515 ret_val.first.append(item);
1517 ret_val.second.append(item);
1532 const_me()->for_each([&ret_val, &i] (
const T & item)
1535 ret_val.first.append(item);
1537 ret_val.second.append(item);
1556 template <
class Operation>
1560 const_me()->for_each([&r1, &r2, &op] (
const T & item)
1581 template <
class Operation>
1584 return tpartition<Operation>(op);
1601 const_me()->for_each([&count] (
const T &) { ++count; });
1635 const_me()->traverse([&i, &ret, n] (
const T & item)
1662 for (
auto it =
const_me()->get_it(i); i <= j and it.has_curr();
1663 it.next_ne(), i += step)
1664 ret.
append(it.get_curr());
1684 const_me()->traverse([&i, &ret, n] (
const T & item)
1703 for (
size_t i = 0; i < n; ++i)
1712template <
class Container,
typename T>
1724 return static_cast<const Container*
>(
this)->
1725 Container::template maps<T> ([] (
const T & key) {
return key; });
1737template <
class Container,
typename T>
1754template <
class Container>
1759 return static_cast<const Container*
>(
this);
1784 auto it2 =
r.get_it();
1786 while (it1.has_curr())
1788 if (not (it1.get_curr() == it2.get_curr()))
1824template <
class Container>
1829 return static_cast<const Container*
>(
this);
1860 return const_me()->all([&
r] (
const typename Container::Key_Type &
k)
1861 {
return r.search(
k) !=
nullptr; });
1881template <
class Container,
typename Key,
typename Data>
1886 return static_cast<const Container*
>(
this);
1908 const_me()->for_each([&ret_val] (
const Key & p)
1910 ret_val.append(p.first);
1932 const_me()->for_each([&ret_val] (
const std::pair<Key, Data> & p)
1934 ret_val.append(p.second);
1958 const_me()->for_each([&ret_val] (std::pair<Key, Data> & p)
1959 { ret_val.append(&p.second); });
1975 C<std::pair<Key, Data>> ret;
1976 const_me()->for_each([&ret] (std::pair<Key, Data> & p) { ret.append(p); });
1994 C<std::pair<Key, Data*>> ret_val;
1995 const_me()->for_each([&ret_val] (std::pair<Key, Data> & p)
1997 ret_val.append(std::pair<Key,Data*>(p.first,
2010 return this->find(key);
2020 return this->find(key);
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.
Dynamic singly linked list with functional programming support.
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.
void mutable_for_each(Operation &operation)
Apply a mutable operation to each element of the container.
Aleph::DynList< std::tuple< T, size_t > > pfilter(Operation &&operation) const
Overload of pfilter() that accepts rvalues.
void each(Operation &operation)
Alias of for_each(Operation&).
__T foldl(const __T &init, Op &op) const
Fold the elements of the container to a specific result.
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criterion.
Aleph::DynList< __T > maps(Operation &&op) const
Overload of maps() that accepts rvalues.
std::vector< T > to_vector() const
Convert container to std::vector.
Aleph::DynList< T > filter(Operation &&operation) const
Overload of filter() that accepts rvalues.
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(size_t n) const
Exclusive partition of container in the nth item.
__T foldl(const __T &init, Op &&op=Op()) const
Overload of foldl() that accepts rvalues.
Aleph::DynList< T > to_dynlist() const
Convert container to DynList.
void emplace(Args &&... args)
Appends a new element into the container by constructing it in-place with the given args.
void each(Operation &operation) const
Const alias of for_each(Operation&).
size_t ninsert(Args ... args)
Insert n variadic items.
__T fold_left(const __T &init, Op &&op=Op()) const
Overload of fold_left() that accepts rvalues.
Aleph::DynList< __T > maps_if(Prop prop, Operation &op) const
Conditional mapping of the elements of the container.
FunctionalMethods< Container, T > * base() const noexcept
Aleph::DynList< const T * > ptr_filter(Operation &&operation) const
Overload of ptr_filter() that accepts rvalues.
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(Operation &op) const
Exclusive partition of container according to a filter criterion.
void each(const size_t pos, const size_t slice, Operation &&operation) const
void emplace_ins(Args &&... args)
Insert a new element into the container by constructing it in-place with the given args.
void mutable_for_each(Operation &&operation)
Aleph::DynList< T > take(const size_t n) const
Return a list with the first n elements seen in the container during its traversal.
bool exists(Operation &op) const
Test for existence in the container of an element satisfying a criterion.
void nninsert(size_t &n, const T &item, Args &... args)
void each(Operation &&operation) const
Const alias of each() that accepts rvalues.
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition(Operation &op) const
Exclusive partition of container according to a filter criterion.
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...
size_t nappend(Args ... args)
Append n variadic items.
bool all(Operation &operation) const
Check if all the elements of the container satisfy a condition.
Aleph::DynList< T > rev() const
Return a list with the elements of container in reverse order respect to its traversal order.
void emplace_end(Args &&... args)
void nnappend(size_t &n, const T &item, Args &... args)
bool all(Operation &&operation) const
Overload of all() that accepts rvalues.
bool exists(Operation &&op) const
Overload of exists() that accepts rvalues.
size_t length() const noexcept
Count the number of elements of a container.
void for_each(Operation &&operation) const
Overload of for_each() const that accepts rvalues.
Aleph::DynList< __T > maps_if(Prop prop, Operation &&op) const
Overload of maps_if() that accepts rvalues.
T fold(const T &init, Operation &&operation) const
Overload of fold() that accepts rvalues.
void mutable_drop(const size_t n)
Drop the first n elements seen from container.
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...
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...
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
void each(Operation &&operation)
Alias of each() that accepts rvalues.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition(Operation &&op) const
Overload of tpartition() that accepts rvalues.
void for_each(Operation &operation) const
Const overload of for_each(Operation&).
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(Operation &&op) const
Overload of partition() 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.
__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.
Aleph::DynList< T > drop(const size_t n) const
Drop the first n elements seen in the container during its traversal.
Common sequential searching methods on containers.
static constexpr bool operation_is_noexcept() noexcept
size_t find_index(Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
Overload of find_index() that accepts rvalues.
std::tuple< bool, Type > find_item(Operation &operation) noexcept(operation_is_noexcept< Operation >())
Safe sequential searching of an item matching a criterion.
Type * find_ptr(Operation &operation) noexcept(operation_is_noexcept< Operation >())
Find a pointer to an item in the container according to a searching criterion.
auto get_itor() const
Alias of get_it().
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.
Type * find_ptr(Operation &&operation) noexcept(operation_is_noexcept< Operation >())
Overload of find_ptr() that accepts rvalues.
Container * me() noexcept
Type & nth_ne(const size_t n) noexcept
Return the n‑th element without bounds checking.
bool contains(const Type &item) const
Test if an item is present in the container using equality.
const Type * find_ptr(Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
Overload of find_ptr() const that accepts rvalues.
LocateFunctions< Container, Type > * base() const
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.
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 >())
Const overload of find_ptr(Operation&).
std::tuple< bool, Type > find_item(Operation &operation) const noexcept(operation_is_noexcept< Operation >())
const Container * const_me() const noexcept
std::tuple< bool, Type > find_item(Operation &&operation) noexcept(operation_is_noexcept< Operation >())
Overload of find_item() that accepts rvalues.
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.
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.
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) const noexcept(traverse_is_noexcept< Operation >())
Overload of traverse(Operation&) const that accepts rvalues.
bool traverse(Operation &operation) const noexcept(traverse_is_noexcept< Operation >())
Const overload of traverse(Operation&).
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.
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