Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
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.
 
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.
 
ZipIterator operator++ (int)
 Increment by postfix.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
const reference operator* () const
 Dereference this iterator at its current position.
 
reference operator* ()
 Dereference this iterator at its current position.
 
const pointer operator-> () const
 Indirect this pointer at its current position.
 
pointer operator-> ()
 Indirect this pointer at its current position.
 
 ZipIterator ()=default
 Default-construct a zip iterator. Dereferencing it is undefined.
 
 ZipIterator (const ZipIterator &other)=default
 Copy-construct a zip iterator.
 
 ZipIterator (ZipIterator &&other)=default
 Move-construct a zip iterator.
 
ZipIteratoroperator= (ZipIterator &&other)=default
 Move-assign a zip iterator.
 
ZipIteratoroperator= (const ZipIterator &other)=default
 Copy-assign a zip iterator.
 
 ZipIterator (Iters... iters)
 Construct from a pack of iterators.
 
template<typename... Iterators>
 ZipIterator (std::tuple< Iterators... > iters)
 Construct from a tuple of iterators.
 
template<typename... It>
bool operator== (const ZipIterator< It... > &other) const
 Compare this object with another zip iterator.
 
template<typename... It>
bool operator!= (const ZipIterator< It... > &other) const
 Compare this object with another zip iterator.
 
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.
 
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.
 
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.
 
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.
 
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
 
 ~ZipIterator ()=default
 Destroy this object.
 

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.
 

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
248 : _iterators(std::make_tuple(iters...))
249 {
250 }
Tuple _iterators
Definition zip.hh:50
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213

◆ 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
257 {
258 }

◆ ~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
278 {
279 return _iterators != other._iterators;
280 }

◆ 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
191 {
192 return boost::hana::transform(
194 [](auto&& iter) { return std::ref(*iter); });
195 }

◆ 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
181 {
182 return boost::hana::transform(
184 [](auto&& iter) { return std::ref(*iter); });
185 }

◆ 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.
117 {
118 This copy(*this);
119 return copy += n;
120 }
ZipIterator< Iters... > This
Definition zip.hh:52
OutputIt copy(const Utopia::ExecPolicy policy, InputIt first, InputIt last, OutputIt d_first)
Copy the input range to a new range.
Definition parallel.hh:324

◆ operator++() [1/2]

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

Increment by prefix.

Returns
Reference to this object after increment
66 {
67 boost::hana::for_each(_iterators, [](auto&& iter) { ++iter; });
68 return *this;
69 }

◆ operator++() [2/2]

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

Increment by postfix.

Returns
Copy of this object before increment
88 {
89 This copy(*this);
90 boost::hana::for_each(_iterators, [](auto&& iter) { iter++; });
91 return copy;
92 }

◆ 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.
158 {
159 boost::hana::for_each(_iterators, [&n](auto&& iter) { iter += n; });
160 return *this;
161 }

◆ 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.
131 {
132 This copy(*this);
133 return copy -= n;
134 }

◆ 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
145 {
146 return std::get<0>(_iterators) - std::get<0>(other._iterators);
147 }

◆ 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
79 {
80 boost::hana::for_each(_iterators, [](auto&& iter) { --iter; });
81 return *this;
82 }

◆ 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
102 {
103 This copy(*this);
104 boost::hana::for_each(_iterators, [](auto&& iter) { iter--; });
105 return copy;
106 }

◆ 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.
172 {
173 boost::hana::for_each(_iterators, [&n](auto&& iter) { iter -= n; });
174 return *this;
175 }

◆ 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
211 {
212 return boost::hana::transform(
214 [](auto&& iter) { return &(*iter); });
215 }

◆ 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
201 {
202 return boost::hana::transform(
204 [](auto&& iter) { return &(*iter); });
205 }

◆ 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
292 {
293 return _iterators < other._iterators;
294 }

◆ 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
306 {
307 return _iterators <= other._iterators;
308 }

◆ 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
267 {
268 return _iterators == other._iterators;
269 }

◆ 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
320 {
321 return _iterators > other._iterators;
322 }

◆ 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
334 {
335 return _iterators >= other._iterators;
336 }

◆ 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
357 {
358 return *(*this + n);
359 }

Friends And Related Symbol 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<<().

370 {
371 // using Utopia::Utils::operator<<;
372 ostr << "->" << *right;
373 return ostr;
374 }

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: