blob: 268fe364728e6f8e9ad3e760ec357f9acd94bdc5 (
plain) (
blame)
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
|
#pragma once
#include <util/generic/yexception.h>
namespace NYql {
template <typename T>
class TRangeWalker {
private:
const T Start_;
const T Finish_;
T Current_;
public:
TRangeWalker(T start, T finish)
: Start_(start)
, Finish_(finish)
, Current_(start)
{
if (Start_ > Finish_) {
ythrow yexception() << "Invalid range for walker";
}
}
T GetStart() const {
return Start_;
}
T GetFinish() const {
return Finish_;
}
T GetRangeSize() const {
return Finish_ - Start_ + 1;
}
T MoveToNext() {
T result = Current_++;
if (Current_ > Finish_) {
Current_ = Start_;
}
return result;
}
};
}
|