Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::TraverseMixin< Derived, Type > Class Template Reference

CRTP Mixin providing traversal operations. More...

#include <ah-dry-mixin.H>

Inheritance diagram for Aleph::TraverseMixin< Derived, Type >:
[legend]

Public Member Functions

template<class Operation >
bool traverse (Operation &operation) const
 Traverse all elements, applying an operation to each.
 
template<class Operation >
bool traverse (Operation &operation)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
bool traverse (Operation and operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
bool traverse (Operation and operation=Operation())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 

Protected Member Functions

const Derivedself () const noexcept
 Access the derived class (const version).
 
Derivedself () noexcept
 Access the derived class (mutable version).
 

Detailed Description

template<typename Derived, typename Type>
class Aleph::TraverseMixin< Derived, Type >

CRTP Mixin providing traversal operations.

This mixin adds the traverse() method to containers, which is the foundation for all other functional operations.

Template Parameters
DerivedThe derived container class (CRTP pattern).
TypeThe element type stored in the container.
Requirements
The derived class must provide:
  • Iterator nested type
  • get_it() method returning an Iterator
Author
Leandro Rabindranath León

Definition at line 115 of file ah-dry-mixin.H.

Member Function Documentation

◆ self() [1/2]

template<typename Derived , typename Type >
const Derived & Aleph::TraverseMixin< Derived, Type >::self ( ) const
inlineprotectednoexcept

Access the derived class (const version).

Definition at line 119 of file ah-dry-mixin.H.

References Aleph::maps().

Referenced by Aleph::TraverseMixin< Derived, Type >::traverse(), and Aleph::TraverseMixin< Derived, Type >::traverse().

◆ self() [2/2]

template<typename Derived , typename Type >
Derived & Aleph::TraverseMixin< Derived, Type >::self ( )
inlineprotectednoexcept

Access the derived class (mutable version).

Definition at line 125 of file ah-dry-mixin.H.

References Aleph::maps().

◆ traverse() [1/4]

template<typename Derived , typename Type >
template<class Operation >
bool Aleph::TraverseMixin< Derived, Type >::traverse ( Operation operation)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 176 of file ah-dry-mixin.H.

References Aleph::maps(), and Aleph::TraverseMixin< Derived, Type >::self().

◆ traverse() [2/4]

template<typename Derived , typename Type >
template<class Operation >
bool Aleph::TraverseMixin< Derived, Type >::traverse ( Operation operation) const
inline

Traverse all elements, applying an operation to each.

Iterates through all elements in the container, calling the operation on each element. The traversal stops early if the operation returns false.

Template Parameters
OperationCallable type with signature bool(const Type&) or bool(Type&).
Parameters
operationThe operation to apply to each element.
Returns
true if all elements were visited (operation always returned true), false if traversal was stopped early.
Complexity
O(n) where n is the number of elements.
Example
DynList<int> list = {1, 2, 3, 4, 5};
// Print all elements
list.traverse([](const int& x) {
std::cout << x << " ";
return true; // continue
});
// Find first even number (stops early)
int found = 0;
list.traverse([&found](const int& x) {
if (x % 2 == 0) {
found = x;
return false; // stop
}
return true;
});
Dynamic singly linked list with functional programming support.
Definition htlist.H:1423
DynList< T > maps(const C &c, Op op)
Classic map operation.
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.
Definition ah-dry.H:95

Definition at line 166 of file ah-dry-mixin.H.

References Aleph::maps(), and Aleph::TraverseMixin< Derived, Type >::self().

Referenced by TEST(), TEST(), and TEST().

◆ traverse() [3/4]

template<typename Derived , typename Type >
template<class Operation >
bool Aleph::TraverseMixin< Derived, Type >::traverse ( Operation and  operation = Operation())
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 194 of file ah-dry-mixin.H.

References Aleph::maps().

◆ traverse() [4/4]

template<typename Derived , typename Type >
template<class Operation >
bool Aleph::TraverseMixin< Derived, Type >::traverse ( Operation and  operation = Operation()) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Version accepting rvalue operation (temporary lambdas).

Definition at line 187 of file ah-dry-mixin.H.

References Aleph::maps().


The documentation for this class was generated from the following file: