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:1155
Pair_Iterator< typename C1::Iterator, typename C2::Iterator > get_pair_it(const C1 &c1, const C2 &c2)
Create a Pair_Iterator for two containers.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
See also
get_pair_it() for creating Pair_Iterator instances.

Definition at line 1665 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 1673 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 1680 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 1698 of file ahFunctional.H.

Referenced by Aleph::clone_tree(), and 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 1707 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 1686 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 1689 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 1692 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 1715 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 1724 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 1734 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 1667 of file ahFunctional.H.

◆ it2

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

Definition at line 1668 of file ahFunctional.H.


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