86template<
typename T>
class DynList;
91template <
typename T,
typename R>
struct Dft_Map_Op;
114template <
typename Derived,
typename Type>
121 return static_cast<const Derived&
>(*this);
127 return static_cast<Derived&
>(*this);
165 template <
class Operation>
168 for (
typename Derived::Iterator it(
self()); it.has_curr(); it.next_ne())
175 template <
class Operation>
178 for (
typename Derived::Iterator it(
self()); it.has_curr(); it.next_ne())
186 template <
class Operation>
193 template <
class Operation>
221template <
typename Derived,
typename Type>
227 return static_cast<const Derived&
>(*this);
232 return static_cast<Derived&
>(*this);
258 Type * ptr =
nullptr;
289 Type * ptr =
nullptr;
326 template <
class Operation>
329 Type * ptr =
nullptr;
344 template <
class Operation>
347 Type * ptr =
nullptr;
362 template <
class Operation>
369 template <
class Operation>
399 template <
class Operation>
403 return ptr ? std::make_tuple(
true, *ptr) : std::make_tuple(
false,
Type());
407 template <
class Operation>
411 return ptr ? std::make_tuple(
true, *ptr) : std::make_tuple(
false,
Type());
415 template <
class Operation>
422 template <
class Operation>
456template <
typename Derived,
typename Type>
462 return static_cast<const Derived&
>(*this);
467 return static_cast<Derived&
>(*this);
492 template <
class Operation>
504 template <
class Operation>
516 template <
class Operation>
523 template <
class Operation>
544 template <
class Operation>
556 template <
class Operation>
584 template <
class Operation>
591 template <
class Operation>
600 template <
class Operation>
607 template <
class Operation>
631 template <
class Operation>
641 template <
class Operation>
729 template <
typename __Type = Type>
744 template <
typename __Type = Type>
760 template <
class Operation>
772 template <
class Operation>
797 template <
class Operation>
810 template <
class Operation>
831 template <
class Operation>
839 ret_val.append(std::make_tuple(item, i));
846 template <
class Operation>
868 template <
class Operation>
883 template <
class Operation>
892 template <
class Operation>
903 return std::make_tuple(
r1, r2);
907 template <
class Operation>
1047 requires requires(
Type a,
Type b) { { a + b } -> std::convertible_to<Type>; }
1052 result = result + item;
1075 requires requires(
Type a,
Type b) { { a * b } -> std::convertible_to<Type>; }
1080 result = result * item;
1104 const Type * result =
nullptr;
1107 if (result ==
nullptr or item < *result)
1132 const Type * result =
nullptr;
1135 if (result ==
nullptr or *result < item)
1158 template <
class Compare>
1161 const Type * result =
nullptr;
1164 if (result ==
nullptr or cmp(item, *result))
1187 template <
class Compare>
1190 const Type * result =
nullptr;
1193 if (result ==
nullptr or cmp(*result, item))
1225 requires requires(
Type a,
Type b) { { a == b } -> std::convertible_to<bool>; }
1227 return exists([&val] (
const Type & item) {
return item == val; });
1247 template <
class Predicate>
1254 template <
class Predicate>
1275 template <
class Predicate>
1306 const Type * result =
nullptr;
1307 self().traverse([&result] (
const Type & item)
1350 const Type * result =
nullptr;
1405 ret.append(std::make_pair(idx++, item));
1425 template <
class Predicate>
1429 size_t result =
static_cast<size_t>(-1);
1430 self().traverse([&idx, &result, &
pred] (
const Type & item)
1462 requires requires(
Type a,
Type b) { { a == b } -> std::convertible_to<bool>; }
1464 return find_index([&val] (
const Type & item) {
return item == val; });
1493 const Type * prev =
nullptr;
1496 if (prev ==
nullptr or not (*prev == item))
1527 const Type * prev =
nullptr;
1530 if (prev ==
nullptr or not eq(*prev, item))
1592 if (n == 0)
return ret;
1599 current.append(item);
1602 ret.append(std::move(current));
1609 ret.append(std::move(current));
1644 for (
size_t start = 0; start +
size <=
total; start +=
step)
1650 if (idx >= start
and idx < start +
size)
1653 return idx < start +
size;
1680 std::vector<Type>
ret;
1681 if constexpr (
requires {
self().size(); })
1705 template <
typename DynListType = DynList<Type>>
1730 template <
typename StringType = std::
string>
1732 requires requires(
Type a) { std::to_string(a); }
1740 ret += std::to_string(item);
1769 ret +=
static_cast<std::string
>(item);
1802 using OtherType =
typename Other::Item_Type;
1805 auto it1 =
self().get_it();
1806 auto it2 =
other.get_it();
1808 while (it1.has_curr()
and it2.has_curr())
1810 ret.append(std::make_pair(it1.get_curr(), it2.get_curr()));
1829template <
typename Derived,
typename Type>
1835 return static_cast<const Derived&
>(*this);
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.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
CRTP Mixin providing functional programming operations.
Derived & self() noexcept
size_t find_index(Predicate pred) const
Find the index of the first element satisfying a predicate.
bool all(Operation &&operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool all(Operation &operation) const
Test if all elements satisfy a predicate.
const Type * min_by(Compare cmp) const
Find the minimum element using a custom comparator.
Type fold(const Type &init, Operation &&operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
DynList< Type > filter(Operation &&operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
auto mutable_for_each(Operation &operation) -> decltype(self())
Apply an operation to each element (mutable).
__Type fold_left(std::function< __Type(const __Type &, const Type &)> operation, const __Type &init) const
Left fold with operation first (alternative signature).
Container< Type > drop(const size_t n) const
Skip the first n elements.
Container< std::pair< size_t, Type > > enumerate() const
Enumerate elements with their indices.
Container< Container< Type > > chunk(size_t n) const
Split into chunks of fixed size.
auto mutable_for_each(Operation &&operation=Operation()) -> decltype(self())
This is an overloaded member function, provided for convenience. It differs from the above function o...
size_t count_if(Predicate pred) const
Count elements satisfying a predicate.
DynListType to_dynlist() const
Convert container to DynList.
DynList< Type > filter(Operation &operation) const
Filter elements by a predicate.
std::pair< DynList< Type >, DynList< Type > > partition(Operation &&op=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
DynList< std::tuple< Type, size_t > > pfilter(Operation &&operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Type * max() const
Find the maximum element.
bool forall(Operation &&operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
DynList< std::tuple< Type, size_t > > pfilter(Operation &operation) const
Filter with position information.
bool exists(Operation &&operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
auto for_each(Operation &&operation=Operation()) const -> decltype(self())
This is an overloaded member function, provided for convenience. It differs from the above function o...
Container< Type > rev() const
Create a reversed copy.
Container< __Type > maps(Operation &operation) const
Transform elements using a mapping function.
Container< Container< Type > > sliding(size_t size, size_t step=1) const
Create sliding windows of fixed size.
Type fold(const Type &init, Operation &operation) const
Simple fold with same type for accumulator and elements.
Container< Type > take(const size_t n) const
Take the first n elements.
std::string join_str(const std::string &sep=", ") const
Join string elements with separator.
Container< Type > unique() const
Remove consecutive duplicate elements.
const Type * first() const
Get the first element.
Container< std::pair< Type, typename Other::Item_Type > > zip_with(const Other &other) const
Zip with another container.
bool none(Predicate &pred) const
Check if no element satisfies a predicate.
Type last_or(const Type &default_val) const
Get the last element or a default value.
bool has_value(const Type &val) const
Check if container has a value.
StringType join(const StringType &sep=StringType{", "}) const
Join elements into a string with separator.
bool exists(Operation &operation) const
Test if any element satisfies a predicate.
size_t index_of(const Type &val) const
Find the index of a specific value.
__Type foldl(const __Type &init, std::function< __Type(const __Type &, const Type &)> operation) const
Left fold (reduce) with initial value.
auto for_each(Operation &operation) -> decltype(self())
This is an overloaded member function, provided for convenience. It differs from the above function o...
auto for_each(Operation &operation) const -> decltype(self())
Apply an operation to each element (read-only).
Type product(const Type &init) const
Compute the product of all elements.
std::tuple< DynList< Type >, DynList< Type > > tpartition(Operation &&op=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
size_t length() const noexcept
Count the number of elements.
Container< Type > unique_by(EqPred eq) const
Remove consecutive duplicates using a custom equality predicate.
Type sum(const Type &init=Type{}) const
Compute the sum of all elements.
const Type * max_by(Compare cmp) const
Find the maximum element using a custom comparator.
std::pair< DynList< Type >, DynList< Type > > partition(Operation &op) const
Partition elements by a predicate.
std::vector< Type > to_vector() const
Convert to std::vector.
bool none(Predicate &&pred) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Derived & self() const noexcept
Container< Type > intersperse(const Type &sep) const
Intersperse a separator between elements.
auto for_each(Operation &&operation=Operation()) -> decltype(self())
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::tuple< DynList< Type >, DynList< Type > > tpartition(Operation &op) const
Partition returning tuple instead of pair.
Container< __Type > maps(Operation &&operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Type first_or(const Type &default_val) const
Get the first element or a default value.
bool forall(Operation &operation) const
Alias for all().
const Type * last() const
Get the last element.
const Type * min() const
Find the minimum element.
CRTP Mixin for extracting keys from set-like containers.
Container< Type > items() const
Alias for keys().
const Derived & self() const noexcept
Container< Type > keys() const
Extract all keys as a list.
CRTP Mixin providing element location operations.
std::tuple< bool, Type > find_item(Operation &operation)
Find element with success flag.
Type * find_ptr(Operation &operation) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::tuple< bool, Type > find_item(Operation &&operation=Operation())
This is an overloaded member function, provided for convenience. It differs from the above function o...
Type * find_ptr(Operation &operation)
Find the first element satisfying a predicate.
std::tuple< bool, Type > find_item(Operation &&operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::tuple< bool, Type > find_item(Operation &operation) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Type & nth_ne(const size_t n) const noexcept
Access the n-th element (unchecked).
const Derived & self() const noexcept
Type * find_ptr(Operation and operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Type * find_ptr(Operation and operation=Operation())
This is an overloaded member function, provided for convenience. It differs from the above function o...
Type & nth(const size_t n) const
Access the n-th element (bounds-checked).
Derived & self() noexcept
CRTP Mixin providing traversal operations.
bool traverse(Operation &operation)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Derived & self() const noexcept
Access the derived class (const version).
bool traverse(Operation and operation=Operation())
This is an overloaded member function, provided for convenience. It differs from the above function o...
Derived & self() noexcept
Access the derived class (mutable version).
bool traverse(Operation and operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool traverse(Operation &operation) const
Traverse all elements, applying an operation to each.
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Freq_Node * pred
Predecessor node in level-order traversal.
Main namespace for Aleph-w library functions.
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
size_t size(Node *root) noexcept
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Default mapping operation (identity).
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.