forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip_longest_examples.cpp
More file actions
29 lines (25 loc) · 737 Bytes
/
Copy pathzip_longest_examples.cpp
File metadata and controls
29 lines (25 loc) · 737 Bytes
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
#include <zip_longest.hpp>
#include <vector>
#include <string>
#include <iostream>
#include <array>
#include <boost/optional.hpp>
// prints Just VALUE or Nothing
template <typename T>
std::ostream & operator<<(std::ostream & out, const boost::optional<T>& opt) {
if (opt) {
out << "Just " << *opt;
} else {
out << "Nothing";
}
return out;
}
int main() {
std::vector<int> ivec = {1, 4, 9, 16, 25, 36};
std::vector<std::string> svec = {"hello", "good day", "goodbye"};
std::cout << "zipping a vector of strings with a vector of ints:\n";
for (auto&& e : iter::zip_longest(ivec, svec)) {
std::cout << '(' << std::get<0>(e) << ", "
<< std::get<1>(e) << ")\n";
}
}