Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::StlZipIterator< Containers > Class Template Reference

Lazy iterator that traverses multiple STL containers in lockstep. More...

#include <ah-stl-zip.H>

Classes

struct  end_tag
 Construct end iterator (all at end). More...
 

Public Types

using iterator_category = std::input_iterator_tag
 
using difference_type = std::ptrdiff_t
 
using IteratorTuple = std::tuple< std::pair< typename std::decay_t< Containers >::const_iterator, typename std::decay_t< Containers >::const_iterator >... >
 
using value_type = std::tuple< typename std::decay_t< Containers >::value_type... >
 
using reference = std::tuple< const typename std::decay_t< Containers >::value_type &... >
 
using pointer = void
 

Public Member Functions

constexpr StlZipIterator (const Containers &... cs)
 Construct iterator from containers.
 
constexpr StlZipIterator (const Containers &... cs, end_tag)
 
constexpr bool has_curr () const noexcept
 Check if iterator has current element.
 
constexpr bool completed () const noexcept
 Check if all iterators have completed.
 
constexpr auto get_curr () const
 Get current tuple of elements.
 
constexpr void next () noexcept
 Advance all iterators.
 
constexpr auto operator* () const
 Dereference operator for range-based for.
 
constexpr StlZipIteratoroperator++ () noexcept
 Pre-increment operator.
 
constexpr StlZipIterator operator++ (int) noexcept
 Post-increment operator.
 
constexpr bool operator== (const StlZipIterator &other) const noexcept
 Equality comparison.
 
constexpr bool operator!= (const StlZipIterator &other) const noexcept
 Inequality comparison.
 

Static Public Attributes

static constexpr size_t num_containers = sizeof...(Containers)
 Number of containers being zipped.
 

Private Member Functions

template<size_t... Is>
constexpr bool has_curr_impl (std::index_sequence< Is... >) const noexcept
 
template<size_t... Is>
constexpr auto deref_impl (std::index_sequence< Is... >) const
 
template<size_t... Is>
constexpr void advance_impl (std::index_sequence< Is... >) noexcept
 
template<size_t... Is>
constexpr bool completed_impl (std::index_sequence< Is... >) const noexcept
 

Private Attributes

IteratorTuple iters_
 

Detailed Description

template<typename... Containers>
class Aleph::StlZipIterator< Containers >

Lazy iterator that traverses multiple STL containers in lockstep.

This iterator allows synchronized iteration over multiple STL containers without allocating any additional memory. It produces tuples of references to elements at each position.

The iterator satisfies the InputIterator concept and can be used with range-based for loops and STL algorithms.

Template Parameters
ContainersParameter pack of container types.
Note
Iteration stops when ANY underlying iterator reaches its end.
See also
stl_zip() Factory function to create zip views
Author
Leandro Rabindranath León

Definition at line 141 of file ah-stl-zip.H.

Member Typedef Documentation

◆ difference_type

template<typename... Containers>
using Aleph::StlZipIterator< Containers >::difference_type = std::ptrdiff_t

Definition at line 146 of file ah-stl-zip.H.

◆ iterator_category

template<typename... Containers>
using Aleph::StlZipIterator< Containers >::iterator_category = std::input_iterator_tag

Definition at line 145 of file ah-stl-zip.H.

◆ IteratorTuple

template<typename... Containers>
using Aleph::StlZipIterator< Containers >::IteratorTuple = std::tuple< std::pair<typename std::decay_t<Containers>::const_iterator, typename std::decay_t<Containers>::const_iterator>...>

Definition at line 149 of file ah-stl-zip.H.

◆ pointer

template<typename... Containers>
using Aleph::StlZipIterator< Containers >::pointer = void

Definition at line 160 of file ah-stl-zip.H.

◆ reference

template<typename... Containers>
using Aleph::StlZipIterator< Containers >::reference = std::tuple< const typename std::decay_t<Containers>::value_type &...>

Definition at line 157 of file ah-stl-zip.H.

◆ value_type

template<typename... Containers>
using Aleph::StlZipIterator< Containers >::value_type = std::tuple< typename std::decay_t<Containers>::value_type...>

Definition at line 154 of file ah-stl-zip.H.

Constructor & Destructor Documentation

◆ StlZipIterator() [1/2]

template<typename... Containers>
constexpr Aleph::StlZipIterator< Containers >::StlZipIterator ( const Containers &...  cs)
inlineexplicitconstexpr

Construct iterator from containers.

Parameters
csReferences to containers to zip.

Definition at line 202 of file ah-stl-zip.H.

◆ StlZipIterator() [2/2]

template<typename... Containers>
constexpr Aleph::StlZipIterator< Containers >::StlZipIterator ( const Containers &...  cs,
end_tag   
)
inlineconstexpr

Definition at line 213 of file ah-stl-zip.H.

Member Function Documentation

◆ advance_impl()

template<typename... Containers>
template<size_t... Is>
constexpr void Aleph::StlZipIterator< Containers >::advance_impl ( std::index_sequence< Is... >  )
inlineconstexprprivatenoexcept

◆ completed()

template<typename... Containers>
constexpr bool Aleph::StlZipIterator< Containers >::completed ( ) const
inlineconstexprnoexcept

Check if all iterators have completed.

Useful to verify equal-length containers after iteration.

Returns
true if all underlying iterators are at their end.

Definition at line 231 of file ah-stl-zip.H.

References Aleph::StlZipIterator< Containers >::completed_impl().

◆ completed_impl()

template<typename... Containers>
template<size_t... Is>
constexpr bool Aleph::StlZipIterator< Containers >::completed_impl ( std::index_sequence< Is... >  ) const
inlineconstexprprivatenoexcept

◆ deref_impl()

template<typename... Containers>
template<size_t... Is>
constexpr auto Aleph::StlZipIterator< Containers >::deref_impl ( std::index_sequence< Is... >  ) const
inlineconstexprprivate

◆ get_curr()

template<typename... Containers>
constexpr auto Aleph::StlZipIterator< Containers >::get_curr ( ) const
inlineconstexpr

Get current tuple of elements.

Returns
Tuple of references to current elements.
Precondition
has_curr() must be true.

Definition at line 241 of file ah-stl-zip.H.

References Aleph::StlZipIterator< Containers >::deref_impl().

Referenced by Aleph::StlZipIterator< Containers >::operator*(), Aleph::stl_zip_find_last(), Aleph::stl_zip_last(), and Aleph::stl_zip_take_while().

◆ has_curr()

template<typename... Containers>
constexpr bool Aleph::StlZipIterator< Containers >::has_curr ( ) const
inlineconstexprnoexcept

Check if iterator has current element.

Returns
true if all underlying iterators are valid.

Definition at line 220 of file ah-stl-zip.H.

References Aleph::StlZipIterator< Containers >::has_curr_impl().

Referenced by Aleph::StlZipView< Containers >::empty(), Aleph::StlZipIterator< Containers >::operator==(), and Aleph::StlZipView< Containers >::size().

◆ has_curr_impl()

template<typename... Containers>
template<size_t... Is>
constexpr bool Aleph::StlZipIterator< Containers >::has_curr_impl ( std::index_sequence< Is... >  ) const
inlineconstexprprivatenoexcept

◆ next()

template<typename... Containers>
constexpr void Aleph::StlZipIterator< Containers >::next ( )
inlineconstexprnoexcept

Advance all iterators.

Precondition
has_curr() must be true.

Definition at line 250 of file ah-stl-zip.H.

References Aleph::StlZipIterator< Containers >::advance_impl().

Referenced by Aleph::StlZipIterator< Containers >::operator++(), and Aleph::StlZipIterator< Containers >::operator++().

◆ operator!=()

template<typename... Containers>
constexpr bool Aleph::StlZipIterator< Containers >::operator!= ( const StlZipIterator< Containers > &  other) const
inlineconstexprnoexcept

Inequality comparison.

Definition at line 297 of file ah-stl-zip.H.

References Aleph::maps().

◆ operator*()

template<typename... Containers>
constexpr auto Aleph::StlZipIterator< Containers >::operator* ( ) const
inlineconstexpr

Dereference operator for range-based for.

Returns
Tuple of current elements.

Definition at line 261 of file ah-stl-zip.H.

References Aleph::StlZipIterator< Containers >::get_curr().

◆ operator++() [1/2]

template<typename... Containers>
constexpr StlZipIterator & Aleph::StlZipIterator< Containers >::operator++ ( )
inlineconstexprnoexcept

Pre-increment operator.

Returns
Reference to this iterator after advancing.

Definition at line 270 of file ah-stl-zip.H.

References Aleph::StlZipIterator< Containers >::next().

◆ operator++() [2/2]

template<typename... Containers>
constexpr StlZipIterator Aleph::StlZipIterator< Containers >::operator++ ( int  )
inlineconstexprnoexcept

Post-increment operator.

Returns
Copy of iterator before advancing.

Definition at line 280 of file ah-stl-zip.H.

References Aleph::maps(), and Aleph::StlZipIterator< Containers >::next().

◆ operator==()

template<typename... Containers>
constexpr bool Aleph::StlZipIterator< Containers >::operator== ( const StlZipIterator< Containers > &  other) const
inlineconstexprnoexcept

Equality comparison.

Two iterators are equal if both have no current element.

Definition at line 291 of file ah-stl-zip.H.

References Aleph::StlZipIterator< Containers >::has_curr(), and Aleph::maps().

Member Data Documentation

◆ iters_

◆ num_containers

template<typename... Containers>
constexpr size_t Aleph::StlZipIterator< Containers >::num_containers = sizeof...(Containers)
staticconstexpr

Number of containers being zipped.

Definition at line 196 of file ah-stl-zip.H.


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