Spec
ZipIteratorZips multiple iterators over different containers into a single iterator.
Zips multiple iterators over different containers into a single iterator.
Extends | Iter |
---|---|
Implements | IteratorAssociatedTypesConcept |
All Extended | Iter |
All Impl'd | IteratorAssociatedTypesConcept |
Defined in | <seqan/basic.h> |
Signature |
class Iter<std::tuple<TIteratorTypes...>, ZipIterator>;
|
Template Parameters
TIteratorTypes |
A template parameter pack with one or more Iterator types. |
---|
Interface Function Overview
-
Iter() Iter(TIteratorTypes... args)
Constructor.
Interface Functions Inherited From IteratorAssociatedTypesConcept
Interface Metafunction Overview
-
typename Container<TZipIterator>::Type;
Retruns the Container type of the ZipIterator. -
typename GetValue<TZipIterator>::Type;
Retruns the GetValue type of the ZipIterator. -
typename GetValue<TZipIterator>::Type;
Retruns the Reference type of the ZipIterator. -
typename Value<TZipIterator>::Type;
Retruns the Value type of the ZipIterator.
Interface Metafunctions Inherited From Iter
Interface Metafunctions Inherited From IteratorAssociatedTypesConcept
Detailed Description
Note:
Throws an assertion if sizeof...(TIteratorTypes) == 0 is true.
This iterator ties together different iterator types for different containers of the same size. It allows one to operate on a single iterator, if multiple containers need to be traversed simultaneously. Note, that all operations are still executed in a serial fashion. If the zip iterator is dereferenced it returns a std::tuple containing the dereferenced values of all embedded iterators. The metafunctions Value, GetValue and Reference are overloaded accordingly.
To easily create a zip iterator one can use the helper function makeZipIterator.
Example
The following example demonstrates the function of the zip iterator:
#include <iostream>
#include <seqan/basic.h>
#include <seqan/sequence.h>
#include <seqan/stream.h>
using namespace seqan2;
int main()
{
StringSet<CharString> names;
StringSet<CharString> surnames;
String<int> ages;
appendValue(names, "John");
appendValue(names, "Johnny");
appendValue(names, "Garfield");
appendValue(surnames, "Doe");
appendValue(surnames, "Donny");
appendValue(surnames, "the Cat");
appendValue(ages, 98);
appendValue(ages, 20);
appendValue(ages, 42);
auto it = makeZipIterator(begin(names), begin(surnames), begin(ages));
auto itEnd = makeZipIterator(end(names), end(surnames), end(ages));
for (; it != itEnd; ++it)
std::cout << std::get<1>(*it) << ", " << std::get<0>(*it) << ": " << std::get<2>(*it) << std::endl;
return 0;
}
This outputs the following to the console:
Doe, John: 98 Donny, Johnny: 20 the Cat, Garfield: 42
Interface Functions Detail
Iter()
Iter(TIteratorTypes... args)
Constructor.
Parameters
args
|
The iterator instances to create the ZipIterator from. Default constructors are not listed. |
---|
Data Races
If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.