Line data Source code
1 : #pragma once
2 :
3 : #include <chrono>
4 :
5 : namespace jage::engine::time::inline durations {
6 :
7 : using seconds = std::chrono::duration<double, std::ratio<1>>;
8 : using milliseconds = std::chrono::duration<double, std::milli>;
9 : using microseconds = std::chrono::duration<double, std::micro>;
10 : using nanoseconds = std::chrono::duration<double, std::nano>;
11 :
12 1 : constexpr auto operator""_s(unsigned long long value) -> seconds {
13 1 : return seconds{static_cast<long double>(value)};
14 : }
15 :
16 : constexpr auto operator""_ms(long double value) -> milliseconds {
17 : return milliseconds{value};
18 : }
19 :
20 1 : constexpr auto operator""_ms(unsigned long long value) -> milliseconds {
21 1 : return milliseconds{static_cast<long double>(value)};
22 : }
23 :
24 : constexpr auto operator""_us(long double value) -> microseconds {
25 : return microseconds{value};
26 : }
27 :
28 : constexpr auto operator""_ns(long double value) -> nanoseconds {
29 : return nanoseconds{value};
30 : }
31 :
32 87 : constexpr auto operator""_ns(unsigned long long value) -> nanoseconds {
33 87 : return nanoseconds{static_cast<long double>(value)};
34 : }
35 :
36 : template <class TToDuration, class TFromDuration>
37 336 : constexpr auto cast(const TFromDuration &duration) -> TToDuration {
38 336 : return std::chrono::duration_cast<TToDuration>(duration);
39 : }
40 :
41 : } // namespace jage::engine::time::inline durations
|