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

CRTP Mixin providing element location operations. More...

#include <ah-dry-mixin.H>

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

Public Member Functions

Type & nth (const size_t n) const
 Access the n-th element (bounds-checked).
 
Type & nth_ne (const size_t n) const noexcept
 Access the n-th element (unchecked).
 
template<class Operation >
requires PredicateWith<Operation &, Type &>
Type * find_ptr (Operation &operation)
 Find the first element satisfying a predicate.
 
template<class Operation >
requires PredicateWith<Operation &, Type &>
Type * find_ptr (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 >
requires PredicateWith<Operation &, Type &>
Type * find_ptr (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 >
requires PredicateWith<Operation &, Type &>
Type * find_ptr (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.
 
template<class Operation >
requires PredicateWith<Operation &, Type &>
std::tuple< bool, Type > find_item (Operation &operation)
 Find element with success flag.
 
template<class Operation >
requires PredicateWith<Operation &, Type &>
std::tuple< bool, Type > find_item (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 >
requires PredicateWith<Operation &, Type &>
std::tuple< bool, Type > find_item (Operation &&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 >
requires PredicateWith<Operation &, Type &>
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 only in what argument(s) it accepts.
 

Protected Member Functions

const Derived & self () const noexcept
 
Derived & self () noexcept
 

Detailed Description

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

CRTP Mixin providing element location operations.

This mixin adds methods to find and locate elements within a container:

Template Parameters
DerivedThe derived container class (CRTP pattern).
TypeThe element type stored in the container.
Requirements
The derived class must provide traverse() method (typically via TraverseMixin).
Author
Leandro Rabindranath León

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

Member Function Documentation

◆ find_item() [1/4]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, Type &>
std::tuple< bool, Type > Aleph::LocateMixin< Derived, Type >::find_item ( Operation &&  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 428 of file ah-dry-mixin.H.

References Aleph::blossom_maximum_cardinality_matching(), and Aleph::LocateMixin< Derived, Type >::find_item().

◆ find_item() [2/4]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, Type &>
std::tuple< bool, Type > Aleph::LocateMixin< Derived, Type >::find_item ( Operation &&  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.

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

References Aleph::blossom_maximum_cardinality_matching(), and Aleph::LocateMixin< Derived, Type >::find_item().

◆ find_item() [3/4]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, Type &>
std::tuple< bool, Type > Aleph::LocateMixin< Derived, Type >::find_item ( Operation &  operation)
inline

Find element with success flag.

Like find_ptr() but returns a tuple containing:

  • bool: true if element was found
  • Type: copy of the found element (or default-constructed if not found)
Template Parameters
OperationCallable with signature bool(const Type&).
Parameters
operationPredicate to test each element.
Returns
Tuple of (found, element).
Example
DynList<std::string> list = {"apple", "banana", "cherry"};
auto [found, item] = list.find_item([](const auto& s) {
return s.starts_with("b");
});
if (found)
std::cout << item; // prints "banana"
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1155
std::tuple< bool, Type > find_item(Operation &operation) noexcept(operation_is_noexcept< Operation >())
Safe sequential searching of an item matching a criterion.
Definition ah-dry.H:499
Note
This returns a copy. Use find_ptr() to avoid copying.

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

References Aleph::blossom_maximum_cardinality_matching(), Aleph::LocateMixin< Derived, Type >::find_ptr(), and Aleph::Type.

Referenced by Aleph::LocateMixin< Derived, Type >::find_item(), Aleph::LocateMixin< Derived, Type >::find_item(), and TEST().

◆ find_item() [4/4]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, Type &>
std::tuple< bool, Type > Aleph::LocateMixin< Derived, Type >::find_item ( 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.

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

References Aleph::blossom_maximum_cardinality_matching(), Aleph::LocateMixin< Derived, Type >::find_ptr(), and Aleph::Type.

◆ find_ptr() [1/4]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, Type &>
Type * Aleph::LocateMixin< Derived, Type >::find_ptr ( Operation &  operation)
inline

Find the first element satisfying a predicate.

Searches for the first element where the operation returns true.

Template Parameters
OperationCallable with signature bool(Type&) or bool(const Type&).
Parameters
operationPredicate to test each element.
Returns
Pointer to the first matching element, or nullptr if not found.
Complexity
O(n) worst case.
Example
DynList<int> list = {1, 2, 3, 4, 5};
// Find first even number
int* p = list.find_ptr([](int x) { return x % 2 == 0; });
if (p) std::cout << *p; // prints 2
// Modify through pointer
*p = 20; // list = {1, 20, 3, 4, 5}
Type * find_ptr(Operation &operation) noexcept(operation_is_noexcept< Operation >())
Find a pointer to an item in the container according to a searching criterion.
Definition ah-dry.H:359
See also
find_item() for version returning success flag with copy.

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

References Aleph::blossom_maximum_cardinality_matching(), Aleph::LocateMixin< Derived, Type >::self(), and Aleph::Type.

Referenced by Aleph::LocateMixin< Derived, Type >::find_item(), Aleph::LocateMixin< Derived, Type >::find_item(), TEST(), and TEST().

◆ find_ptr() [2/4]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, Type &>
Type * Aleph::LocateMixin< Derived, Type >::find_ptr ( 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.

Const version.

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

References Aleph::blossom_maximum_cardinality_matching(), Aleph::LocateMixin< Derived, Type >::self(), and Aleph::Type.

◆ find_ptr() [3/4]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, Type &>
Type * Aleph::LocateMixin< Derived, Type >::find_ptr ( 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 379 of file ah-dry-mixin.H.

References Aleph::blossom_maximum_cardinality_matching().

◆ find_ptr() [4/4]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, Type &>
Type * Aleph::LocateMixin< Derived, Type >::find_ptr ( 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.

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

References Aleph::blossom_maximum_cardinality_matching().

◆ nth()

template<typename Derived , typename Type >
Type & Aleph::LocateMixin< Derived, Type >::nth ( const size_t  n) const
inline

Access the n-th element (bounds-checked).

Returns a reference to the element at position n (0-indexed).

Parameters
nZero-based index of the element.
Returns
Reference to the n-th element.
Exceptions
std::out_of_rangeif n >= size().
Complexity
O(n) - linear traversal to the n-th element.
Example
DynList<int> list = {10, 20, 30};
int x = list.nth(1); // x = 20
list.nth(1) = 25; // list = {10, 25, 30}
Type & nth(const size_t n)
Return the n-th item of the container.
Definition ah-dry.H:308
See also
nth_ne() for unchecked version.

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

References ah_out_of_range_error_if, Aleph::LocateMixin< Derived, Type >::self(), and Aleph::Type.

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

◆ nth_ne()

template<typename Derived , typename Type >
Type & Aleph::LocateMixin< Derived, Type >::nth_ne ( const size_t  n) const
inlinenoexcept

Access the n-th element (unchecked).

Returns a reference to the element at position n without bounds checking.

Parameters
nZero-based index of the element.
Returns
Reference to the n-th element.
Warning
Undefined behavior if n >= size().
Complexity
O(n) - linear traversal to the n-th element.
See also
nth() for bounds-checked version.

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

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

Referenced by TEST().

◆ self() [1/2]

◆ self() [2/2]

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

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

References Aleph::blossom_maximum_cardinality_matching().


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