30#ifndef _GLIBCXX_CHRONO_H
31#define _GLIBCXX_CHRONO_H 1
33#pragma GCC system_header
35#if __cplusplus >= 201103L
42#if __cplusplus >= 202002L
49namespace std _GLIBCXX_VISIBILITY(default)
51_GLIBCXX_BEGIN_NAMESPACE_VERSION
53#if __cplusplus >= 201703L
54 namespace filesystem {
struct __file_clock; };
63 template<
typename _Rep,
typename _Period = ratio<1>>
67 template<
typename _Clock,
typename _Dur =
typename _Clock::duration>
79 template<
typename _CT,
typename _Period1,
typename _Period2,
typename =
void>
80 struct __duration_common_type
83 template<
typename _CT,
typename _Period1,
typename _Period2>
84 struct __duration_common_type<_CT, _Period1, _Period2,
85 __void_t<typename _CT::type>>
88 using __gcd_num = __static_gcd<_Period1::num, _Period2::num>;
89 using __gcd_den = __static_gcd<_Period1::den, _Period2::den>;
90 using __cr =
typename _CT::type;
91 using __r = ratio<__gcd_num::value,
92 (_Period1::den / __gcd_den::value) * _Period2::den>;
95 using type = chrono::duration<__cr, typename __r::type>;
104 template<
typename _Rep1,
typename _Period1,
typename _Rep2,
typename _Period2>
107 : __duration_common_type<common_type<_Rep1, _Rep2>,
108 typename _Period1::type,
109 typename _Period2::type>
113 template<
typename _Rep,
typename _Period>
118 typename _Period::type>;
122 template<
typename _Rep,
typename _Period>
126 typename _Period::type>;
134 template<
typename _CT,
typename _Clock,
typename =
void>
135 struct __timepoint_common_type
138 template<
typename _CT,
typename _Clock>
139 struct __timepoint_common_type<_CT, _Clock, __void_t<typename _CT::type>>
141 using type = chrono::time_point<_Clock, typename _CT::type>;
150 template<
typename _Clock,
typename _Duration1,
typename _Duration2>
153 : __timepoint_common_type<common_type<_Duration1, _Duration2>, _Clock>
157 template<
typename _Clock,
typename _Duration>
163 template<
typename _Clock,
typename _Duration>
182 template<
typename _Rep,
typename _Period>
186 typedef typename _ToDur::rep
__to_rep;
188 *
static_cast<_CR>(_CF::num)
189 /
static_cast<_CR>(_CF::den)));
193 template<
typename _ToDur,
typename _CF,
typename _CR>
194 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
196 template<
typename _Rep,
typename _Period>
197 static constexpr _ToDur
198 __cast(
const duration<_Rep, _Period>& __d)
200 typedef typename _ToDur::rep __to_rep;
201 return _ToDur(
static_cast<__to_rep
>(__d.count()));
205 template<
typename _ToDur,
typename _CF,
typename _CR>
206 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
208 template<
typename _Rep,
typename _Period>
209 static constexpr _ToDur
210 __cast(
const duration<_Rep, _Period>& __d)
212 typedef typename _ToDur::rep __to_rep;
213 return _ToDur(
static_cast<__to_rep
>(
214 static_cast<_CR
>(__d.count()) /
static_cast<_CR
>(_CF::den)));
218 template<
typename _ToDur,
typename _CF,
typename _CR>
219 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
221 template<
typename _Rep,
typename _Period>
222 static constexpr _ToDur
223 __cast(
const duration<_Rep, _Period>& __d)
225 typedef typename _ToDur::rep __to_rep;
226 return _ToDur(
static_cast<__to_rep
>(
227 static_cast<_CR
>(__d.count()) *
static_cast<_CR
>(_CF::num)));
231 template<
typename _Tp>
236 template<
typename _Rep,
typename _Period>
237 struct __is_duration<duration<_Rep, _Period>>
241 template<
typename _Tp>
242 using __enable_if_is_duration
243 =
typename enable_if<__is_duration<_Tp>::value, _Tp>::type;
245 template<
typename _Tp>
246 using __disable_if_is_duration
247 =
typename enable_if<!__is_duration<_Tp>::value, _Tp>::type;
249#if __cplusplus >= 201703L
250 template<
typename _Tp>
251 inline constexpr bool __is_duration_v =
false;
252 template<
typename _Rep,
typename _Period>
253 inline constexpr bool __is_duration_v<duration<_Rep, _Period>> =
true;
254 template<
typename _Tp>
255 inline constexpr bool __is_time_point_v =
false;
256 template<
typename _Clock,
typename _Dur>
257 inline constexpr bool __is_time_point_v<time_point<_Clock, _Dur>> =
true;
272 template<
typename _ToDur,
typename _Rep,
typename _Period>
274 constexpr __enable_if_is_duration<_ToDur>
277#if __cpp_inline_variables && __cpp_if_constexpr
284 using __to_rep =
typename _ToDur::rep;
288 __cf::num == 1, __cf::den == 1>;
289 return __dc::__cast(__d);
290#if __cpp_inline_variables && __cpp_if_constexpr
306 template<
typename _Rep>
311#if __cplusplus > 201402L
312 template <
typename _Rep>
313 inline constexpr bool treat_as_floating_point_v =
330#if __cplusplus > 201703L
331#if __cpp_lib_concepts
332 template<
typename _Tp>
333 inline constexpr bool is_clock_v =
false;
335 template<
typename _Tp>
338 typename _Tp::period;
339 typename _Tp::duration;
340 typename _Tp::time_point::clock;
341 typename _Tp::time_point::duration;
343 { _Tp::now() } -> same_as<typename _Tp::time_point>;
344 requires same_as<
typename _Tp::duration,
345 duration<typename _Tp::rep, typename _Tp::period>>;
346 requires same_as<
typename _Tp::time_point::duration,
347 typename _Tp::duration>;
349 inline constexpr bool is_clock_v<_Tp> =
true;
351 template<
typename _Tp,
typename =
void>
352 inline constexpr bool is_clock_v =
false;
354 template<
typename _Tp>
355 inline constexpr bool
356 is_clock_v<_Tp,
void_t<
typename _Tp::rep,
typename _Tp::period,
357 typename _Tp::duration,
358 typename _Tp::time_point::duration,
359 decltype(_Tp::is_steady),
360 decltype(_Tp::now())>>
361 = __and_v<is_same<
typename _Tp::duration,
362 duration<typename _Tp::rep, typename _Tp::period>>,
363 is_same<
typename _Tp::time_point::duration,
364 typename _Tp::duration>,
365 is_same<
decltype(&_Tp::is_steady),
const bool*>,
366 is_same<
decltype(_Tp::now()),
typename _Tp::time_point>>;
369 template<
typename _Tp>
371 : bool_constant<is_clock_v<_Tp>>
375#ifdef __glibcxx_chrono
386 template<
typename _ToDur,
typename _Rep,
typename _Period>
387 [[nodiscard]]
constexpr __enable_if_is_duration<_ToDur>
390 auto __to = chrono::duration_cast<_ToDur>(__d);
406 template<
typename _ToDur,
typename _Rep,
typename _Period>
410 auto __to = chrono::duration_cast<_ToDur>(__d);
427 template <
typename _ToDur,
typename _Rep,
typename _Period>
441 if (
__t0.count() & 1)
456 template<
typename _Rep,
typename _Period>
461 if (__d >= __d.zero())
476 template<
typename _Tp,
typename _Up>
478 __ceil_impl(
const _Tp& __t,
const _Up& __u)
480 return (__t < __u) ? (__t + _Tp{1}) : __t;
484 template<
typename _ToDur,
typename _Rep,
typename _Period>
486 ceil(
const duration<_Rep, _Period>& __d)
488 return __detail::__ceil_impl(chrono::duration_cast<_ToDur>(__d), __d);
494 template<
typename _Rep>
497 static constexpr _Rep
501 static constexpr _Rep
505 static constexpr _Rep
510 template<
typename _Rep,
typename _Period>
514 "rep cannot be a std::chrono::duration");
516 "period must be a specialization of std::ratio");
517 static_assert(_Period::num > 0,
"period must be positive");
519 template<
typename _Rep2>
527#if __cplusplus >= 201402L
539 return (__n == 0) ?
__m : _S_gcd(__n,
__m % __n);
547 template<
typename _R1,
typename _R2,
554 template<
typename _Period2>
561 using period =
typename _Period::type;
574 : __r(
static_cast<rep
>(__rep)) { }
639 operator*=(
const rep&
__rhs)
646 operator/=(
const rep&
__rhs)
653 template<
typename _Rep2 = rep>
656 operator%=(
const rep&
__rhs)
662 template<
typename _Rep2 = rep>
739 template<
typename _Rep1,
typename _Period,
typename _Rep2>
748 template<
typename _Rep1,
typename _Rep2,
typename _Period>
751 {
return __d *
__s; }
753 template<
typename _Rep1,
typename _Period,
typename _Rep2>
776 template<
typename _Rep1,
typename _Period,
typename _Rep2>
831#if __cpp_lib_three_way_comparison
852 template<
typename _Rep1,
typename _Period1,
853 typename _Rep2,
typename _Period2>
876#ifdef _GLIBCXX_USE_C99_STDINT
877# define _GLIBCXX_CHRONO_INT64_T int64_t
878#elif defined __INT64_TYPE__
879# define _GLIBCXX_CHRONO_INT64_T __INT64_TYPE__
882 "Representation type for nanoseconds must have at least 64 bits");
883# define _GLIBCXX_CHRONO_INT64_T long long
905#if __cplusplus > 201703L
919#undef _GLIBCXX_CHRONO_INT64_T
921 template<
typename _Clock,
typename _Dur>
925 "duration must be a specialization of std::chrono::duration");
929 typedef _Dur duration;
930 typedef typename duration::rep rep;
931 typedef typename duration::period period;
933 constexpr time_point() : __d(duration::zero())
941 template<
typename _Dur2,
944 : __d(__t.time_since_epoch())
949 time_since_epoch()
const
952#if __cplusplus > 201703L
978 operator+=(
const duration&
__dur)
985 operator-=(
const duration&
__dur)
1016 template<
typename _ToDur,
typename _Clock,
typename _Dur>
1017 _GLIBCXX_NODISCARD
constexpr
1025#if __cplusplus > 201402L
1038 template<
typename _ToDur,
typename _Clock,
typename _Dur>
1044 chrono::floor<_ToDur>(
__tp.time_since_epoch())};
1059 template<
typename _ToDur,
typename _Clock,
typename _Dur>
1065 chrono::ceil<_ToDur>(
__tp.time_since_epoch())};
1081 template<
typename _ToDur,
typename _Clock,
typename _Dur>
1089 chrono::round<_ToDur>(
__tp.time_since_epoch())};
1099 constexpr time_point<
_Clock,
1127 constexpr time_point<
_Clock,
1139 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1143 {
return __lhs.time_since_epoch() -
__rhs.time_since_epoch(); }
1151 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1155 {
return __lhs.time_since_epoch() ==
__rhs.time_since_epoch(); }
1157#if __cpp_lib_three_way_comparison
1158 template<
typename _Clock,
typename _Dur1,
1159 three_way_comparable_with<_Dur1> _Dur2>
1161 operator<=>(
const time_point<_Clock, _Dur1>& __lhs,
1162 const time_point<_Clock, _Dur2>& __rhs)
1163 {
return __lhs.time_since_epoch() <=> __rhs.time_since_epoch(); }
1165 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1167 operator!=(
const time_point<_Clock, _Dur1>& __lhs,
1168 const time_point<_Clock, _Dur2>& __rhs)
1169 {
return !(__lhs == __rhs); }
1172 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1174 operator<(
const time_point<_Clock, _Dur1>& __lhs,
1175 const time_point<_Clock, _Dur2>& __rhs)
1176 {
return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
1178 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1180 operator<=(
const time_point<_Clock, _Dur1>& __lhs,
1181 const time_point<_Clock, _Dur2>& __rhs)
1182 {
return !(__rhs < __lhs); }
1184 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1186 operator>(
const time_point<_Clock, _Dur1>& __lhs,
1187 const time_point<_Clock, _Dur2>& __rhs)
1188 {
return __rhs < __lhs; }
1190 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1192 operator>=(
const time_point<_Clock, _Dur1>& __lhs,
1193 const time_point<_Clock, _Dur2>& __rhs)
1194 {
return !(__lhs < __rhs); }
1217_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
1228 typedef duration::rep rep;
1229 typedef duration::period period;
1232 static_assert(system_clock::duration::min()
1233 < system_clock::duration::zero(),
1234 "a clock's minimum duration cannot be less than its epoch");
1236 static constexpr bool is_steady =
false;
1242 [[__gnu__::__always_inline__]]
1247 (__t.time_since_epoch()).count());
1250 [[__gnu__::__always_inline__]]
1270 typedef duration::rep rep;
1271 typedef duration::period period;
1274 static constexpr bool is_steady =
true;
1291_GLIBCXX_END_INLINE_ABI_NAMESPACE(
_V2)
1293#if __cplusplus >= 202002L
1296 template<
typename _Duration>
1301 using file_clock = ::std::filesystem::__file_clock;
1303 template<
typename _Duration>
1307 template<>
struct is_clock<steady_clock> :
true_type { };
1308 template<>
struct is_clock<file_clock> :
true_type { };
1310 template<>
inline constexpr bool is_clock_v<system_clock> =
true;
1311 template<>
inline constexpr bool is_clock_v<steady_clock> =
true;
1312 template<>
inline constexpr bool is_clock_v<file_clock> =
true;
1317#ifdef __glibcxx_chrono_udls
1318 inline namespace literals
1344 inline namespace chrono_literals
1349#pragma GCC diagnostic push
1350#pragma GCC diagnostic ignored "-Wliteral-suffix"
1352 template<
typename _Dur,
char... _Digits>
1353 constexpr _Dur __check_overflow()
1355 using _Val = __parse_int::_Parse_int<_Digits...>;
1356 constexpr typename _Dur::rep __repval = _Val::value;
1357 static_assert(__repval >= 0 && __repval == _Val::value,
1358 "literal value cannot be represented by duration type");
1359 return _Dur(__repval);
1364 constexpr chrono::duration<long double, ratio<3600,1>>
1429#pragma GCC diagnostic pop
1436 using namespace literals::chrono_literals;
1440#if __cplusplus >= 201703L
1441 namespace filesystem
1446 using rep = duration::rep;
1447 using period = duration::period;
1448 using time_point = chrono::time_point<__file_clock>;
1449 static constexpr bool is_steady =
false;
1453 {
return _S_from_sys(chrono::system_clock::now()); }
1455#if __cplusplus > 201703L
1456 template<
typename _Dur>
1458 chrono::file_time<common_type_t<_Dur, chrono::seconds>>
1459 from_sys(
const chrono::sys_time<_Dur>& __t)
noexcept
1460 {
return _S_from_sys(__t); }
1463 template<
typename _Dur>
1465 chrono::sys_time<common_type_t<_Dur, chrono::seconds>>
1466 to_sys(
const chrono::file_time<_Dur>& __t)
noexcept
1467 {
return _S_to_sys(__t); }
1471 using __sys_clock = chrono::system_clock;
1480 template<
typename _Dur>
1482 chrono::time_point<__file_clock, common_type_t<_Dur, chrono::seconds>>
1483 _S_from_sys(
const chrono::time_point<__sys_clock, _Dur>& __t)
noexcept
1485 using _CDur = common_type_t<_Dur, chrono::seconds>;
1486 using __file_time = chrono::time_point<__file_clock, _CDur>;
1487 return __file_time{__t.time_since_epoch()} - _S_epoch_diff;
1491 template<
typename _Dur>
1493 chrono::time_point<__sys_clock, common_type_t<_Dur, chrono::seconds>>
1494 _S_to_sys(
const chrono::time_point<__file_clock, _Dur>& __t)
noexcept
1496 using _CDur = common_type_t<_Dur, chrono::seconds>;
1497 using __sys_time = chrono::time_point<__sys_clock, _CDur>;
1498 return __sys_time{__t.time_since_epoch()} + _S_epoch_diff;
1504_GLIBCXX_END_NAMESPACE_VERSION
constexpr bool operator==(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
duration< int64_t > seconds
seconds
constexpr enable_if_t< __and_< __is_duration< _ToDur >, __not_< treat_as_floating_point< typename _ToDur::rep > > >::value, _ToDur > round(const duration< _Rep, _Period > &__d)
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
duration< int64_t, ratio< 3600 > > hours
hours
duration< int64_t, milli > milliseconds
milliseconds
duration< int64_t, micro > microseconds
microseconds
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr duration< __common_rep_t< _Rep2, _Rep1 >, _Period > operator*(const _Rep1 &__s, const duration< _Rep2, _Period > &__d)
duration< int64_t, nano > nanoseconds
nanoseconds
constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator%(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
constexpr time_point< _Clock, typename common_type< _Dur1, duration< _Rep2, _Period2 > >::type > operator+(const time_point< _Clock, _Dur1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr __enable_if_t< __is_duration< _ToDur >::value, time_point< _Clock, _ToDur > > time_point_cast(const time_point< _Clock, _Dur > &__t)
duration< int64_t, ratio< 60 > > minutes
minutes
constexpr time_point< _Clock, typename common_type< duration< _Rep1, _Period1 >, _Dur2 >::type > operator+(const duration< _Rep1, _Period1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs)
Adjust a time point forwards by the given duration.
constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator+(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator-(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
The difference between two durations.
constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator/(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
constexpr duration< __common_rep_t< _Rep1, _Rep2 >, _Period > operator*(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
constexpr __enable_if_is_duration< _ToDur > ceil(const duration< _Rep, _Period > &__d)
constexpr auto operator<=>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr __enable_if_is_duration< _ToDur > duration_cast(const duration< _Rep, _Period > &__d)
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
void void_t
A metafunction that always yields void, used for detecting valid types.
ISO C++ entities toplevel namespace is std.
Properties of fundamental types.
static constexpr _Tp max() noexcept
static constexpr _Tp lowest() noexcept
Provides compile-time rational arithmetic.
chrono::duration represents a distance between two points in time
chrono::time_point represents a point in time as measured by a clock