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

Typenth (const size_t n) const
 Access the n-th element (bounds-checked).
 
Typenth_ne (const size_t n) const noexcept
 Access the n-th element (unchecked).
 
template<class Operation >
Typefind_ptr (Operation &operation)
 Find the first element satisfying a predicate.
 
template<class Operation >
Typefind_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 >
Typefind_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 >
Typefind_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 >
std::tuple< bool, Typefind_item (Operation &operation)
 Find element with success flag.
 
template<class Operation >
std::tuple< bool, Typefind_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 >
std::tuple< bool, Typefind_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 >
std::tuple< bool, Typefind_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 Derivedself () const noexcept
 
Derivedself () 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 222 of file ah-dry-mixin.H.

Member Function Documentation

◆ find_item() [1/4]

template<typename Derived , typename Type >
template<class Operation >
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 416 of file ah-dry-mixin.H.

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

◆ find_item() [2/4]

template<typename Derived , typename Type >
template<class Operation >
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 423 of file ah-dry-mixin.H.

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

◆ find_item() [3/4]

template<typename Derived , typename Type >
template<class Operation >
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"
Dynamic singly linked list with functional programming support.
Definition htlist.H:1423
std::tuple< bool, Type > find_item(Operation &operation) noexcept(operation_is_noexcept< Operation >())
Safe sequential searching of an item matching a criteria.
Definition ah-dry.H:440
DynList< T > maps(const C &c, Op op)
Classic map operation.
Note
This returns a copy. Use find_ptr() to avoid copying.

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

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

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 >
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 408 of file ah-dry-mixin.H.

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

◆ find_ptr() [1/4]

template<typename Derived , typename Type >
template<class Operation >
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 criteria.
Definition ah-dry.H:318
See also
find_item() for version returning success flag with copy.

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

References Aleph::maps(), Aleph::LocateMixin< Derived, Type >::self(), and GenericTraverse< Container >::traverse().

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 >
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 345 of file ah-dry-mixin.H.

References Aleph::maps(), Aleph::LocateMixin< Derived, Type >::self(), and GenericTraverse< Container >::traverse().

◆ find_ptr() [3/4]

template<typename Derived , typename Type >
template<class Operation >
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 370 of file ah-dry-mixin.H.

References Aleph::maps().

◆ find_ptr() [4/4]

template<typename Derived , typename Type >
template<class Operation >
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 363 of file ah-dry-mixin.H.

References Aleph::maps().

◆ 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 container.
Definition ah-dry.H:267
See also
nth_ne() for unchecked version.

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

References ah_out_of_range_error_if, Aleph::maps(), Aleph::LocateMixin< Derived, Type >::self(), and GenericTraverse< Container >::traverse().

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 287 of file ah-dry-mixin.H.

References Aleph::maps(), Aleph::LocateMixin< Derived, Type >::self(), and GenericTraverse< Container >::traverse().

Referenced by TEST().

◆ self() [1/2]

◆ self() [2/2]

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

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

References Aleph::maps().


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