22 #ifndef LELY_LIBC_CHRONO_HPP_
23 #define LELY_LIBC_CHRONO_HPP_
28 #include <type_traits>
33 #if __cplusplus <= 201703L
35 template <
class Dest,
class Source,
class Duration>
37 inline typename ::std::enable_if<
38 ::std::is_same<Dest, Source>::value,
39 ::std::chrono::time_point<Dest, Duration>>::type
40 clock_cast(const ::std::chrono::time_point<Source, Duration>& t) {
49 template <
class Dest,
class Source,
class Duration>
51 inline typename ::std::enable_if<
52 !::std::is_same<Dest, Source>::value,
53 ::std::chrono::time_point<Dest, Duration>>::type
54 clock_cast(const ::std::chrono::time_point<Source, Duration>& t) {
56 using time_point = ::std::chrono::time_point<Dest, Duration>;
57 auto d1 = Dest::now().time_since_epoch();
58 auto s = Source::now().time_since_epoch();
59 auto d2 = Dest::now().time_since_epoch();
60 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.