92template <
typename tgtT,
typename srcT>
115template <
typename Derived,
typename Type>
120 [[nodiscard]]
const Derived &
self() const noexcept
122 return static_cast<const Derived &
>(*this);
126 [[nodiscard]] Derived &
self() noexcept
128 return static_cast<Derived &
>(*this);
166 template <
class Operation>
171 if (not operation(it.get_curr()))
177 template <
class Operation>
182 if (not operation(it.get_curr()))
189 template <
class Operation>
193 return traverse<Operation>(operation);
197 template <
class Operation>
201 return traverse<Operation>(operation);
225template <
typename Derived,
typename Type>
229 [[nodiscard]]
const Derived &
self() const noexcept
231 return static_cast<const Derived &
>(*this);
234 [[nodiscard]] Derived &
self() noexcept
236 return static_cast<Derived &
>(*this);
264 self().traverse([&ptr, &i, n](
Type &item)
281 const Type *ptr =
nullptr;
283 self().traverse([&ptr, &i, n](
const Type &item)
314 self().traverse([&ptr, &i, &n](
Type &item)
328 const Type *ptr =
nullptr;
330 self().traverse([&ptr, &i, &n](
const Type &item)
365 template <
class Operation>
370 self().traverse([&ptr, &operation](
Type &item)
384 template <
class Operation>
388 const Type *ptr =
nullptr;
389 self().traverse([&ptr, &operation](
const Type &item)
403 template <
class Operation>
407 return find_ptr<Operation>(operation);
411 template <
class Operation>
415 return find_ptr<Operation>(operation);
442 template <
class Operation>
447 return ptr ? std::make_tuple(
true, *ptr) : std::make_tuple(
false,
Type());
451 template <
class Operation>
453 std::tuple<bool, Type>
find_item(Operation &operation)
const
456 return ptr ? std::make_tuple(
true, *ptr) : std::make_tuple(
false,
Type());
460 template <
class Operation>
462 std::tuple<bool, Type>
find_item(Operation &&operation = Operation())
468 template <
class Operation>
470 std::tuple<bool, Type>
find_item(Operation &&operation = Operation())
const
502template <
typename Derived,
typename Type>
506 [[nodiscard]]
const Derived &
self() const noexcept
508 return static_cast<const Derived &
>(*this);
511 [[nodiscard]] Derived &
self() noexcept
513 return static_cast<Derived &
>(*this);
537 template <
class Operation>
541 self().traverse([&operation](
const Type &item)
550 template <
class Operation>
554 self().traverse([&operation](
const Type &item)
563 template <
class Operation>
565 auto for_each(Operation &&operation = Operation()) const -> decltype(
self())
567 return for_each<Operation>(operation);
571 template <
class Operation>
575 return for_each<Operation>(operation);
593 template <
class Operation>
597 self().traverse([&operation](
Type &item)
606 template <
class Operation>
610 return mutable_for_each<Operation>(operation);
635 template <
class Operation>
638 { c.template traverse<Operation>(op) } -> std::convertible_to<bool>;
640 [[nodiscard]]
bool all(Operation &operation)
const
642 return self().template traverse<Operation>(operation);
646 template <
class Operation>
649 { c.template traverse<Operation>(op) } -> std::convertible_to<bool>;
651 [[nodiscard]]
bool all(Operation &&operation = Operation())
const
653 return all<Operation>(operation);
659 template <
class Operation>
662 { c.template traverse<Operation>(op) } -> std::convertible_to<bool>;
664 [[nodiscard]]
bool forall(Operation &operation)
const
666 return all<Operation>(operation);
670 template <
class Operation>
673 { c.template traverse<Operation>(op) } -> std::convertible_to<bool>;
675 [[nodiscard]]
bool forall(Operation &&operation = Operation())
const
677 return all<Operation>(operation);
698 template <
class Operation>
700 [[nodiscard]]
bool exists(Operation &operation)
const
702 return not
self().traverse([&operation](
const Type &item)
704 return not operation(item);
709 template <
class Operation>
711 [[nodiscard]]
bool exists(Operation &&operation = Operation())
const
713 return exists<Operation>(operation);
755 requires std::invocable<Operation &, const Type &>
and
757 const Type &item) {
l.
append(std::invoke(op, item)); }
759 Operation &operation)
const
767 requires(
decltype(ret_val) &
l,
const Type &item) {
l.
append(item); })
768 for_each([&ret_val](
const Type &item) { ret_val.append(item); });
772 ret_val.append(std::invoke(operation, item));
780 requires std::invocable<Operation &, const Type &>
and
782 const Type &item) {
l.
append(std::invoke(op, item)); }
784 Operation &&operation = Operation())
const
786 return maps<R, Container, Operation>(operation);
818 template <
typename Acc = Type>
819 [[nodiscard]] Acc
foldl(
const Acc &
init, std::function<Acc(
const Acc &,
const Type &)> operation)
const
824 ret_val = operation(ret_val, item);
832 template <
typename Acc = Type>
833 [[nodiscard]] Acc
fold_left(std::function<Acc(
const Acc &,
const Type &)> operation,
834 const Acc &
init)
const
836 return foldl<Acc>(
init, operation);
848 template <
class Operation>
849 requires requires(
Type &acc, Operation &op,
const Type &item) { acc = op(acc, item); }
855 ret_val = operation(ret_val, item);
861 template <
class Operation>
862 requires requires(
Type &acc, Operation &op,
const Type &item) { acc = op(acc, item); }
865 return fold<Operation>(
init, operation);
887 template <
class Operation>
901 template <
class Operation>
905 return filter<Operation>(operation);
923 template <
class Operation>
932 ret_val.
append(std::make_tuple(item, i));
939 template <
class Operation>
943 return pfilter<Operation>(operation);
962 template <
class Operation>
970 ret_val.first.append(item);
972 ret_val.second.append(item);
978 template <
class Operation>
982 return partition<Operation>(op);
988 template <
class Operation>
1000 return std::make_tuple(r1, r2);
1004 template <
class Operation>
1008 return tpartition<Operation>(op);
1055 ret_val.insert(item);
1085 self().traverse([&i, &ret, n](
const Type &item)
1116 self().traverse([&i, &ret, n](
const Type &item)
1148 requires requires(
Type a,
Type b) {
1149 { a + b } -> std::convertible_to<Type>;
1155 result = result + item;
1178 requires requires(
Type a,
Type b) {
1179 { a * b } -> std::convertible_to<Type>;
1185 result = result * item;
1207 requires requires(
Type a,
Type b) {
1208 { a < b } -> std::convertible_to<bool>;
1211 const Type *result =
nullptr;
1214 if (result ==
nullptr or item < *result)
1237 requires requires(
Type a,
Type b) {
1238 { a < b } -> std::convertible_to<bool>;
1241 const Type *result =
nullptr;
1244 if (result ==
nullptr or *result < item)
1267 template <
class Compare>
1268 requires PredicateWith<Compare &, const Type &, const Type &>
1271 const Type *result =
nullptr;
1274 if (result ==
nullptr or
cmp(item, *result))
1297 template <
class Compare>
1301 const Type *result =
nullptr;
1304 if (result ==
nullptr or
cmp(*result, item))
1336 requires requires(
Type a,
Type b) {
1337 { a == b } -> std::convertible_to<bool>;
1363 template <
class Predicate>
1364 requires PredicateWith<Predicate &, const Type &>
1371 template <
class Predicate>
1375 return not
exists(std::forward<Predicate>(
pred));
1393 template <
class Predicate>
1425 const Type *result =
nullptr;
1426 self().traverse([&result](
const Type &item)
1451 return ptr ? *ptr : default_val;
1469 const Type *result =
nullptr;
1494 return ptr ? *ptr : default_val;
1524 ret.append(std::make_pair(idx++, item));
1546 template <
class Predicate>
1580 requires requires(
Type a,
Type b) {
1581 { a == b } -> std::convertible_to<bool>;
1613 requires requires(
Type a,
Type b) {
1614 { a == b } -> std::convertible_to<bool>;
1618 const Type *prev =
nullptr;
1621 if (prev ==
nullptr or not (*prev == item))
1649 requires PredicateWith<EqPred &, const Type &, const Type &>
1653 const Type *prev =
nullptr;
1656 if (prev ==
nullptr or not
eq(*prev, item))
1726 current.append(item);
1729 ret.append(std::move(current));
1736 ret.append(std::move(current));
1762 if (
size == 0 or step == 0)
1772 size_t total =
all.size();
1776 for (
size_t start = 0; start +
size <= total; start += step)
1780 all.traverse([&window, &idx, start,
size](
const Type &item)
1782 if (idx >= start
and idx < start +
size)
1783 window.append(item);
1785 return idx < start +
size;
1787 ret.append(std::move(window));
1812 std::vector<Type> ret;
1813 if constexpr (
requires {
self().size(); })
1814 ret.reserve(
self().size());
1817 ret.push_back(item);
1840 template <
typename DynListType = DynList<Type>>
1868 template <
typename StringType = std::
string>
1869 [[nodiscard]] StringType
join(
const StringType &sep = StringType{
", "})
const
1870 requires requires(
Type a) { std::to_string(a); }
1878 ret += std::to_string(item);
1898 [[nodiscard]] std::string
join_str(
const std::string &sep =
", ") const
1899 requires
std::is_convertible_v<
Type,
std::
string>
1907 ret +=
static_cast<std::string
>(item);
1939 using OtherType =
typename Other::Item_Type;
1942 auto it1 =
self().get_it();
1943 auto it2 = other.get_it();
1945 while (it1.has_curr()
and it2.has_curr())
1947 ret.append(std::make_pair(it1.get_curr(), it2.get_curr()));
1965template <
typename Derived,
typename Type>
1969 [[nodiscard]]
const Derived &
self() const noexcept
1971 return static_cast<const Derived &
>(*this);
1983 return self().template maps<Type, Container>([](
const Type &key) ->
const Type &
1995 return keys<Container>();
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
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.
STL-compatible iterator adapters for Aleph containers.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
CRTP Mixin providing functional programming operations.
Derived & self() noexcept
bool all(Operation &&operation=Operation()) const
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.
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.
and
Transform elements using a mapping function.
bool forall(Operation &&operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Container< Container< Type > > chunk(size_t n) const
Split into chunks of fixed size.
DynListType to_dynlist() const
Convert container to DynList.
std::pair< DynList< Type >, DynList< Type > > partition(Operation &op) const
Partition elements by a predicate.
std::tuple< DynList< Type >, DynList< Type > > tpartition(Operation &op) const
Partition returning tuple instead of pair.
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...
auto mutable_for_each(Operation &operation) -> decltype(self())
Apply an operation to each element (mutable).
bool none(Predicate &&pred) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Type * min_by(Compare cmp) const
Find the minimum element using a custom comparator.
auto for_each(Operation &&operation=Operation()) -> decltype(self())
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Type * max() const
Find the maximum element.
Container< concepts_detail::map_result_t< R, Operation &, Type > > maps(Operation &&operation=Operation()) const
Container< Type > unique_by(EqPred eq) const
Remove consecutive duplicates using a custom equality predicate.
Type fold(const Type &init, Operation &operation) const
Simple fold with same type for accumulator and elements.
bool none(Predicate &pred) const
Check if no element satisfies a predicate.
Container< Type > rev() const
Create a reversed copy.
Acc foldl(const Acc &init, std::function< Acc(const Acc &, const Type &)> operation) const
Left fold (reduce) with initial value.
bool exists(Operation &operation) const
Test if any element satisfies a predicate.
Container< Container< Type > > sliding(size_t size, size_t step=1) const
Create sliding windows of fixed size.
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.
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...
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...
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.
Type last_or(const Type &default_val) const
Get the last element or a default value.
Container< concepts_detail::map_result_t< R, Operation &, Type > > maps(Operation &operation) const
auto for_each(Operation &operation) const -> decltype(self())
Apply an operation to each element (read-only).
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.
size_t index_of(const Type &val) const
Find the index of a specific value.
DynList< std::tuple< Type, size_t > > pfilter(Operation &operation) const
Filter with position information.
Acc fold_left(std::function< Acc(const Acc &, const Type &)> operation, const Acc &init) const
Left fold with operation first (alternative signature).
bool exists(Operation &&operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Type product(const Type &init) const
Compute the product of all elements.
bool all(Operation &operation) const
Test if all elements satisfy a predicate.
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...
size_t length() const noexcept
Count the number of elements.
DynList< Type > filter(Operation &&operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Type sum(const Type &init=Type{}) const
Compute the sum of all elements.
size_t find_index(Predicate pred) const
Find the index of the first element satisfying a predicate.
std::vector< Type > to_vector() const
Convert to std::vector.
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...
const Type * max_by(Compare cmp) const
Find the maximum element using a custom comparator.
const Derived & self() const noexcept
Container< Type > intersperse(const Type &sep) const
Intersperse a separator between elements.
bool forall(Operation &operation) const
Alias for all().
Type first_or(const Type &default_val) const
Get the first element or a default value.
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...
auto for_each(Operation &operation) -> decltype(self())
This is an overloaded member function, provided for convenience. It differs from the above function o...
DynList< Type > filter(Operation &operation) const
Filter elements by a predicate.
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) 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)
Find element with success flag.
const Type * find_ptr(Operation and operation=Operation()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Type & nth_ne(const size_t n) const noexcept
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 and operation=Operation())
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()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Type * find_ptr(Operation &operation) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Derived & self() const noexcept
const Type & nth(const size_t n) const
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.
Type & nth(const size_t n)
Access the n-th element (bounds-checked).
Type & nth_ne(const size_t n) noexcept
Access the n-th element (unchecked).
Derived & self() noexcept
CRTP Mixin providing traversal operations.
bool traverse(Operation &operation) const
Traverse all elements, applying an operation to each.
bool traverse(Operation and operation=Operation()) const
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...
bool traverse(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).
f(args...) is a valid call expression, exactly as written.
f(args...) is a valid call whose result is usable as a condition.
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
See compute_cardinality_rec(Node * root).
and
Check uniqueness with explicit hash + equality functors.
auto iterator_for(C &c)
Iterator on c positioned on its first item: the container's own iterator on a modifiable container.
static std::atomic< bool > init
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Default mapping operation: the conversion of the item, which is its copy when the two types are the s...