77
88#include < chrono>
99#include < ratio>
10+ #include < type_traits>
1011
1112#include " CoreApi.h"
1213
@@ -18,6 +19,7 @@ namespace gf {
1819 using ClockType = std::conditional_t <std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, std::chrono::steady_clock>;
1920 using DurationType = ClockType::duration;
2021 using TimePointType = ClockType::time_point;
22+ using RepType = DurationType::rep;
2123 }
2224
2325 class GF_CORE_API Time {
@@ -140,6 +142,37 @@ namespace gf {
140142 return Time (lhs.as_duration () - rhs.as_duration ());
141143 }
142144
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+
143176 GF_CORE_API Serializer& operator |(Serializer& archive, Time time);
144177 GF_CORE_API Deserializer& operator |(Deserializer& archive, Time& time);
145178
0 commit comments