22 #ifndef LELY_LIBC_CHRONO_HPP_
23 #define LELY_LIBC_CHRONO_HPP_
28 #include <type_traits>
33 #if __cpp_lib_chrono >= 201907L
35 using ::std::chrono::clock_cast;
39 template <
class Dest,
class Source,
class Duration>
41 inline typename ::std::enable_if<
42 ::std::is_same<Dest, Source>::value,
43 ::std::chrono::time_point<Dest, Duration>>::type
44 clock_cast(const ::std::chrono::time_point<Source, Duration>& t) {
53 template <
class Dest,
class Source,
class Duration>
55 inline typename ::std::enable_if<
56 !::std::is_same<Dest, Source>::value,
57 ::std::chrono::time_point<Dest, Duration>>::type
58 clock_cast(const ::std::chrono::time_point<Source, Duration>& t) {
60 using time_point = ::std::chrono::time_point<Dest, Duration>;
61 auto d1 = Dest::now().time_since_epoch();
62 auto s = Source::now().time_since_epoch();
63 auto d2 = Dest::now().time_since_epoch();
64 return time_point{t.time_since_epoch() + ((d1 - s) + (d2 - s)) / 2};
This header file is part of the Lely libraries; it contains the compiler feature definitions.