-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharoundIt.cpp
65 lines (58 loc) · 1.22 KB
/
aroundIt.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <span>
#include <array>
namespace pointsSpace
{
using steps = std::pair<uint8_t, uint8_t>;
}
std::array<pointsSpace::steps, 4> basicMoves = {
pointsSpace::steps{1, 0},
pointsSpace::steps{-1, 0},
pointsSpace::steps{0, 1},
pointsSpace::steps{0, -1},
};
template <typename AxisType, typename MovesType>
class AroundIter
{
using Point = pair<AxisType, AxisType>;
Point start;
Point now_;
std::span<MovesType> moves_;
short step = 0;
Point add(Point raw, MovesType step)
{
raw.first += step.first;
raw.second += step.second;
return raw;
}
public:
AroundIter(Point pt, std::span<MovesType> moves = basicMoves) : start{pt}, step{0}, moves_{moves}
{
}
template <class T>
bool operator!=(const T &t)
{
return step < sp.size();
}
Point operator*() { return now_; }
void operator++()
{
now_ = add(start, moves_[step++]);
return;
}
};
template <typename AxisType>
class AroundWrap
{
public:
using Point = pair<AxisType, AxisType>;
Point pt;
AroundWrap(Point p) : pt{p} {}
auto begin()
{
return AroundIter(pt);
}
auto end()
{
return nullptr;
}
};