Utopia  2
Framework for studying models of complex & adaptive systems.
Public Types | Public Member Functions | Private Types | Private Attributes | Friends | List of all members
Utopia::Itertools::ZipIterator< Iters > Class Template Reference

Iterator over an arbitrary number of collections. More...

#include <zip.hh>

Public Types

using value_type = std::tuple< typename std::iterator_traits< Iters >::value_type... >
 
using difference_type = int
 
using pointer = PtrTuple
 
using reference = RefTuple
 
using iterator_category = std::common_type_t< typename std::iterator_traits< Iters >::iterator_category... >
 

Public Member Functions

ZipIteratoroperator++ ()
 Increment by prefix. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::bidirectional_iterator_tag, category >, int > = 0>
ZipIteratoroperator-- ()
 Decrement by prefix. More...
 
ZipIterator operator++ (int)
 Increment by postfix. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::bidirectional_iterator_tag, category >, int > = 0>
ZipIterator operator-- (int)
 Decrement by postfix. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
ZipIterator operator+ (const difference_type n) const
 Increment by a number of steps. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
ZipIterator operator- (const difference_type n) const
 Decrement by a number of steps. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
difference_type operator- (const ZipIterator &other) const
 Compute the difference between two iterators. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
ZipIteratoroperator+= (const difference_type n)
 Increment in-place by a number of steps. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
ZipIteratoroperator-= (const difference_type n)
 Decrement in-place by a number of steps. More...
 
const reference operator* () const
 Dereference this iterator at its current position. More...
 
reference operator* ()
 Dereference this iterator at its current position. More...
 
const pointer operator-> () const
 Indirect this pointer at its current position. More...
 
pointer operator-> ()
 Indirect this pointer at its current position. More...
 
 ZipIterator ()=default
 Default-construct a zip iterator. Dereferencing it is undefined. More...
 
 ZipIterator (const ZipIterator &other)=default
 Copy-construct a zip iterator. More...
 
 ZipIterator (ZipIterator &&other)=default
 Move-construct a zip iterator. More...
 
ZipIteratoroperator= (ZipIterator &&other)=default
 Move-assign a zip iterator. More...
 
ZipIteratoroperator= (const ZipIterator &other)=default
 Copy-assign a zip iterator. More...
 
 ZipIterator (Iters... iters)
 Construct from a pack of iterators. More...
 
template<typename... Iterators>
 ZipIterator (std::tuple< Iterators... > iters)
 Construct from a tuple of iterators. More...
 
template<typename... It>
bool operator== (const ZipIterator< It... > &other) const
 Compare this object with another zip iterator. More...
 
template<typename... It>
bool operator!= (const ZipIterator< It... > &other) const
 Compare this object with another zip iterator. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
bool operator< (const ZipIterator &other) const
 Less-than compare this object with another zip iterator. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
bool operator<= (const ZipIterator &other) const
 Less-than or equal compare this object with another zip iterator. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
bool operator> (const ZipIterator &other) const
 Greater-than compare this object with another zip iterator. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
bool operator>= (const ZipIterator &other) const
 Greater-than or equal compare this object with another zip iterator. More...
 
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
reference operator[] (const difference_type n) const
 offset dereference operator for purely random accesss iterators held by ZipIterator More...
 
 ~ZipIterator ()=default
 Destroy this object. More...
 

Private Types

using Tuple = std::tuple< Iters... >
 
using RefTuple = std::tuple< decltype(*std::declval< Iters >())... >
 
using PtrTuple = std::tuple< typename std::iterator_traits< Iters >::pointer... >
 
using This = ZipIterator< Iters... >
 

Private Attributes

Tuple _iterators
 

Friends

std::ostream & operator<< (std::ostream &ostr, const ZipIterator &right)
 Write the contents of this iterator into an outstream. More...
 

Detailed Description

template<typename... Iters>
class Utopia::Itertools::ZipIterator< Iters >

Iterator over an arbitrary number of collections.

This object stores an iterator for each collection it iterates over and obeys the lowest-level iterator category of all inserted iterators.

Most operations on this iterator are forwarded to the underlying iterators. Dereferencing packs the resulting references to values of the collections into an std::tuple and returns it.

Note
This iterator is invalidated as soon as any of the underlying iterators is invalidated.
Template Parameters
ItersThe types of iterators used within this object.

Member Typedef Documentation

◆ difference_type

template<typename... Iters>
using Utopia::Itertools::ZipIterator< Iters >::difference_type = int

◆ iterator_category

template<typename... Iters>
using Utopia::Itertools::ZipIterator< Iters >::iterator_category = std::common_type_t<typename std::iterator_traits<Iters>::iterator_category...>

◆ pointer

template<typename... Iters>
using Utopia::Itertools::ZipIterator< Iters >::pointer = PtrTuple

◆ PtrTuple

template<typename... Iters>
using Utopia::Itertools::ZipIterator< Iters >::PtrTuple = std::tuple<typename std::iterator_traits<Iters>::pointer...>
private

◆ reference

template<typename... Iters>
using Utopia::Itertools::ZipIterator< Iters >::reference = RefTuple

◆ RefTuple

template<typename... Iters>
using Utopia::Itertools::ZipIterator< Iters >::RefTuple = std::tuple<decltype(*std::declval<Iters>())...>
private

◆ This

template<typename... Iters>
using Utopia::Itertools::ZipIterator< Iters >::This = ZipIterator<Iters...>
private

◆ Tuple

template<typename... Iters>
using Utopia::Itertools::ZipIterator< Iters >::Tuple = std::tuple<Iters...>
private

◆ value_type

template<typename... Iters>
using Utopia::Itertools::ZipIterator< Iters >::value_type = std::tuple<typename std::iterator_traits<Iters>::value_type...>

Constructor & Destructor Documentation

◆ ZipIterator() [1/5]

template<typename... Iters>
Utopia::Itertools::ZipIterator< Iters >::ZipIterator ( )
default

Default-construct a zip iterator. Dereferencing it is undefined.

◆ ZipIterator() [2/5]

template<typename... Iters>
Utopia::Itertools::ZipIterator< Iters >::ZipIterator ( const ZipIterator< Iters > &  other)
default

Copy-construct a zip iterator.

Parameters
otherThe iterator to copy from

◆ ZipIterator() [3/5]

template<typename... Iters>
Utopia::Itertools::ZipIterator< Iters >::ZipIterator ( ZipIterator< Iters > &&  other)
default

Move-construct a zip iterator.

Parameters
otherThe iterator to move from (will be left in undefined state)

◆ ZipIterator() [4/5]

template<typename... Iters>
Utopia::Itertools::ZipIterator< Iters >::ZipIterator ( Iters...  iters)
inline

Construct from a pack of iterators.

Parameters
itersThe iterators to bundle in this ZipIterator

◆ ZipIterator() [5/5]

template<typename... Iters>
template<typename... Iterators>
Utopia::Itertools::ZipIterator< Iters >::ZipIterator ( std::tuple< Iterators... >  iters)
inline

Construct from a tuple of iterators.

Parameters
itersThe iterators to bundle in this ZipIterator

◆ ~ZipIterator()

template<typename... Iters>
Utopia::Itertools::ZipIterator< Iters >::~ZipIterator ( )
default

Destroy this object.

Member Function Documentation

◆ operator!=()

template<typename... Iters>
template<typename... It>
bool Utopia::Itertools::ZipIterator< Iters >::operator!= ( const ZipIterator< It... > &  other) const
inline

Compare this object with another zip iterator.

This compares the internal iterators of the ZipIterator objects

Parameters
otherThe iterator to compare to
Returns
True if all internal iterators are un-equal

◆ operator*() [1/2]

template<typename... Iters>
reference Utopia::Itertools::ZipIterator< Iters >::operator* ( )
inline

Dereference this iterator at its current position.

Returns
Tuple of references to underlying object values

◆ operator*() [2/2]

template<typename... Iters>
const reference Utopia::Itertools::ZipIterator< Iters >::operator* ( ) const
inline

Dereference this iterator at its current position.

Returns
Const tuple of references to underlying object values

◆ operator+()

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
ZipIterator Utopia::Itertools::ZipIterator< Iters >::operator+ ( const difference_type  n) const
inline

Increment by a number of steps.

Parameters
nThe number of incrementation steps
Returns
A copy of this object which has been incremented by n.

◆ operator++() [1/2]

template<typename... Iters>
ZipIterator& Utopia::Itertools::ZipIterator< Iters >::operator++ ( )
inline

Increment by prefix.

Returns
Reference to this object after increment

◆ operator++() [2/2]

template<typename... Iters>
ZipIterator Utopia::Itertools::ZipIterator< Iters >::operator++ ( int  )
inline

Increment by postfix.

Returns
Copy of this object before increment

◆ operator+=()

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
ZipIterator& Utopia::Itertools::ZipIterator< Iters >::operator+= ( const difference_type  n)
inline

Increment in-place by a number of steps.

Parameters
nThe number of incrementation steps
Returns
Reference to this object after incrementing it by n.

◆ operator-() [1/2]

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
ZipIterator Utopia::Itertools::ZipIterator< Iters >::operator- ( const difference_type  n) const
inline

Decrement by a number of steps.

Parameters
nThe number of decrementation steps
Returns
A copy of this object which has been decremented by n.

◆ operator-() [2/2]

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
difference_type Utopia::Itertools::ZipIterator< Iters >::operator- ( const ZipIterator< Iters > &  other) const
inline

Compute the difference between two iterators.

Parameters
otherThe iterator to compare this object to
Returns
The difference in steps

◆ operator--() [1/2]

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::bidirectional_iterator_tag, category >, int > = 0>
ZipIterator& Utopia::Itertools::ZipIterator< Iters >::operator-- ( )
inline

Decrement by prefix.

Returns
Reference to this object after decrement

◆ operator--() [2/2]

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::bidirectional_iterator_tag, category >, int > = 0>
ZipIterator Utopia::Itertools::ZipIterator< Iters >::operator-- ( int  )
inline

Decrement by postfix.

Returns
Copy of this object before decrement

◆ operator-=()

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
ZipIterator& Utopia::Itertools::ZipIterator< Iters >::operator-= ( const difference_type  n)
inline

Decrement in-place by a number of steps.

Parameters
nThe number of decrementation steps
Returns
Reference to this object after decrementing it by n.

◆ operator->() [1/2]

template<typename... Iters>
pointer Utopia::Itertools::ZipIterator< Iters >::operator-> ( )
inline

Indirect this pointer at its current position.

Returns
Tuple of pointers to underlying object values

◆ operator->() [2/2]

template<typename... Iters>
const pointer Utopia::Itertools::ZipIterator< Iters >::operator-> ( ) const
inline

Indirect this pointer at its current position.

Returns
Const tuple of pointers to underlying object values

◆ operator<()

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
bool Utopia::Itertools::ZipIterator< Iters >::operator< ( const ZipIterator< Iters > &  other) const
inline

Less-than compare this object with another zip iterator.

This compares the internal iterators of the ZipIterator objects

Parameters
otherThe iterator to compare to
Returns
True if all internal iterators are less-than compared

◆ operator<=()

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
bool Utopia::Itertools::ZipIterator< Iters >::operator<= ( const ZipIterator< Iters > &  other) const
inline

Less-than or equal compare this object with another zip iterator.

This compares the internal iterators of the ZipIterator objects

Parameters
otherThe iterator to compare to
Returns
True if this object is not greater than the other

◆ operator=() [1/2]

template<typename... Iters>
ZipIterator& Utopia::Itertools::ZipIterator< Iters >::operator= ( const ZipIterator< Iters > &  other)
default

Copy-assign a zip iterator.

Parameters
otherThe iterator to copy from
Returns
Reference to this object after copying

◆ operator=() [2/2]

template<typename... Iters>
ZipIterator& Utopia::Itertools::ZipIterator< Iters >::operator= ( ZipIterator< Iters > &&  other)
default

Move-assign a zip iterator.

Parameters
otherThe iterator to move from (will be left in undefined state)
Returns
Reference to this object after moving

◆ operator==()

template<typename... Iters>
template<typename... It>
bool Utopia::Itertools::ZipIterator< Iters >::operator== ( const ZipIterator< It... > &  other) const
inline

Compare this object with another zip iterator.

This compares the internal iterators of the ZipIterator objects

Parameters
otherThe iterator to compare to
Returns
True if all internal iterators are equal

◆ operator>()

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
bool Utopia::Itertools::ZipIterator< Iters >::operator> ( const ZipIterator< Iters > &  other) const
inline

Greater-than compare this object with another zip iterator.

This compares the internal iterators of the ZipIterator objects

Parameters
otherThe iterator to compare to
Returns
True if all internal iterators are greater-than compared

◆ operator>=()

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
bool Utopia::Itertools::ZipIterator< Iters >::operator>= ( const ZipIterator< Iters > &  other) const
inline

Greater-than or equal compare this object with another zip iterator.

This compares the internal iterators of the ZipIterator objects

Parameters
otherThe iterator to compare to
Returns
True if this object is not less than the other

◆ operator[]()

template<typename... Iters>
template<typename category = iterator_category, typename std::enable_if_t< std::is_base_of_v< std::random_access_iterator_tag, category >, int > = 0>
reference Utopia::Itertools::ZipIterator< Iters >::operator[] ( const difference_type  n) const
inline

offset dereference operator for purely random accesss iterators held by ZipIterator

Parameters
nincrement
Returns
tuple containing references to values pointed to by zipped iterators Random access this object Create a copy of this object, increment it by the specified steps and return a reference to it. This does not modify the original iterator!
Parameters
nThe steps to increment
Returns
Dereferenced temporary which has been incremented by n steps

Friends And Related Function Documentation

◆ operator<<

template<typename... Iters>
std::ostream& operator<< ( std::ostream &  ostr,
const ZipIterator< Iters > &  right 
)
friend

Write the contents of this iterator into an outstream.

Use reporter for tuples, see std::operator<<().

Member Data Documentation

◆ _iterators

template<typename... Iters>
Tuple Utopia::Itertools::ZipIterator< Iters >::_iterators
private

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