ctrl-utils
chrono.h
1 
10 #if __cplusplus < 201703L
11 
12 #include <chrono> // std::chrono
13 #include <type_traits> // std::enable_if_t
14 
15 namespace std {
16 namespace chrono {
17 
18 template<class T> struct is_duration : std::false_type {};
19 template<class Rep, class Period> struct is_duration<std::chrono::duration<Rep, Period>>
20  : std::true_type {};
21 
22 template<class To, class Rep, class Period, class = std::enable_if_t<is_duration<To>{}>>
23 constexpr To floor(const duration<Rep, Period>& d) {
24  To t = std::chrono::duration_cast<To>(d);
25  if (t > d) return t - To{1};
26  return t;
27 }
28 
29 template<class To, class Clock, class FromDuration, class = std::enable_if_t<is_duration<To>{}>>
30 constexpr std::chrono::time_point<Clock, To>
31 floor(const std::chrono::time_point<Clock, FromDuration>& tp) {
32  return std::chrono::time_point<Clock, To>{ std::chrono::floor<To>(tp.time_since_epoch()) };
33 }
34 
35 } // namespace chrono
36 } // namespace std
37 
38 #endif // __cplusplus
Definition: chrono.h:15
Definition: chrono.h:18