-
Notifications
You must be signed in to change notification settings - Fork 0
/
Epoch.h
42 lines (36 loc) · 961 Bytes
/
Epoch.h
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
#pragma once
namespace tower120::utils{
class Epoch{
using Value = unsigned int;
Value value = 1;
explicit constexpr Epoch(Value value) : value(value) {}
public:
Epoch() = default;
Epoch& operator++() {
value++;
return *this;
}
Epoch operator++(int) {
return Epoch(value+1);
}
bool operator==(const Epoch& other) const {
return value == other.value;
}
bool operator!=(const Epoch& other) const {
return value != other.value;
}
// return need update
[[nodiscard]]
bool update(const Epoch& other){
if (value == other.value) return false;
value = other.value;
return true;
}
Value count() const {
return value;
}
constexpr static Epoch Pre(){
return Epoch{0};
}
};
}