|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Container traversal and functional operation mixins. More...
#include "ahFunctional.H"#include <ah-concepts.H>#include <concepts>#include <functional>#include <limits>#include <optional>#include <tuple>#include <type_traits>#include <utility>#include <vector>#include <ah-errors.H>#include <ah-iterator.H>Go to the source code of this file.
Classes | |
| struct | Aleph::dry_detail::Modifying_Probe< T > |
| Operation that needs to modify the item it receives. More... | |
| struct | Aleph::dry_detail::Reading_Probe< T > |
| Operation that only reads the item and never throws. More... | |
| struct | Aleph::dry_detail::inner_item< C > |
Item type of a container returned by the operation of flat_map(): its Item_Type, or else its value_type. More... | |
| struct | Aleph::dry_detail::inner_item< C > |
Item type of an Aleph container returned by the operation of flat_map(). More... | |
| struct | GenericTraverse< Container > |
| Generic traversal of the container through its iterator. More... | |
| class | LocateFunctions< Container, Type > |
| Common sequential searching methods on containers. More... | |
| struct | SpecialCtors< Container, T > |
Special constructors common to Aleph-w ( \(\aleph_\omega\)) containers. More... | |
| class | FunctionalMethods< Container, T > |
Common methods to the Aleph-w ( \(\aleph_\omega\)) containers. More... | |
| struct | GenericItems< Container, T > |
| Generic list of items stored in a container. More... | |
| class | EqualSequenceMethod< Container > |
| Mixin providing equality comparison for sequence containers. More... | |
| class | EqualToMethod< Container > |
| Equality test for sets. More... | |
| class | EqualSortedMethod< Container > |
| Equality test for containers sorted by a comparator. More... | |
| class | MapSequencesMethods< Container, Key, Data > |
| Common methods to mapping containers. More... | |
Namespaces | |
| namespace | Aleph |
| Main namespace for Aleph-w library functions. | |
| namespace | Aleph::dry_detail |
Concepts | |
| concept | Aleph::dry_detail::MutablyTraversable |
The modifiable traversal of Container hands out T &. | |
| concept | Aleph::dry_detail::SetSearchable |
Container can be compared as a set: it has size(), a Key_Type and a search() that returns a pointer. | |
| concept | Aleph::dry_detail::FoldOperation |
op folds an accumulator Acc with an item T. | |
| concept | Aleph::dry_detail::FoldRightOperation |
op folds an item T with an accumulator Acc from the right. | |
Macros | |
| #define | Derived_Build(Name) |
Declare build() in a class derived from a container. | |
Typedefs | |
| template<class Container , typename T > | |
| using | GenericKeys = GenericItems< Container, T > |
| Alias to GenricItems functor. | |
Functions | |
| template<class It > | |
| void | Aleph::dry_detail::advance (It &it) noexcept(advance_is_noexcept< It >) |
| Advance an iterator that is positioned on an item. | |
| template<class It > | |
| decltype(auto) | Aleph::dry_detail::current (It &it) noexcept(current_is_noexcept< It >) |
| Current item of an iterator that is positioned on one. | |
| template<class Acc , class Step > | |
| void | Aleph::dry_detail::assign_fold (Acc &acc, Step &&step) |
Store in acc the result of a folding step step(). | |
| template<class Acc , class Op , class T > | |
| void | Aleph::dry_detail::fold_left_step (Acc &acc, Op &op, const T &item) |
One step of a left fold: acc = op(acc, item). | |
| template<class Acc , class Op , class T > | |
| void | Aleph::dry_detail::fold_right_step (Acc &acc, Op &op, const T &item) |
One step of a right fold: acc = op(item, acc). | |
| template<class Container , class Operation > | |
| bool | traverse (const Container &c, Operation &op) noexcept(noexcept(c.traverse(op))) |
Invoke c.traverse(op) as a free function (lvalue operation). | |
| template<class Container , class Operation > | |
| bool | traverse (const Container &c, Operation &&op) noexcept(noexcept(c.traverse(op))) |
Invoke c.traverse(op) as a free function (rvalue overload). | |
Variables | |
| template<class Container , class T > | |
| constexpr bool | Aleph::dry_detail::const_traversal_is_noexcept |
The constant traversal of Container cannot throw by itself. | |
| template<class Container , class T > | |
| constexpr bool | Aleph::dry_detail::mutable_traversal_is_noexcept |
The modifiable traversal of Container cannot throw by itself. | |
| template<class It > | |
| constexpr bool | Aleph::dry_detail::advance_is_noexcept |
| Advancing an iterator positioned on an item cannot throw. | |
| template<class It > | |
| constexpr bool | Aleph::dry_detail::current_is_noexcept |
| Reading the current item of an iterator positioned on one cannot throw. | |
Container traversal and functional operation mixins.
This file provides generic traversal classes and mixins that implement functional operations (for_each, exists, all, filter, map, etc.) for containers through their iterators. These follow the DRY principle.
A query never modifies the container: every member that only reads traverses the container through its constant traverse(), which hands out each item as const T &. Only the members meant to modify, such as mutable_for_each() or the non-constant find_ptr() and nth(), use the modifiable traversal, and they exist only for containers whose modifiable traverse() hands out T &.
The operations are called through std::invoke, so a pointer to member works as a projection: c.filter(&Item::is_valid), c.maps(&Point::get_x).
Every member builds its whole result, usually a DynList. A chain such as c.filter(p).maps(f).take(3) therefore visits every item and builds two intermediate lists. For a lazy pipeline that touches only what it needs, use the C++20 views, which work with the Aleph containers that provide begin()/end() (see ah-ranges.H, which requires GCC 12 or later):
Definition in file ah-dry.H.
| #define Derived_Build | ( | Name | ) |
Declare build() in a class derived from a container.
A class derived from a container inherits FunctionalMethods::build(), which builds the base class. Placed in the public part of class Name, Derived_Build(Name) declares a build() that builds a Name instead, with the items appended as the base container appends them (see FunctionalMethods::build_as()).
| Name | the derived class; inside a class template, its injected name (DynSetAvlTree, not DynSetAvlTree<Key, Compare>). |
| using GenericKeys = GenericItems<Container, T> |
|
noexcept |
Invoke c.traverse(op) as a free function (rvalue overload).
Overload for temporary / rvalue callables such as lambda expressions. The operation op is passed (invoked) as a named lvalue to the member overload rather than being perfectly forwarded.
| Container | Any type that provides a traverse(Operation&) member. |
| Operation | Callable with signature bool(const Item_Type &). |
| [in] | c | Container to traverse. |
| [in] | op | Operation passed (invoked) as a named lvalue to the member overload rather than being perfectly forwarded. |
true if all elements were visited, false if traversal was stopped. | anything | that op throws. |
|
noexcept |
Invoke c.traverse(op) as a free function (lvalue operation).
Convenience wrapper so that traverse(container, op) can be used in generic code without depending on the container type. The container is constant, so op receives each item as a constant reference.
| Container | Any type that provides a traverse(Operation&) member. |
| Operation | Callable with signature bool(const Item_Type &). |
| [in] | c | Container to traverse. |
| [in] | op | Operation to apply to each element; return false to stop. |
true if all elements were visited, false if traversal was stopped. | anything | that op throws. |