Aleph-w 7.10.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)
 Access the n-th element (bounds-checked).
 
const Type & nth (const size_t n) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const.
 
Type & nth_ne (const size_t n) noexcept
 Access the n-th element (unchecked).
 
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 only in what argument(s) it accepts. A reference to const.
 
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 &, const Type &>
const 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 &, const Type &>
const 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 226 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 462 of file ah-dry-mixin.H.

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

References 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:1231
and std::default_initializable< T > and std::copy_constructible< T > std::tuple< bool, Type > find_item(Operation &operation) const noexcept(find_item_is_noexcept< Operation >())
Safe sequential searching of an item matching a criterion.
Definition ah-dry.H:983
Note
This returns a copy. Use find_ptr() to avoid copying.

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

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

References 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}
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, Type > Type * find_ptr(Operation &operation) noexcept(mutable_search_is_noexcept< Operation >())
Find a pointer to an item in the container according to a searching criterion.
Definition ah-dry.H:825
See also
find_item() for version returning success flag with copy.

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

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

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

◆ find_ptr() [2/4]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, const Type &>
const 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 386 of file ah-dry-mixin.H.

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

◆ find_ptr() [4/4]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, const Type &>
const 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 405 of file ah-dry-mixin.H.

◆ nth() [1/2]

template<typename Derived , typename Type >
Type & Aleph::LocateMixin< Derived, Type >::nth ( const size_t  n)
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:774
See also
nth_ne() for unchecked version.

Definition at line 260 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(), TEST(), and TEST().

◆ nth() [2/2]

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

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

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

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

◆ nth_ne() [1/2]

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

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

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

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

◆ nth_ne() [2/2]

template<typename Derived , typename Type >
Type & Aleph::LocateMixin< Derived, Type >::nth_ne ( const size_t  n)
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 310 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 234 of file ah-dry-mixin.H.


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