Aleph-w 3.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 >
 Pair_Iterator (const C1 &c1, const 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
 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();
}
Dynamic singly linked list with functional programming support.
Definition htlist.H:1423
Pair_Iterator< typename C1::Iterator, typename C2::Iterator > get_pair_it(const C1 &c1, const C2 &c2)
Create a Pair_Iterator for two containers.
DynList< T > maps(const C &c, Op op)
Classic map operation.
See also
get_pair_it() for creating Pair_Iterator instances.

Definition at line 1474 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 1482 of file ahFunctional.H.

◆ Pair_Iterator() [2/2]

template<class Itor1 , class Itor2 = Itor1>
template<class C1 , class C2 >
Aleph::Pair_Iterator< Itor1, Itor2 >::Pair_Iterator ( const C1 c1,
const C2 c2 
)
inline

Construct from two containers.

Parameters
c1First container.
c2Second container.

Definition at line 1489 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 1507 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 1516 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 1495 of file ahFunctional.H.

◆ 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 1498 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 1501 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 1524 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.

Definition at line 1533 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 1543 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 1476 of file ahFunctional.H.

◆ it2

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

Definition at line 1477 of file ahFunctional.H.


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