R-Type  2
Doom but in better
Loading...
Searching...
No Matches
IndexedZipper.hpp
Go to the documentation of this file.
1#pragma once
2
4
14template <class... Containers>
16public:
18 using iterator = IndexedZipperIterator<Containers...>;
21
27 IndexedZipper(Containers&... cs)
28 : _begin(create_iterators(cs...)), _end(create_end_iterators(cs...)),
29 _size(_compute_size(cs...)) {}
30
37 return iterator(_begin, _size);
38 }
39
46 return iterator(_end, _size, _size);
47 }
48
49private:
58 static std::size_t _compute_size(Containers&... containers) {
59 return std::min({containers.size()...});
60 }
61
68 static iterator_t create_iterators(Containers&... containers) {
69 return iterator_t(containers.begin()...);
70 }
71
78 static iterator_t create_end_iterators(Containers&... containers) {
79 return iterator_t(containers.end()...);
80 }
81
82private:
83 iterator_t _begin;
84 iterator_t _end;
85 std::size_t _size;
86};
Iterator for traversing the elements of multiple zipped containers, paired with their indices.
std::tuple< iterator_t< Containers >... > iterator_tuple
Type alias for the tuple of iterators for the containers being iterated.
Combines multiple containers into a single iterable unit, iterating over corresponding elements from ...
typename iterator::iterator_tuple iterator_t
Type alias for the tuple of iterators for the zipped containers.
IndexedZipperIterator< Containers... > iterator
Type alias for the iterator type.
iterator end()
Returns an iterator to the end of the zipped containers.
iterator begin()
Returns an iterator to the beginning of the zipped containers.
IndexedZipper(Containers &... cs)
Constructs an IndexedZipper with the given containers.