C++ zip
Public Types | Public Member Functions | List of all members
msd::zip_iterator< Iterators > Class Template Reference

Bidirectional iterator over multiple iterators simultaneously. More...

#include <zip.hpp>

Public Types

using iterator_category = std::bidirectional_iterator_tag
 Supports bidirectional traversal.
 
using difference_type = std::ptrdiff_t
 The difference between two iterators.
 
using value_type = std::tuple< typename std::iterator_traits< Iterators >::reference... >
 A tuple of references from each of the zipped iterators.
 
using pointer = std::tuple< typename std::iterator_traits< Iterators >::pointer... >
 A tuple of pointers from each of the zipped iterators.
 
using reference = std::tuple< typename std::iterator_traits< Iterators >::reference... >
 A tuple of references from each of the zipped iterators.
 

Public Member Functions

 zip_iterator (Iterators... iterators)
 Constructs a zip_iterator from the provided iterators. More...
 
value_type operator* () const
 Dereferences the zip_iterator to obtain a tuple of references from each iterator. More...
 
bool operator== (const zip_iterator &other) const
 Checks if two zip_iterator instances are equal. More...
 
bool operator!= (const zip_iterator &other) const
 Checks if two zip_iterator instances are not equal. More...
 
zip_iteratoroperator++ ()
 Advances the zip_iterator by one position. More...
 
zip_iterator operator+ (const std::size_t offset) const
 Returns a new zip_iterator advanced by a specified offset. More...
 
zip_iterator operator+ (const zip_iterator &other) const
 Returns a new zip_iterator advanced by the distance between two iterators. More...
 
zip_iteratoroperator-- ()
 Moves the zip_iterator back by one position. More...
 
zip_iterator operator- (const int offset) const
 Returns a new zip_iterator moved back by a specified offset. More...
 
zip_iterator operator- (const zip_iterator &other) const
 Returns the distance between two zip_iterator instances. More...
 

Detailed Description

template<typename... Iterators>
class msd::zip_iterator< Iterators >

Bidirectional iterator over multiple iterators simultaneously.

Template Parameters
IteratorsTypes of the iterators to be zipped. Each iterator should support bidirectional iteration (i.e., it should support ++, --, and dereferencing).

Constructor & Destructor Documentation

◆ zip_iterator()

template<typename... Iterators>
msd::zip_iterator< Iterators >::zip_iterator ( Iterators...  iterators)
inlineexplicit

Constructs a zip_iterator from the provided iterators.

Parameters
iteratorsThe iterators to be zipped together.

Member Function Documentation

◆ operator!=()

template<typename... Iterators>
bool msd::zip_iterator< Iterators >::operator!= ( const zip_iterator< Iterators > &  other) const
inline

Checks if two zip_iterator instances are not equal.

Parameters
otherThe other zip_iterator to compare with.
Returns
true if the iterators are not equal, false otherwise.

◆ operator*()

template<typename... Iterators>
value_type msd::zip_iterator< Iterators >::operator* ( ) const
inline

Dereferences the zip_iterator to obtain a tuple of references from each iterator.

Returns
A tuple containing the values pointed to by each iterator.

◆ operator+() [1/2]

template<typename... Iterators>
zip_iterator msd::zip_iterator< Iterators >::operator+ ( const std::size_t  offset) const
inline

Returns a new zip_iterator advanced by a specified offset.

Parameters
offsetThe number of positions to advance.
Returns
A new zip_iterator advanced by the specified offset.

◆ operator+() [2/2]

template<typename... Iterators>
zip_iterator msd::zip_iterator< Iterators >::operator+ ( const zip_iterator< Iterators > &  other) const
inline

Returns a new zip_iterator advanced by the distance between two iterators.

Parameters
otherThe zip_iterator to measure the distance to.
Returns
A new zip_iterator advanced by the distance to the specified iterator.

◆ operator++()

template<typename... Iterators>
zip_iterator& msd::zip_iterator< Iterators >::operator++ ( )
inline

Advances the zip_iterator by one position.

Returns
A reference to the updated zip_iterator.

◆ operator-() [1/2]

template<typename... Iterators>
zip_iterator msd::zip_iterator< Iterators >::operator- ( const int  offset) const
inline

Returns a new zip_iterator moved back by a specified offset.

Parameters
offsetThe number of positions to move back.
Returns
A new zip_iterator moved back by the specified offset.

◆ operator-() [2/2]

template<typename... Iterators>
zip_iterator msd::zip_iterator< Iterators >::operator- ( const zip_iterator< Iterators > &  other) const
inline

Returns the distance between two zip_iterator instances.

Parameters
otherThe zip_iterator to measure the distance from.
Returns
A new zip_iterator moved back by the distance to the specified iterator.

◆ operator--()

template<typename... Iterators>
zip_iterator& msd::zip_iterator< Iterators >::operator-- ( )
inline

Moves the zip_iterator back by one position.

Returns
A reference to the updated zip_iterator.

◆ operator==()

template<typename... Iterators>
bool msd::zip_iterator< Iterators >::operator== ( const zip_iterator< Iterators > &  other) const
inline

Checks if two zip_iterator instances are equal.

Parameters
otherThe other zip_iterator to compare with.
Returns
true if the iterators are equal, false otherwise.

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