-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnatural.h
62 lines (54 loc) · 2.12 KB
/
natural.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef NATURAL_H
#define NATURAL_H
#include <iterator>
namespace refactor {
template<class t = size_t>
class natural_t : public std::iterator<std::input_iterator_tag, t> {
t _i;
public:
natural_t(t val) noexcept : _i(val) {}
bool operator==(natural_t const &rhs) const noexcept { return _i == rhs._i; }
bool operator!=(natural_t const &rhs) const noexcept { return _i != rhs._i; }
bool operator<(natural_t const &rhs) const noexcept { return _i < rhs._i; }
bool operator>(natural_t const &rhs) const noexcept { return _i > rhs._i; }
bool operator<=(natural_t const &rhs) const noexcept { return _i <= rhs._i; }
bool operator>=(natural_t const &rhs) const noexcept { return _i >= rhs._i; }
natural_t &operator++() noexcept {
++_i;
return *this;
}
natural_t operator++(int) noexcept {
auto ans = *this;
operator++();
return ans;
}
t operator*() const noexcept {
return _i;
}
};
template<class t = size_t>
class rev_natural_t : public std::iterator<std::input_iterator_tag, t> {
t _i;
public:
rev_natural_t(t val) noexcept : _i(val - 1) {}
bool operator==(rev_natural_t const &rhs) const noexcept { return _i == rhs._i; }
bool operator!=(rev_natural_t const &rhs) const noexcept { return _i != rhs._i; }
bool operator<(rev_natural_t const &rhs) const noexcept { return _i > rhs._i; }
bool operator>(rev_natural_t const &rhs) const noexcept { return _i < rhs._i; }
bool operator<=(rev_natural_t const &rhs) const noexcept { return _i >= rhs._i; }
bool operator>=(rev_natural_t const &rhs) const noexcept { return _i <= rhs._i; }
rev_natural_t &operator++() noexcept {
--_i;
return *this;
}
rev_natural_t operator++(int) noexcept {
auto ans = *this;
operator++();
return ans;
}
t operator*() const noexcept {
return _i;
}
};
}// namespace refactor
#endif// NATURAL_H