Lely core libraries 2.3.4
chrono.hpp
Go to the documentation of this file.
1
22#ifndef LELY_LIBC_CHRONO_HPP_
23#define LELY_LIBC_CHRONO_HPP_
24
25#include <lely/features.h>
26
27#include <chrono>
28#include <type_traits>
29
30namespace lely {
31namespace compat {
32
33#if __cpp_lib_chrono >= 201907L
34
35using ::std::chrono::clock_cast;
36
37#else // __cpp_lib_chrono < 201907L
38
39template <class Dest, class Source, class Duration>
40// clang-format off
41inline typename ::std::enable_if<
42 ::std::is_same<Dest, Source>::value,
43 ::std::chrono::time_point<Dest, Duration>>::type
44clock_cast(const ::std::chrono::time_point<Source, Duration>& t) {
45 // clang-format on
46 return t;
47}
48
53template <class Dest, class Source, class Duration>
54// clang-format off
55inline typename ::std::enable_if<
56 !::std::is_same<Dest, Source>::value,
57 ::std::chrono::time_point<Dest, Duration>>::type
58clock_cast(const ::std::chrono::time_point<Source, Duration>& t) {
59 // clang-format on
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};
65}
66
67#endif // __cpp_lib_chrono < 201907L
68
69} // namespace compat
70} // namespace lely
71
72#endif // !LELY_LIBC_CHRONO_HPP_
A CANopen value.
Definition val.hpp:42
This header file is part of the Lely libraries; it contains the compiler feature definitions.