blob: 748404020ba9635f90efc3bfa8ee52f0db3aab17 (
plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#ifndef units_hh_INCLUDED
#define units_hh_INCLUDED
namespace Kakoune
{
template<typename RealType, typename ValueType = int>
class StronglyTypedInteger
{
public:
explicit constexpr StronglyTypedInteger(ValueType value)
: m_value(value) {}
constexpr RealType operator+(const RealType& other) const
{ return RealType(m_value + other.m_value); }
constexpr RealType operator-(const RealType& other) const
{ return RealType(m_value - other.m_value); }
constexpr RealType operator*(const RealType& other) const
{ return RealType(m_value * other.m_value); }
constexpr RealType operator/(const RealType& other) const
{ return RealType(m_value / other.m_value); }
RealType& operator+=(const RealType& other)
{ m_value += other.m_value; return static_cast<RealType&>(*this); }
RealType& operator-=(const RealType& other)
{ m_value -= other.m_value; return static_cast<RealType&>(*this); }
RealType& operator*=(const RealType& other)
{ m_value *= other.m_value; return static_cast<RealType&>(*this); }
RealType& operator/=(const RealType& other)
{ m_value /= other.m_value; return static_cast<RealType&>(*this); }
RealType& operator++()
{ ++m_value; return static_cast<RealType&>(*this); }
RealType& operator--()
{ --m_value; return static_cast<RealType&>(*this); }
RealType operator++(int)
{ RealType backup(static_cast<RealType&>(*this)); ++m_value; return backup; }
RealType operator--(int)
{ RealType backup(static_cast<RealType&>(*this)); --m_value; return backup; }
constexpr RealType operator-() { return RealType(-m_value); }
constexpr bool operator==(const RealType& other) const
{ return m_value == other.m_value; }
constexpr bool operator!=(const RealType& other) const
{ return m_value != other.m_value; }
constexpr bool operator<(const RealType& other) const
{ return m_value < other.m_value; }
constexpr bool operator<=(const RealType& other) const
{ return m_value <= other.m_value; }
constexpr bool operator>(const RealType& other) const
{ return m_value > other.m_value; }
constexpr bool operator>=(const RealType& other) const
{ return m_value >= other.m_value; }
constexpr bool operator!() const
{ return !m_value; }
explicit constexpr operator ValueType() const { return m_value; }
explicit constexpr operator bool() const { return m_value; }
private:
ValueType m_value;
};
struct LineCount : public StronglyTypedInteger<LineCount, int>
{
constexpr LineCount(int value) : StronglyTypedInteger<LineCount>(value) {}
};
inline constexpr LineCount operator"" _line(unsigned long long int value)
{
return LineCount(value);
}
struct ByteCount : public StronglyTypedInteger<ByteCount, int>
{
constexpr ByteCount(int value) : StronglyTypedInteger<ByteCount>(value) {}
};
inline constexpr ByteCount operator"" _byte(unsigned long long int value)
{
return ByteCount(value);
}
struct CharCount : public StronglyTypedInteger<CharCount, int>
{
constexpr CharCount(int value) : StronglyTypedInteger<CharCount>(value) {}
};
inline constexpr CharCount operator"" _char(unsigned long long int value)
{
return CharCount(value);
}
}
#endif // units_hh_INCLUDED
|