itertools::zip

#include <itertools.hpp>

Synopsis

template<typename R>
details::zipped<R…> zip (R &&… ranges)

Generate a zip of the ranges (similar to Python zip).

The function returns a iterable lazy object. When iterated upon, this object yields a tuple of the objects in the ranges.

Template parameters

  • R Type of the ranges

Parameters

  • ranges

    The ranges to zip.

    Warning

    The ranges have to be equal lengths or behaviour is undefined.

Example

#include <itertools/itertools.hpp>
#include <vector>
#include <iostream>

int main() {

  std::vector<int> v1 {10,11,12,13,14};
  std::vector<int> v2 {0,1,2,3,4};

  for (auto [x,y] : itertools::zip(v1, v2))
    std::cout << x << "  " << y << std::endl;
}

Output

10  0
11  1
12  2
13  3
14  4