-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathZipLongest.cpp
36 lines (33 loc) · 940 Bytes
/
ZipLongest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <Lz/ZipLongest.hpp>
#include <iostream>
#include <list>
#include <vector>
int main() {
std::vector<int> v1 = { 1, 2, 3, 4, 5, 6 };
std::list<char> v2 = { 'h', 'e', 'l', 'l' };
std::vector<int> v3 = { 1, 2, 3 };
// Iterator is forward, since v2 is bidirectional (it decays to forward if one of the iterators is bidirectional or lower,
// otherwise its random access)
for (auto&& tup : lz::zipLongest(v1, v2, v3)) { // Elements are accessed by value
auto&& first = std::get<0>(tup);
auto&& second = std::get<1>(tup);
auto&& third = std::get<2>(tup);
if (first) {
std::cout << *first << ' ';
}
if (second) {
std::cout << *second << ' ';
}
if (third) {
std::cout << *third << ' ';
}
std::cout << '\n';
}
// Output:
// 1 h 1
// 2 e 2
// 3 l 3
// 4 l
// 5
// 6
}