Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Pair_Iterator< Itor1, Itor2 > Class Template Reference

Iterator that zips two other iterators. More...

#include <ahFunctional.H>

Public Member Functions

 Pair_Iterator (Itor1 i1, Itor2 i2)
 Construct from two iterators.
 
template<class C1 , class C2 >
requires (not std::same_as<std::remove_cvref_t<C1>, Itor1>)
 Pair_Iterator (C1 &c1, C2 &c2)
 Construct from two containers.
 
bool has_curr () const noexcept
 Check if both iterators have current elements.
 
bool has_curr1 () const noexcept
 Check if first iterator has current element.
 
bool has_curr2 () const noexcept
 Check if second iterator has current element.
 
auto get_curr () const
 Get current pair (bounds-checked).
 
auto get_curr_ne () const noexcept
 Get current pair (no bounds check).
 
void next ()
 Advance both iterators (bounds-checked).
 
void next_ne () noexcept(noexcept(std::declval< Itor1 & >().next_ne()) and noexcept(std::declval< Itor2 & >().next_ne()))
 Advance both iterators (no bounds check).
 
bool was_traversed () const noexcept
 Check if both iterators were completely traversed.
 

Private Attributes

Itor1 it1
 
Itor2 it2
 

Detailed Description

template<class Itor1, class Itor2 = Itor1>
class Aleph::Pair_Iterator< Itor1, Itor2 >

Iterator that zips two other iterators.

Synchronizes two iterators so they advance together. Produces pairs of elements from both iterators. Useful for iterating over two containers in lockstep.

Template Parameters
Itor1Type of first iterator.
Itor2Type of second iterator (defaults to Itor1).
Example:
DynList<int> nums = {1, 2, 3};
DynList<std::string> names = {"one", "two", "three"};
auto it = get_pair_it(nums, names);
while (it.has_curr()) {
auto [num, name] = it.get_curr_ne();
std::cout << num << " = " << name << '\n';
it.next_ne();
}
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
auto get_pair_it(C1 &c1, C2 &c2)
Create a Pair_Iterator for two containers.
See also
get_pair_it() for creating Pair_Iterator instances.

Definition at line 1736 of file ahFunctional.H.

Constructor & Destructor Documentation

◆ Pair_Iterator() [1/2]

template<class Itor1 , class Itor2 = Itor1>
Aleph::Pair_Iterator< Itor1, Itor2 >::Pair_Iterator ( Itor1  i1,
Itor2  i2 
)
inline

Construct from two iterators.

Definition at line 1743 of file ahFunctional.H.

◆ Pair_Iterator() [2/2]

template<class Itor1 , class Itor2 = Itor1>
template<class C1 , class C2 >
requires (not std::same_as<std::remove_cvref_t<C1>, Itor1>)
Aleph::Pair_Iterator< Itor1, Itor2 >::Pair_Iterator ( C1 &  c1,
C2 &  c2 
)
inline

Construct from two containers.

Parameters
c1First container.
c2Second container.

Definition at line 1751 of file ahFunctional.H.

Member Function Documentation

◆ get_curr()

template<class Itor1 , class Itor2 = Itor1>
auto Aleph::Pair_Iterator< Itor1, Itor2 >::get_curr ( ) const
inline

Get current pair (bounds-checked).

Returns
Pair of current elements.
Exceptions
std::overflow_errorif either iterator is exhausted.

Definition at line 1778 of file ahFunctional.H.

Referenced by TEST_F().

◆ get_curr_ne()

template<class Itor1 , class Itor2 = Itor1>
auto Aleph::Pair_Iterator< Itor1, Itor2 >::get_curr_ne ( ) const
inlinenoexcept

Get current pair (no bounds check).

Returns
Pair of current elements.
Note
Requires has_curr() to be true.

Definition at line 1787 of file ahFunctional.H.

◆ has_curr()

template<class Itor1 , class Itor2 = Itor1>
bool Aleph::Pair_Iterator< Itor1, Itor2 >::has_curr ( ) const
inlinenoexcept

Check if both iterators have current elements.

Returns
true if both iterators are valid.

Definition at line 1757 of file ahFunctional.H.

Referenced by main().

◆ has_curr1()

template<class Itor1 , class Itor2 = Itor1>
bool Aleph::Pair_Iterator< Itor1, Itor2 >::has_curr1 ( ) const
inlinenoexcept

Check if first iterator has current element.

Definition at line 1763 of file ahFunctional.H.

◆ has_curr2()

template<class Itor1 , class Itor2 = Itor1>
bool Aleph::Pair_Iterator< Itor1, Itor2 >::has_curr2 ( ) const
inlinenoexcept

Check if second iterator has current element.

Definition at line 1769 of file ahFunctional.H.

◆ next()

template<class Itor1 , class Itor2 = Itor1>
void Aleph::Pair_Iterator< Itor1, Itor2 >::next ( )
inline

Advance both iterators (bounds-checked).

Exceptions
std::overflow_errorif either iterator is exhausted.

Definition at line 1795 of file ahFunctional.H.

◆ next_ne()

template<class Itor1 , class Itor2 = Itor1>
void Aleph::Pair_Iterator< Itor1, Itor2 >::next_ne ( )
inlinenoexcept

Advance both iterators (no bounds check).

Note
Requires has_curr() to be true.
Exceptions
whatnext_ne() of the two iterators throws; nothing with most of them. The inorder iterator of a binary tree (Aleph::BinNodeInfixIterator) throws std::bad_alloc if the tree is deeper than its inline capacity and the pending nodes cannot be moved to the heap.

Definition at line 1809 of file ahFunctional.H.

◆ was_traversed()

template<class Itor1 , class Itor2 = Itor1>
bool Aleph::Pair_Iterator< Itor1, Itor2 >::was_traversed ( ) const
inlinenoexcept

Check if both iterators were completely traversed.

Returns
true if both iterators are exhausted.
Note
Useful for verifying equal container lengths.

Definition at line 1820 of file ahFunctional.H.

Member Data Documentation

◆ it1

template<class Itor1 , class Itor2 = Itor1>
Itor1 Aleph::Pair_Iterator< Itor1, Itor2 >::it1
private

Definition at line 1738 of file ahFunctional.H.

◆ it2

template<class Itor1 , class Itor2 = Itor1>
Itor2 Aleph::Pair_Iterator< Itor1, Itor2 >::it2
private

Definition at line 1739 of file ahFunctional.H.


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