30 #ifndef _GLIBCXX_CHRONO
31 #define _GLIBCXX_CHRONO 1
33 #pragma GCC system_header
35 #if __cplusplus < 201103L
44 #if __cplusplus > 201703L
48 namespace std _GLIBCXX_VISIBILITY(default)
50 _GLIBCXX_BEGIN_NAMESPACE_VERSION
52 #if __cplusplus >= 201703L
53 namespace filesystem {
struct __file_clock; };
69 template<
typename _Rep,
typename _Period = ratio<1>>
72 template<
typename _Clock,
typename _Dur =
typename _Clock::duration>
80 template<
typename _CT,
typename _Period1,
typename _Period2,
typename =
void>
81 struct __duration_common_type
84 template<
typename _CT,
typename _Period1,
typename _Period2>
85 struct __duration_common_type<_CT, _Period1, _Period2,
86 __void_t<typename _CT::type>>
89 using __gcd_num = __static_gcd<_Period1::num, _Period2::num>;
90 using __gcd_den = __static_gcd<_Period1::den, _Period2::den>;
91 using __cr =
typename _CT::type;
92 using __r =
ratio<__gcd_num::value,
93 (_Period1::den / __gcd_den::value) * _Period2::den>;
99 template<
typename _Period1,
typename _Period2>
100 struct __duration_common_type<__failure_type, _Period1, _Period2>
101 {
typedef __failure_type type; };
107 template<
typename _Rep1,
typename _Period1,
typename _Rep2,
typename _Period2>
110 : __duration_common_type<common_type<_Rep1, _Rep2>, _Period1, _Period2>
117 template<
typename _CT,
typename _Clock,
typename =
void>
118 struct __timepoint_common_type
121 template<
typename _CT,
typename _Clock>
122 struct __timepoint_common_type<_CT, _Clock, __void_t<typename _CT::type>>
124 using type = chrono::time_point<_Clock, typename _CT::type>;
131 template<
typename _Clock,
typename _Duration1,
typename _Duration2>
134 : __timepoint_common_type<common_type<_Duration1, _Duration2>, _Clock>
147 template<
typename _ToDur,
typename _CF,
typename _CR,
148 bool _NumIsOne =
false,
bool _DenIsOne =
false>
149 struct __duration_cast_impl
151 template<
typename _Rep,
typename _Period>
152 static constexpr _ToDur
153 __cast(
const duration<_Rep, _Period>& __d)
155 typedef typename _ToDur::rep __to_rep;
156 return _ToDur(
static_cast<__to_rep
>(
static_cast<_CR
>(__d.count())
157 *
static_cast<_CR
>(_CF::num)
158 /
static_cast<_CR
>(_CF::den)));
162 template<
typename _ToDur,
typename _CF,
typename _CR>
163 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
165 template<
typename _Rep,
typename _Period>
166 static constexpr _ToDur
167 __cast(
const duration<_Rep, _Period>& __d)
169 typedef typename _ToDur::rep __to_rep;
170 return _ToDur(
static_cast<__to_rep
>(__d.count()));
174 template<
typename _ToDur,
typename _CF,
typename _CR>
175 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
177 template<
typename _Rep,
typename _Period>
178 static constexpr _ToDur
179 __cast(
const duration<_Rep, _Period>& __d)
181 typedef typename _ToDur::rep __to_rep;
182 return _ToDur(
static_cast<__to_rep
>(
183 static_cast<_CR
>(__d.count()) /
static_cast<_CR
>(_CF::den)));
187 template<
typename _ToDur,
typename _CF,
typename _CR>
188 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
190 template<
typename _Rep,
typename _Period>
191 static constexpr _ToDur
192 __cast(
const duration<_Rep, _Period>& __d)
194 typedef typename _ToDur::rep __to_rep;
195 return _ToDur(
static_cast<__to_rep
>(
196 static_cast<_CR
>(__d.count()) *
static_cast<_CR
>(_CF::num)));
200 template<
typename _Tp>
205 template<
typename _Rep,
typename _Period>
206 struct __is_duration<duration<_Rep, _Period>>
210 template<
typename _Tp>
211 using __enable_if_is_duration
212 =
typename enable_if<__is_duration<_Tp>::value, _Tp>::type;
214 template<
typename _Tp>
215 using __disable_if_is_duration
216 =
typename enable_if<!__is_duration<_Tp>::value, _Tp>::type;
221 template<
typename _ToDur,
typename _Rep,
typename _Period>
222 constexpr __enable_if_is_duration<_ToDur>
225 typedef typename _ToDur::period __to_period;
226 typedef typename _ToDur::rep __to_rep;
230 typedef __duration_cast_impl<_ToDur, __cf, __cr,
231 __cf::num == 1, __cf::den == 1> __dc;
232 return __dc::__cast(__d);
236 template<
typename _Rep>
241 #if __cplusplus > 201402L
242 template <
typename _Rep>
243 inline constexpr
bool treat_as_floating_point_v =
247 #if __cplusplus > 201703L
248 template<
typename _Tp>
251 template<
typename _Tp>
252 inline constexpr
bool is_clock_v = is_clock<_Tp>::value;
254 #if __cpp_lib_concepts
255 template<
typename _Tp>
259 template<
typename _Tp>
262 typename _Tp::period;
263 typename _Tp::duration;
264 typename _Tp::time_point::clock;
265 typename _Tp::time_point::duration;
266 { &_Tp::is_steady } -> same_as<const bool*>;
267 { _Tp::now() } -> same_as<typename _Tp::time_point>;
268 requires same_as<
typename _Tp::duration,
269 duration<typename _Tp::rep, typename _Tp::period>>;
270 requires same_as<
typename _Tp::time_point::duration,
271 typename _Tp::duration>;
276 template<
typename _Tp,
typename =
void>
280 template<
typename _Tp>
281 struct __is_clock_impl<_Tp,
282 void_t<typename _Tp::rep, typename _Tp::period,
283 typename _Tp::duration,
284 typename _Tp::time_point::duration,
285 decltype(_Tp::is_steady),
286 decltype(_Tp::now())>>
287 : __and_<is_same<typename _Tp::duration,
288 duration<typename _Tp::rep, typename _Tp::period>>,
289 is_same<typename _Tp::time_point::duration,
290 typename _Tp::duration>,
291 is_same<decltype(&_Tp::is_steady), const bool*>,
292 is_same<decltype(_Tp::now()), typename _Tp::time_point>>::type
295 template<
typename _Tp>
296 struct is_clock : __is_clock_impl<_Tp>::type
301 #if __cplusplus >= 201703L
302 # define __cpp_lib_chrono 201611
304 template<
typename _ToDur,
typename _Rep,
typename _Period>
305 constexpr __enable_if_is_duration<_ToDur>
306 floor(
const duration<_Rep, _Period>& __d)
308 auto __to = chrono::duration_cast<_ToDur>(__d);
310 return __to - _ToDur{1};
314 template<
typename _ToDur,
typename _Rep,
typename _Period>
315 constexpr __enable_if_is_duration<_ToDur>
316 ceil(
const duration<_Rep, _Period>& __d)
318 auto __to = chrono::duration_cast<_ToDur>(__d);
320 return __to + _ToDur{1};
324 template <
typename _ToDur,
typename _Rep,
typename _Period>
326 __and_<__is_duration<_ToDur>,
327 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
329 round(
const duration<_Rep, _Period>& __d)
331 _ToDur __t0 = chrono::floor<_ToDur>(__d);
332 _ToDur __t1 = __t0 + _ToDur{1};
333 auto __diff0 = __d - __t0;
334 auto __diff1 = __t1 - __d;
335 if (__diff0 == __diff1)
337 if (__t0.count() & 1)
341 else if (__diff0 < __diff1)
346 template<
typename _Rep,
typename _Period>
348 enable_if_t<numeric_limits<_Rep>::is_signed, duration<_Rep, _Period>>
349 abs(duration<_Rep, _Period> __d)
351 if (__d >= __d.zero())
358 template<
typename _Rep>
361 static constexpr _Rep
365 static constexpr _Rep
369 static constexpr _Rep
376 template<
typename _Tp>
381 template<
intmax_t _Num,
intmax_t _Den>
382 struct __is_ratio<
ratio<_Num, _Den>>
389 template<
typename _Rep,
typename _Period>
393 template<
typename _Rep2>
394 using __is_float = treat_as_floating_point<_Rep2>;
397 template<
typename _Period2>
399 = __bool_constant<ratio_divide<_Period2, _Period>::den == 1>;
404 typedef _Period period;
406 static_assert(!__is_duration<_Rep>::value,
"rep cannot be a duration");
407 static_assert(__is_ratio<_Period>::value,
408 "period must be a specialization of ratio");
409 static_assert(_Period::num > 0,
"period must be positive");
412 constexpr duration() =
default;
414 duration(
const duration&) =
default;
418 template<
typename _Rep2,
typename = _Require<
419 is_convertible<const _Rep2&, rep>,
420 __or_<__is_float<rep>, __not_<__is_float<_Rep2>>>>>
421 constexpr
explicit duration(
const _Rep2& __rep)
422 : __r(static_cast<rep>(__rep)) { }
424 template<
typename _Rep2,
typename _Period2,
typename = _Require<
425 __or_<__is_float<rep>,
426 __and_<__is_harmonic<_Period2>,
427 __not_<__is_float<_Rep2>>>>>>
428 constexpr duration(
const duration<_Rep2, _Period2>& __d)
431 ~duration() =
default;
432 duration& operator=(
const duration&) =
default;
446 {
return duration(-__r); }
448 _GLIBCXX17_CONSTEXPR duration&
455 _GLIBCXX17_CONSTEXPR duration
457 {
return duration(__r++); }
459 _GLIBCXX17_CONSTEXPR duration&
466 _GLIBCXX17_CONSTEXPR duration
468 {
return duration(__r--); }
470 _GLIBCXX17_CONSTEXPR duration&
471 operator+=(
const duration& __d)
477 _GLIBCXX17_CONSTEXPR duration&
478 operator-=(
const duration& __d)
484 _GLIBCXX17_CONSTEXPR duration&
485 operator*=(
const rep& __rhs)
491 _GLIBCXX17_CONSTEXPR duration&
492 operator/=(
const rep& __rhs)
499 template<
typename _Rep2 = rep>
501 typename enable_if<!treat_as_floating_point<_Rep2>::value,
503 operator%=(
const rep& __rhs)
509 template<
typename _Rep2 = rep>
511 typename enable_if<!treat_as_floating_point<_Rep2>::value,
513 operator%=(
const duration& __d)
520 static constexpr duration
522 {
return duration(duration_values<rep>::zero()); }
524 static constexpr duration
526 {
return duration(duration_values<rep>::min()); }
528 static constexpr duration
530 {
return duration(duration_values<rep>::max()); }
539 template<
typename _Rep1,
typename _Period1,
540 typename _Rep2,
typename _Period2>
541 constexpr
typename common_type<duration<_Rep1, _Period1>,
542 duration<_Rep2, _Period2>>::type
549 return __cd(__cd(__lhs).count() + __cd(__rhs).count());
553 template<
typename _Rep1,
typename _Period1,
554 typename _Rep2,
typename _Period2>
563 return __cd(__cd(__lhs).count() - __cd(__rhs).count());
574 template<
typename _Rep1,
typename _Rep2,
576 using __common_rep_t =
typename
584 template<
typename _Rep1,
typename _Period,
typename _Rep2>
590 return __cd(__cd(__d).count() * __s);
594 template<
typename _Rep1,
typename _Rep2,
typename _Period>
597 {
return __d * __s; }
599 template<
typename _Rep1,
typename _Period,
typename _Rep2>
606 return __cd(__cd(__d).count() / __s);
609 template<
typename _Rep1,
typename _Period1,
610 typename _Rep2,
typename _Period2>
612 operator/(
const duration<_Rep1, _Period1>& __lhs,
613 const duration<_Rep2, _Period2>& __rhs)
615 typedef duration<_Rep1, _Period1> __dur1;
616 typedef duration<_Rep2, _Period2> __dur2;
618 return __cd(__lhs).count() / __cd(__rhs).count();
622 template<
typename _Rep1,
typename _Period,
typename _Rep2>
624 duration<__common_rep_t<_Rep1, __disable_if_is_duration<_Rep2>>, _Period>
625 operator%(
const duration<_Rep1, _Period>& __d,
const _Rep2& __s)
627 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
629 return __cd(__cd(__d).count() % __s);
632 template<
typename _Rep1,
typename _Period1,
633 typename _Rep2,
typename _Period2>
634 constexpr
typename common_type<duration<_Rep1, _Period1>,
635 duration<_Rep2, _Period2>>::type
636 operator%(
const duration<_Rep1, _Period1>& __lhs,
637 const duration<_Rep2, _Period2>& __rhs)
639 typedef duration<_Rep1, _Period1> __dur1;
640 typedef duration<_Rep2, _Period2> __dur2;
641 typedef typename common_type<__dur1,__dur2>::type __cd;
642 return __cd(__cd(__lhs).count() % __cd(__rhs).count());
647 template<
typename _Rep1,
typename _Period1,
648 typename _Rep2,
typename _Period2>
650 operator==(
const duration<_Rep1, _Period1>& __lhs,
651 const duration<_Rep2, _Period2>& __rhs)
653 typedef duration<_Rep1, _Period1> __dur1;
654 typedef duration<_Rep2, _Period2> __dur2;
655 typedef typename common_type<__dur1,__dur2>::type __ct;
656 return __ct(__lhs).count() == __ct(__rhs).count();
659 template<
typename _Rep1,
typename _Period1,
660 typename _Rep2,
typename _Period2>
662 operator<(
const duration<_Rep1, _Period1>& __lhs,
663 const duration<_Rep2, _Period2>& __rhs)
665 typedef duration<_Rep1, _Period1> __dur1;
666 typedef duration<_Rep2, _Period2> __dur2;
667 typedef typename common_type<__dur1,__dur2>::type __ct;
668 return __ct(__lhs).count() < __ct(__rhs).count();
671 template<
typename _Rep1,
typename _Period1,
672 typename _Rep2,
typename _Period2>
674 operator!=(
const duration<_Rep1, _Period1>& __lhs,
675 const duration<_Rep2, _Period2>& __rhs)
676 {
return !(__lhs == __rhs); }
678 template<
typename _Rep1,
typename _Period1,
679 typename _Rep2,
typename _Period2>
681 operator<=(
const duration<_Rep1, _Period1>& __lhs,
682 const duration<_Rep2, _Period2>& __rhs)
683 {
return !(__rhs < __lhs); }
685 template<
typename _Rep1,
typename _Period1,
686 typename _Rep2,
typename _Period2>
688 operator>(
const duration<_Rep1, _Period1>& __lhs,
689 const duration<_Rep2, _Period2>& __rhs)
690 {
return __rhs < __lhs; }
692 template<
typename _Rep1,
typename _Period1,
693 typename _Rep2,
typename _Period2>
695 operator>=(
const duration<_Rep1, _Period1>& __lhs,
696 const duration<_Rep2, _Period2>& __rhs)
697 {
return !(__lhs < __rhs); }
701 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
702 # define _GLIBCXX_CHRONO_INT64_T int64_t
703 #elif defined __INT64_TYPE__
704 # define _GLIBCXX_CHRONO_INT64_T __INT64_TYPE__
707 "Representation type for nanoseconds must have at least 64 bits");
708 # define _GLIBCXX_CHRONO_INT64_T long long
729 #if __cplusplus > 201703L
743 #undef _GLIBCXX_CHRONO_INT64_T
746 template<
typename _Clock,
typename _Dur>
749 static_assert(__is_duration<_Dur>::value,
750 "duration must be a specialization of std::chrono::duration");
752 typedef _Clock clock;
754 typedef typename duration::rep rep;
755 typedef typename duration::period period;
757 constexpr
time_point() : __d(duration::zero())
765 template<
typename _Dur2,
766 typename = _Require<is_convertible<_Dur2, _Dur>>>
768 : __d(__t.time_since_epoch())
773 time_since_epoch()
const
805 template<
typename _ToDur,
typename _Clock,
typename _Dur>
807 time_point<_Clock, _ToDur>>::type
811 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
814 #if __cplusplus > 201402L
815 template<
typename _ToDur,
typename _Clock,
typename _Dur>
818 floor(
const time_point<_Clock, _Dur>& __tp)
820 return time_point<_Clock, _ToDur>{
821 chrono::floor<_ToDur>(__tp.time_since_epoch())};
824 template<
typename _ToDur,
typename _Clock,
typename _Dur>
826 enable_if_t<__is_duration<_ToDur>::value, time_point<_Clock, _ToDur>>
827 ceil(
const time_point<_Clock, _Dur>& __tp)
829 return time_point<_Clock, _ToDur>{
830 chrono::ceil<_ToDur>(__tp.time_since_epoch())};
833 template<
typename _ToDur,
typename _Clock,
typename _Dur>
835 __and_<__is_duration<_ToDur>,
836 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
837 time_point<_Clock, _ToDur>>
838 round(
const time_point<_Clock, _Dur>& __tp)
840 return time_point<_Clock, _ToDur>{
841 chrono::round<_ToDur>(__tp.time_since_epoch())};
848 template<
typename _Clock,
typename _Dur1,
849 typename _Rep2,
typename _Period2>
850 constexpr time_point<_Clock,
851 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
853 const duration<_Rep2, _Period2>& __rhs)
855 typedef duration<_Rep2, _Period2> __dur2;
858 return __time_point(__lhs.time_since_epoch() + __rhs);
862 template<
typename _Rep1,
typename _Period1,
863 typename _Clock,
typename _Dur2>
869 typedef duration<_Rep1, _Period1> __dur1;
872 return __time_point(__rhs.time_since_epoch() + __lhs);
876 template<
typename _Clock,
typename _Dur1,
877 typename _Rep2,
typename _Period2>
881 const duration<_Rep2, _Period2>& __rhs)
883 typedef duration<_Rep2, _Period2> __dur2;
886 return __time_point(__lhs.time_since_epoch() -__rhs);
894 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
898 {
return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
900 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
904 {
return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
906 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
908 operator!=(
const time_point<_Clock, _Dur1>& __lhs,
909 const time_point<_Clock, _Dur2>& __rhs)
910 {
return !(__lhs == __rhs); }
912 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
914 operator<(
const time_point<_Clock, _Dur1>& __lhs,
915 const time_point<_Clock, _Dur2>& __rhs)
916 {
return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
918 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
920 operator<=(
const time_point<_Clock, _Dur1>& __lhs,
921 const time_point<_Clock, _Dur2>& __rhs)
922 {
return !(__rhs < __lhs); }
924 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
926 operator>(
const time_point<_Clock, _Dur1>& __lhs,
927 const time_point<_Clock, _Dur2>& __rhs)
928 {
return __rhs < __lhs; }
930 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
932 operator>=(
const time_point<_Clock, _Dur1>& __lhs,
933 const time_point<_Clock, _Dur2>& __rhs)
934 {
return !(__lhs < __rhs); }
956 inline namespace _V2 {
967 typedef duration::rep rep;
968 typedef duration::period period;
971 static_assert(system_clock::duration::min()
972 < system_clock::duration::zero(),
973 "a clock's minimum duration cannot be less than its epoch");
975 static constexpr
bool is_steady =
false;
984 return std::time_t(duration_cast<chrono::seconds>
985 (__t.time_since_epoch()).count());
989 from_time_t(std::time_t __t) noexcept
992 return time_point_cast<system_clock::duration>
1007 typedef duration::rep rep;
1008 typedef duration::period period;
1011 static constexpr
bool is_steady =
true;
1030 #if __cplusplus > 201703L
1031 template<
typename _Duration>
1033 using sys_seconds = sys_time<seconds>;
1034 using sys_days = sys_time<days>;
1036 using file_clock = ::std::filesystem::__file_clock;
1038 template<
typename _Duration>
1042 template<>
struct is_clock<steady_clock> :
true_type { };
1043 template<>
struct is_clock<file_clock> :
true_type { };
1045 template<>
inline constexpr
bool is_clock_v<system_clock> =
true;
1046 template<>
inline constexpr
bool is_clock_v<steady_clock> =
true;
1047 template<>
inline constexpr
bool is_clock_v<file_clock> =
true;
1050 template<
typename _Duration>
1051 using local_time = time_point<local_t, _Duration>;
1052 using local_seconds = local_time<seconds>;
1053 using local_days = local_time<days>;
1059 #if __cplusplus > 201103L
1061 #define __cpp_lib_chrono_udls 201304
1063 inline namespace literals
1088 inline namespace chrono_literals
1090 #pragma GCC diagnostic push
1091 #pragma GCC diagnostic ignored "-Wliteral-suffix"
1093 template<
typename _Dur,
char... _Digits>
1094 constexpr _Dur __check_overflow()
1096 using _Val = __parse_int::_Parse_int<_Digits...>;
1097 constexpr
typename _Dur::rep __repval = _Val::value;
1098 static_assert(__repval >= 0 && __repval == _Val::value,
1099 "literal value cannot be represented by duration type");
1100 return _Dur(__repval);
1106 operator""h(
long double __hours)
1110 template <
char... _Digits>
1117 operator""min(
long double __mins)
1121 template <
char... _Digits>
1128 operator""s(
long double __secs)
1132 template <
char... _Digits>
1139 operator""ms(
long double __msecs)
1143 template <
char... _Digits>
1150 operator""us(
long double __usecs)
1154 template <
char... _Digits>
1161 operator""ns(
long double __nsecs)
1165 template <
char... _Digits>
1170 #pragma GCC diagnostic pop
1176 using namespace literals::chrono_literals;
1179 #if __cplusplus >= 201703L
1180 namespace filesystem
1185 using rep = duration::rep;
1186 using period = duration::period;
1187 using time_point = chrono::time_point<__file_clock>;
1188 static constexpr
bool is_steady =
false;
1192 {
return _S_from_sys(chrono::system_clock::now()); }
1194 #if __cplusplus > 201703L
1195 template<
typename _Dur>
1197 chrono::file_time<_Dur>
1198 from_sys(
const chrono::sys_time<_Dur>& __t) noexcept
1199 {
return _S_from_sys(__t); }
1202 template<
typename _Dur>
1204 chrono::sys_time<_Dur>
1205 to_sys(
const chrono::file_time<_Dur>& __t) noexcept
1206 {
return _S_to_sys(__t); }
1210 using __sys_clock = chrono::system_clock;
1219 template<
typename _Dur>
1221 chrono::time_point<__file_clock, _Dur>
1222 _S_from_sys(
const chrono::time_point<__sys_clock, _Dur>& __t) noexcept
1224 using __file_time = chrono::time_point<__file_clock, _Dur>;
1225 return __file_time{__t.time_since_epoch()} - _S_epoch_diff;
1229 template<
typename _Dur>
1231 chrono::time_point<__sys_clock, _Dur>
1232 _S_to_sys(
const chrono::time_point<__file_clock, _Dur>& __t) noexcept
1234 using __sys_time = chrono::time_point<__sys_clock, _Dur>;
1235 return __sys_time{__t.time_since_epoch()} + _S_epoch_diff;
1242 _GLIBCXX_END_NAMESPACE_VERSION
1247 #endif //_GLIBCXX_CHRONO