Build a zip iterator adapter
Many scripting languages include a function for zipping two sequences together. A typical zip operation will take two input sequences and return a pair of values for each position in both inputs:
Consider the case of two sequences – they can be containers, iterators, or initialization lists:
We want to zip them together to make a new sequence with pairs of elements from the first two sequences:
In this recipe we will accomplish this task with an iterator adapter.
How to do it…
In this recipe we'll build a zip iterator adapter that takes two containers of the same type and zips the values into std::pair
objects:
- In our
main()
function we want to call our adapter with two vectors:int main() { vector<std::string> vec_a {"Bob", "John", "Joni...