-
Notifications
You must be signed in to change notification settings - Fork 0
/
iters.hxx
33 lines (28 loc) · 780 Bytes
/
iters.hxx
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
#pragma once
#include <glm/vec2.hpp>
#include "gen.hxx"
template <typename T>
generator<T> irange(T start, T stop, T step = T{1});
template <>
generator<int> irange<int>(int start, int stop, int step) {
for (int x = start; x < stop; x += step)
co_yield x;
}
template <>
generator<glm::ivec2> irange<glm::ivec2>(glm::ivec2 start, glm::ivec2 stop, glm::ivec2 step) {
for (int y = start.y; y < stop.y; y += step.y)
for (int x = start.x; x < stop.x; x += step.x)
co_yield {x, y};
}
template <typename T>
generator<T> irange(T stop) {
return irange<T>({}, stop);
}
template <typename C>
auto enumerate(C &&container) -> generator<std::pair<int, decltype(*std::begin(container))>> {
int index = 0;
for (auto &&item: container) {
co_yield {index, item};
++index;
}
}