30#ifndef _GLIBCXX_CHRONO_H
31#define _GLIBCXX_CHRONO_H 1
34#pragma GCC system_header
37#if __cplusplus >= 201103L
46#if __cplusplus >= 202002L
53namespace std _GLIBCXX_VISIBILITY(default)
55_GLIBCXX_BEGIN_NAMESPACE_VERSION
57#if __cplusplus >= 201703L && _GLIBCXX_HOSTED
58 namespace filesystem {
struct __file_clock; };
67 template<
typename _Rep,
typename _Period = ratio<1>>
71 template<
typename _Clock,
typename _Dur =
typename _Clock::duration>
83 template<
typename _CT,
typename _Period1,
typename _Period2,
typename =
void>
84 struct __duration_common_type
87 template<
typename _CT,
typename _Period1,
typename _Period2>
88 struct __duration_common_type<_CT, _Period1, _Period2,
89 __void_t<typename _CT::type>>
92 using __gcd_num = __static_gcd<_Period1::num, _Period2::num>;
93 using __gcd_den = __static_gcd<_Period1::den, _Period2::den>;
94 using __cr =
typename _CT::type;
95 using __r = ratio<__gcd_num::value,
96 (_Period1::den / __gcd_den::value) * _Period2::den>;
99 using type = chrono::duration<__cr, typename __r::type>;
108 template<
typename _Rep1,
typename _Period1,
typename _Rep2,
typename _Period2>
111 : __duration_common_type<common_type<_Rep1, _Rep2>,
112 typename _Period1::type,
113 typename _Period2::type>
117 template<
typename _Rep,
typename _Period>
122 typename _Period::type>;
126 template<
typename _Rep,
typename _Period>
130 typename _Period::type>;
138 template<
typename _CT,
typename _Clock,
typename =
void>
139 struct __timepoint_common_type
142 template<
typename _CT,
typename _Clock>
143 struct __timepoint_common_type<_CT, _Clock, __void_t<typename _CT::type>>
145 using type = chrono::time_point<_Clock, typename _CT::type>;
154 template<
typename _Clock,
typename _Duration1,
typename _Duration2>
157 : __timepoint_common_type<common_type<_Duration1, _Duration2>, _Clock>
161 template<
typename _Clock,
typename _Duration>
167 template<
typename _Clock,
typename _Duration>
186 template<
typename _Rep,
typename _Period>
190 typedef typename _ToDur::rep
__to_rep;
192 *
static_cast<_CR>(_CF::num)
193 /
static_cast<_CR>(_CF::den)));
197 template<
typename _ToDur,
typename _CF,
typename _CR>
198 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
200 template<
typename _Rep,
typename _Period>
201 static constexpr _ToDur
202 __cast(
const duration<_Rep, _Period>& __d)
204 typedef typename _ToDur::rep __to_rep;
205 return _ToDur(
static_cast<__to_rep
>(__d.count()));
209 template<
typename _ToDur,
typename _CF,
typename _CR>
210 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
212 template<
typename _Rep,
typename _Period>
213 static constexpr _ToDur
214 __cast(
const duration<_Rep, _Period>& __d)
216 typedef typename _ToDur::rep __to_rep;
217 return _ToDur(
static_cast<__to_rep
>(
218 static_cast<_CR
>(__d.count()) /
static_cast<_CR
>(_CF::den)));
222 template<
typename _ToDur,
typename _CF,
typename _CR>
223 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
225 template<
typename _Rep,
typename _Period>
226 static constexpr _ToDur
227 __cast(
const duration<_Rep, _Period>& __d)
229 typedef typename _ToDur::rep __to_rep;
230 return _ToDur(
static_cast<__to_rep
>(
231 static_cast<_CR
>(__d.count()) *
static_cast<_CR
>(_CF::num)));
235 template<
typename _Tp>
240 template<
typename _Rep,
typename _Period>
241 struct __is_duration<duration<_Rep, _Period>>
245 template<
typename _Tp>
246 using __enable_if_is_duration
247 =
typename enable_if<__is_duration<_Tp>::value, _Tp>::type;
249 template<
typename _Tp>
250 using __disable_if_is_duration
251 =
typename enable_if<!__is_duration<_Tp>::value, _Tp>::type;
253#if __cplusplus >= 201703L
254 template<
typename _Tp>
255 inline constexpr bool __is_duration_v =
false;
256 template<
typename _Rep,
typename _Period>
257 inline constexpr bool __is_duration_v<duration<_Rep, _Period>> =
true;
258 template<
typename _Tp>
259 inline constexpr bool __is_time_point_v =
false;
260 template<
typename _Clock,
typename _Dur>
261 inline constexpr bool __is_time_point_v<time_point<_Clock, _Dur>> =
true;
276 template<
typename _ToDur,
typename _Rep,
typename _Period>
278 constexpr __enable_if_is_duration<_ToDur>
281#if __cpp_inline_variables && __cpp_if_constexpr
288 using __to_rep =
typename _ToDur::rep;
292 __cf::num == 1, __cf::den == 1>;
293 return __dc::__cast(__d);
294#if __cpp_inline_variables && __cpp_if_constexpr
310 template<
typename _Rep>
315#if __cplusplus > 201402L
316 template <
typename _Rep>
317 inline constexpr bool treat_as_floating_point_v =
334#if __cplusplus > 201703L
335#if __cpp_lib_concepts
336 template<
typename _Tp>
337 inline constexpr bool is_clock_v =
false;
339 template<
typename _Tp>
342 typename _Tp::period;
343 typename _Tp::duration;
344 typename _Tp::time_point::clock;
345 typename _Tp::time_point::duration;
347 { _Tp::now() } -> same_as<typename _Tp::time_point>;
348 requires same_as<
typename _Tp::duration,
349 duration<typename _Tp::rep, typename _Tp::period>>;
350 requires same_as<
typename _Tp::time_point::duration,
351 typename _Tp::duration>;
353 inline constexpr bool is_clock_v<_Tp> =
true;
355 template<
typename _Tp,
typename =
void>
356 inline constexpr bool is_clock_v =
false;
358 template<
typename _Tp>
359 inline constexpr bool
360 is_clock_v<_Tp,
void_t<
typename _Tp::rep,
typename _Tp::period,
361 typename _Tp::duration,
362 typename _Tp::time_point::duration,
363 decltype(_Tp::is_steady),
364 decltype(_Tp::now())>>
365 = __and_v<is_same<
typename _Tp::duration,
366 duration<typename _Tp::rep, typename _Tp::period>>,
367 is_same<
typename _Tp::time_point::duration,
368 typename _Tp::duration>,
369 is_same<
decltype(&_Tp::is_steady),
const bool*>,
370 is_same<
decltype(_Tp::now()),
typename _Tp::time_point>>;
373 template<
typename _Tp>
375 : bool_constant<is_clock_v<_Tp>>
379#if __cplusplus >= 201703L
390 template<
typename _ToDur,
typename _Rep,
typename _Period>
391 [[nodiscard]]
constexpr __enable_if_is_duration<_ToDur>
394 auto __to = chrono::duration_cast<_ToDur>(__d);
410 template<
typename _ToDur,
typename _Rep,
typename _Period>
414 auto __to = chrono::duration_cast<_ToDur>(__d);
431 template <
typename _ToDur,
typename _Rep,
typename _Period>
445 if (
__t0.count() & 1)
460 template<
typename _Rep,
typename _Period>
465 if (__d >= __d.zero())
480 template<
typename _Tp,
typename _Up>
482 __ceil_impl(
const _Tp& __t,
const _Up& __u)
484 return (__t < __u) ? (__t + _Tp{1}) : __t;
488 template<
typename _ToDur,
typename _Rep,
typename _Period>
490 ceil(
const duration<_Rep, _Period>& __d)
492 return __detail::__ceil_impl(chrono::duration_cast<_ToDur>(__d), __d);
498 template<
typename _Rep>
501 static constexpr _Rep
505 static constexpr _Rep
509 static constexpr _Rep
514 template<
typename _Rep,
typename _Period>
518 "rep cannot be a std::chrono::duration");
520 "period must be a specialization of std::ratio");
521 static_assert(_Period::num > 0,
"period must be positive");
523 template<
typename _Rep2>
531#if __cplusplus >= 201402L
543 return (__n == 0) ?
__m : _S_gcd(__n,
__m % __n);
551 template<
typename _R1,
typename _R2,
558 template<
typename _Period2>
565 using period =
typename _Period::type;
578 : __r(
static_cast<rep
>(__rep)) { }
643 operator*=(
const rep&
__rhs)
650 operator/=(
const rep&
__rhs)
657 template<
typename _Rep2 = rep>
660 operator%=(
const rep&
__rhs)
666 template<
typename _Rep2 = rep>
743 template<
typename _Rep1,
typename _Period,
typename _Rep2>
752 template<
typename _Rep1,
typename _Rep2,
typename _Period>
755 {
return __d *
__s; }
757 template<
typename _Rep1,
typename _Period,
typename _Rep2>
780 template<
typename _Rep1,
typename _Period,
typename _Rep2>
835#if __cpp_lib_three_way_comparison
856 template<
typename _Rep1,
typename _Period1,
857 typename _Rep2,
typename _Period2>
880#ifdef _GLIBCXX_USE_C99_STDINT
881# define _GLIBCXX_CHRONO_INT64_T int64_t
882#elif defined __INT64_TYPE__
883# define _GLIBCXX_CHRONO_INT64_T __INT64_TYPE__
886 "Representation type for nanoseconds must have at least 64 bits");
887# define _GLIBCXX_CHRONO_INT64_T long long
909#if __cplusplus > 201703L
923#undef _GLIBCXX_CHRONO_INT64_T
925 template<
typename _Clock,
typename _Dur>
929 "duration must be a specialization of std::chrono::duration");
933 typedef _Dur duration;
934 typedef typename duration::rep rep;
935 typedef typename duration::period period;
937 constexpr time_point() : __d(duration::zero())
945 template<
typename _Dur2,
948 : __d(__t.time_since_epoch())
953 time_since_epoch()
const
956#if __cplusplus > 201703L
982 operator+=(
const duration&
__dur)
989 operator-=(
const duration&
__dur)
1020 template<
typename _ToDur,
typename _Clock,
typename _Dur>
1021 _GLIBCXX_NODISCARD
constexpr
1029#if __cplusplus > 201402L
1042 template<
typename _ToDur,
typename _Clock,
typename _Dur>
1048 chrono::floor<_ToDur>(
__tp.time_since_epoch())};
1063 template<
typename _ToDur,
typename _Clock,
typename _Dur>
1069 chrono::ceil<_ToDur>(
__tp.time_since_epoch())};
1085 template<
typename _ToDur,
typename _Clock,
typename _Dur>
1093 chrono::round<_ToDur>(
__tp.time_since_epoch())};
1103 constexpr time_point<
_Clock,
1131 constexpr time_point<
_Clock,
1143 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1147 {
return __lhs.time_since_epoch() -
__rhs.time_since_epoch(); }
1155 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1159 {
return __lhs.time_since_epoch() ==
__rhs.time_since_epoch(); }
1161#if __cpp_lib_three_way_comparison
1162 template<
typename _Clock,
typename _Dur1,
1163 three_way_comparable_with<_Dur1> _Dur2>
1165 operator<=>(
const time_point<_Clock, _Dur1>& __lhs,
1166 const time_point<_Clock, _Dur2>& __rhs)
1167 {
return __lhs.time_since_epoch() <=> __rhs.time_since_epoch(); }
1169 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1171 operator!=(
const time_point<_Clock, _Dur1>& __lhs,
1172 const time_point<_Clock, _Dur2>& __rhs)
1173 {
return !(__lhs == __rhs); }
1176 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1178 operator<(
const time_point<_Clock, _Dur1>& __lhs,
1179 const time_point<_Clock, _Dur2>& __rhs)
1180 {
return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
1182 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1184 operator<=(
const time_point<_Clock, _Dur1>& __lhs,
1185 const time_point<_Clock, _Dur2>& __rhs)
1186 {
return !(__rhs < __lhs); }
1188 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1190 operator>(
const time_point<_Clock, _Dur1>& __lhs,
1191 const time_point<_Clock, _Dur2>& __rhs)
1192 {
return __rhs < __lhs; }
1194 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
1196 operator>=(
const time_point<_Clock, _Dur1>& __lhs,
1197 const time_point<_Clock, _Dur2>& __rhs)
1198 {
return !(__lhs < __rhs); }
1222_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
1233 typedef duration::rep rep;
1234 typedef duration::period period;
1237 static_assert(system_clock::duration::min()
1238 < system_clock::duration::zero(),
1239 "a clock's minimum duration cannot be less than its epoch");
1241 static constexpr bool is_steady =
false;
1247 [[__gnu__::__always_inline__]]
1252 (__t.time_since_epoch()).count());
1255 [[__gnu__::__always_inline__]]
1275 typedef duration::rep rep;
1276 typedef duration::period period;
1279 static constexpr bool is_steady =
true;
1296_GLIBCXX_END_INLINE_ABI_NAMESPACE(
_V2)
1298#if __cplusplus >= 202002L
1301 template<
typename _Duration>
1306 using file_clock = ::std::filesystem::__file_clock;
1308 template<
typename _Duration>
1312 template<>
struct is_clock<steady_clock> :
true_type { };
1313 template<>
struct is_clock<file_clock> :
true_type { };
1315 template<>
inline constexpr bool is_clock_v<system_clock> =
true;
1316 template<>
inline constexpr bool is_clock_v<steady_clock> =
true;
1317 template<>
inline constexpr bool is_clock_v<file_clock> =
true;
1320#elif __cplusplus >= 202002L
1324 template<
typename _Duration>
1325 using sys_time = time_point<__sys_t, _Duration>;
1326 using sys_seconds = sys_time<seconds>;
1327 using sys_days = sys_time<days>;
1331#ifdef __glibcxx_chrono_udls
1332 inline namespace literals
1358 inline namespace chrono_literals
1363#pragma GCC diagnostic push
1364#pragma GCC diagnostic ignored "-Wliteral-suffix"
1366 template<
typename _Dur,
char... _Digits>
1367 constexpr _Dur __check_overflow()
1369 using _Val = __parse_int::_Parse_int<_Digits...>;
1370 constexpr typename _Dur::rep __repval = _Val::value;
1371 static_assert(__repval >= 0 && __repval == _Val::value,
1372 "literal value cannot be represented by duration type");
1373 return _Dur(__repval);
1378 constexpr chrono::duration<long double, ratio<3600,1>>
1443#pragma GCC diagnostic pop
1450 using namespace literals::chrono_literals;
1454#if __cplusplus >= 201703L && _GLIBCXX_HOSTED
1455 namespace filesystem
1460 using rep = duration::rep;
1461 using period = duration::period;
1462 using time_point = chrono::time_point<__file_clock>;
1463 static constexpr bool is_steady =
false;
1467 {
return _S_from_sys(chrono::system_clock::now()); }
1469#if __cplusplus > 201703L
1470 template<
typename _Dur>
1472 chrono::file_time<common_type_t<_Dur, chrono::seconds>>
1473 from_sys(
const chrono::sys_time<_Dur>& __t)
noexcept
1474 {
return _S_from_sys(__t); }
1477 template<
typename _Dur>
1479 chrono::sys_time<common_type_t<_Dur, chrono::seconds>>
1480 to_sys(
const chrono::file_time<_Dur>& __t)
noexcept
1481 {
return _S_to_sys(__t); }
1485 using __sys_clock = chrono::system_clock;
1494 template<
typename _Dur>
1496 chrono::time_point<__file_clock, common_type_t<_Dur, chrono::seconds>>
1497 _S_from_sys(
const chrono::time_point<__sys_clock, _Dur>& __t)
noexcept
1499 using _CDur = common_type_t<_Dur, chrono::seconds>;
1500 using __file_time = chrono::time_point<__file_clock, _CDur>;
1501 return __file_time{__t.time_since_epoch()} - _S_epoch_diff;
1505 template<
typename _Dur>
1507 chrono::time_point<__sys_clock, common_type_t<_Dur, chrono::seconds>>
1508 _S_to_sys(
const chrono::time_point<__file_clock, _Dur>& __t)
noexcept
1510 using _CDur = common_type_t<_Dur, chrono::seconds>;
1511 using __sys_time = chrono::time_point<__sys_clock, _CDur>;
1512 return __sys_time{__t.time_since_epoch()} + _S_epoch_diff;
1518_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