7
7
8
8
#include < chrono>
9
9
#include < ratio>
10
+ #include < type_traits>
10
11
11
12
#include " CoreApi.h"
12
13
@@ -18,6 +19,7 @@ namespace gf {
18
19
using ClockType = std::conditional_t <std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, std::chrono::steady_clock>;
19
20
using DurationType = ClockType::duration;
20
21
using TimePointType = ClockType::time_point;
22
+ using RepType = DurationType::rep;
21
23
}
22
24
23
25
class GF_CORE_API Time {
@@ -140,6 +142,37 @@ namespace gf {
140
142
return Time (lhs.as_duration () - rhs.as_duration ());
141
143
}
142
144
145
+ template <typename T>
146
+ constexpr Time operator *(Time lhs, std::enable_if_t <std::is_arithmetic_v<T>, T> rhs)
147
+ {
148
+ auto duration = lhs * rhs;
149
+ return Time (std::chrono::duration_cast<details::DurationType>(duration));
150
+ }
151
+
152
+ template <typename T>
153
+ constexpr Time operator *(std::enable_if_t <std::is_arithmetic_v<T>, T> lhs, Time rhs)
154
+ {
155
+ auto duration = lhs * rhs;
156
+ return Time (std::chrono::duration_cast<details::DurationType>(duration));
157
+ }
158
+
159
+ template <typename T>
160
+ constexpr Time operator /(Time lhs, std::enable_if_t <std::is_arithmetic_v<T>, T> rhs)
161
+ {
162
+ auto duration = lhs / rhs;
163
+ return Time (std::chrono::duration_cast<details::DurationType>(duration));
164
+ }
165
+
166
+ constexpr details::RepType operator /(Time lhs, Time rhs)
167
+ {
168
+ return lhs.as_duration () / rhs.as_duration ();
169
+ }
170
+
171
+ constexpr Time operator %(Time lhs, details::RepType rhs)
172
+ {
173
+ return Time (lhs.as_duration () % rhs);
174
+ }
175
+
143
176
GF_CORE_API Serializer& operator |(Serializer& archive, Time time);
144
177
GF_CORE_API Deserializer& operator |(Deserializer& archive, Time& time);
145
178
0 commit comments