itertools::enumerate

#include <itertools.hpp>

Synopsis

template<typename R>
details::enumerated<R> enumerate (R && range)

Lazy-enumerate a range (similar to Python enumerate)

The function returns a iterable lazy object. When iterated upon, this object yields a pair (n,x) where :

  • n is the index (starting at 0)
  • x is in the object in the range

Template parameters

  • R Type of the ranges

Parameters

  • range The range to enumerate

Example

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

int main() {

  std::vector<int> v {10,11,12,13,14};

  for (auto [n,x] : itertools::enumerate(v))
    std::cout << n << "  " << x << std::endl;
}

Output

0  10
1  11
2  12
3  13
4  14