1 // chrono::duration and chrono::time_point -*- C++ -*-
3 // Copyright (C) 2008-2024 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file include/bits/chrono.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{chrono}
30 #ifndef _GLIBCXX_CHRONO_H
31 #define _GLIBCXX_CHRONO_H 1
33 #pragma GCC system_header
35 #if __cplusplus >= 201103L
38 #include <type_traits>
43 #include <bits/parse_numbers.h> // for literals support.
44 #if __cplusplus >= 202002L
49 #include <bits/version.h>
51 namespace std
_GLIBCXX_VISIBILITY(default)
53 _GLIBCXX_BEGIN_NAMESPACE_VERSION
55 #if __cplusplus >= 201703L && _GLIBCXX_HOSTED
56 namespace filesystem
{ struct __file_clock
; };
61 /// @addtogroup chrono
64 /// `chrono::duration` represents a distance between two points in time
65 template<typename _Rep
, typename _Period
= ratio
<1>>
68 /// `chrono::time_point` represents a point in time as measured by a clock
69 template<typename _Clock
, typename _Dur
= typename
_Clock::duration
>
74 /// @addtogroup chrono
77 // 20.11.4.3 specialization of common_type (for duration, sfinae-friendly)
79 /// @cond undocumented
81 template<typename _CT
, typename _Period1
, typename _Period2
, typename
= void>
82 struct __duration_common_type
85 template<typename _CT
, typename _Period1
, typename _Period2
>
86 struct __duration_common_type
<_CT
, _Period1
, _Period2
,
87 __void_t
<typename
_CT::type
>>
90 using __gcd_num
= __static_gcd
<_Period1::num
, _Period2::num
>;
91 using __gcd_den
= __static_gcd
<_Period1::den
, _Period2::den
>;
92 using __cr
= typename
_CT::type
;
93 using __r
= ratio
<__gcd_num::value
,
94 (_Period1::den
/ __gcd_den::value
) * _Period2::den
>;
97 using type
= chrono::duration
<__cr
, typename
__r::type
>;
103 /// @relates chrono::duration
105 /// Specialization of common_type for chrono::duration types.
106 template<typename _Rep1
, typename _Period1
, typename _Rep2
, typename _Period2
>
107 struct common_type
<chrono::duration
<_Rep1
, _Period1
>,
108 chrono::duration
<_Rep2
, _Period2
>>
109 : __duration_common_type
<common_type
<_Rep1
, _Rep2
>,
110 typename
_Period1::type
,
111 typename
_Period2::type
>
114 /// Specialization of common_type for two identical chrono::duration types.
115 template<typename _Rep
, typename _Period
>
116 struct common_type
<chrono::duration
<_Rep
, _Period
>,
117 chrono::duration
<_Rep
, _Period
>>
119 using type
= chrono::duration
<typename common_type
<_Rep
>::type
,
120 typename
_Period::type
>;
123 /// Specialization of common_type for one chrono::duration type.
124 template<typename _Rep
, typename _Period
>
125 struct common_type
<chrono::duration
<_Rep
, _Period
>>
127 using type
= chrono::duration
<typename common_type
<_Rep
>::type
,
128 typename
_Period::type
>;
132 // 20.11.4.3 specialization of common_type (for time_point, sfinae-friendly)
134 /// @cond undocumented
136 template<typename _CT
, typename _Clock
, typename
= void>
137 struct __timepoint_common_type
140 template<typename _CT
, typename _Clock
>
141 struct __timepoint_common_type
<_CT
, _Clock
, __void_t
<typename
_CT::type
>>
143 using type
= chrono::time_point
<_Clock
, typename
_CT::type
>;
149 /// @relates chrono::time_point
151 /// Specialization of common_type for chrono::time_point types.
152 template<typename _Clock
, typename _Duration1
, typename _Duration2
>
153 struct common_type
<chrono::time_point
<_Clock
, _Duration1
>,
154 chrono::time_point
<_Clock
, _Duration2
>>
155 : __timepoint_common_type
<common_type
<_Duration1
, _Duration2
>, _Clock
>
158 /// Specialization of common_type for two identical chrono::time_point types.
159 template<typename _Clock
, typename _Duration
>
160 struct common_type
<chrono::time_point
<_Clock
, _Duration
>,
161 chrono::time_point
<_Clock
, _Duration
>>
162 { using type
= chrono::time_point
<_Clock
, _Duration
>; };
164 /// Specialization of common_type for one chrono::time_point type.
165 template<typename _Clock
, typename _Duration
>
166 struct common_type
<chrono::time_point
<_Clock
, _Duration
>>
167 { using type
= chrono::time_point
<_Clock
, _Duration
>; };
174 /// @addtogroup chrono
177 /// @cond undocumented
179 // Primary template for duration_cast impl.
180 template<typename _ToDur
, typename _CF
, typename _CR
,
181 bool _NumIsOne
= false, bool _DenIsOne
= false>
182 struct __duration_cast_impl
184 template<typename _Rep
, typename _Period
>
185 static constexpr _ToDur
186 __cast(const duration
<_Rep
, _Period
>& __d
)
188 typedef typename
_ToDur::rep __to_rep
;
189 return _ToDur(static_cast<__to_rep
>(static_cast<_CR
>(__d
.count())
190 * static_cast<_CR
>(_CF::num
)
191 / static_cast<_CR
>(_CF::den
)));
195 template<typename _ToDur
, typename _CF
, typename _CR
>
196 struct __duration_cast_impl
<_ToDur
, _CF
, _CR
, true, true>
198 template<typename _Rep
, typename _Period
>
199 static constexpr _ToDur
200 __cast(const duration
<_Rep
, _Period
>& __d
)
202 typedef typename
_ToDur::rep __to_rep
;
203 return _ToDur(static_cast<__to_rep
>(__d
.count()));
207 template<typename _ToDur
, typename _CF
, typename _CR
>
208 struct __duration_cast_impl
<_ToDur
, _CF
, _CR
, true, false>
210 template<typename _Rep
, typename _Period
>
211 static constexpr _ToDur
212 __cast(const duration
<_Rep
, _Period
>& __d
)
214 typedef typename
_ToDur::rep __to_rep
;
215 return _ToDur(static_cast<__to_rep
>(
216 static_cast<_CR
>(__d
.count()) / static_cast<_CR
>(_CF::den
)));
220 template<typename _ToDur
, typename _CF
, typename _CR
>
221 struct __duration_cast_impl
<_ToDur
, _CF
, _CR
, false, true>
223 template<typename _Rep
, typename _Period
>
224 static constexpr _ToDur
225 __cast(const duration
<_Rep
, _Period
>& __d
)
227 typedef typename
_ToDur::rep __to_rep
;
228 return _ToDur(static_cast<__to_rep
>(
229 static_cast<_CR
>(__d
.count()) * static_cast<_CR
>(_CF::num
)));
233 template<typename _Tp
>
238 template<typename _Rep
, typename _Period
>
239 struct __is_duration
<duration
<_Rep
, _Period
>>
243 template<typename _Tp
>
244 using __enable_if_is_duration
245 = typename enable_if
<__is_duration
<_Tp
>::value
, _Tp
>::type
;
247 template<typename _Tp
>
248 using __disable_if_is_duration
249 = typename enable_if
<!__is_duration
<_Tp
>::value
, _Tp
>::type
;
251 #if __cplusplus >= 201703L
252 template<typename _Tp
>
253 inline constexpr bool __is_duration_v
= false;
254 template<typename _Rep
, typename _Period
>
255 inline constexpr bool __is_duration_v
<duration
<_Rep
, _Period
>> = true;
256 template<typename _Tp
>
257 inline constexpr bool __is_time_point_v
= false;
258 template<typename _Clock
, typename _Dur
>
259 inline constexpr bool __is_time_point_v
<time_point
<_Clock
, _Dur
>> = true;
264 /** Convert a `duration` to type `ToDur`.
266 * If the duration cannot be represented accurately in the result type,
267 * returns the result of integer truncation (i.e., rounded towards zero).
269 * @tparam _ToDur The result type must be a `duration`.
270 * @param __d A duration.
271 * @return The value of `__d` converted to type `_ToDur`.
274 template<typename _ToDur
, typename _Rep
, typename _Period
>
276 constexpr __enable_if_is_duration
<_ToDur
>
277 duration_cast(const duration
<_Rep
, _Period
>& __d
)
279 #if __cpp_inline_variables && __cpp_if_constexpr
280 if constexpr (is_same_v
<_ToDur
, duration
<_Rep
, _Period
>>)
285 using __to_period
= typename
_ToDur::period
;
286 using __to_rep
= typename
_ToDur::rep
;
287 using __cf
= ratio_divide
<_Period
, __to_period
>;
288 using __cr
= typename common_type
<__to_rep
, _Rep
, intmax_t>::type
;
289 using __dc
= __duration_cast_impl
<_ToDur
, __cf
, __cr
,
290 __cf::num
== 1, __cf::den
== 1>;
291 return __dc::__cast(__d
);
292 #if __cpp_inline_variables && __cpp_if_constexpr
297 /** Trait indicating whether to treat a type as a floating-point type.
299 * The chrono library uses this trait to tell whether a `duration` can
300 * represent fractional values of the given precision, or only integral
303 * You should specialize this trait for your own numeric types that are
304 * used with `duration` and can represent non-integral values.
308 template<typename _Rep
>
309 struct treat_as_floating_point
310 : is_floating_point
<_Rep
>
313 #if __cplusplus > 201402L
314 template <typename _Rep
>
315 inline constexpr bool treat_as_floating_point_v
=
316 treat_as_floating_point
<_Rep
>::value
;
319 inline constexpr bool treat_as_floating_point_v
<int> = false;
321 inline constexpr bool treat_as_floating_point_v
<long> = false;
323 inline constexpr bool treat_as_floating_point_v
<long long> = false;
325 inline constexpr bool treat_as_floating_point_v
<float> = true;
327 inline constexpr bool treat_as_floating_point_v
<double> = true;
329 inline constexpr bool treat_as_floating_point_v
<long double> = true;
332 #if __cplusplus > 201703L
333 #if __cpp_lib_concepts
334 template<typename _Tp
>
335 inline constexpr bool is_clock_v
= false;
337 template<typename _Tp
>
340 typename
_Tp::period
;
341 typename
_Tp::duration
;
342 typename
_Tp::time_point::clock
;
343 typename
_Tp::time_point::duration
;
344 { &_Tp::is_steady
} -> same_as
<const bool*>;
345 { _Tp::now() } -> same_as
<typename
_Tp::time_point
>;
346 requires same_as
<typename
_Tp::duration
,
347 duration
<typename
_Tp::rep
, typename
_Tp::period
>>;
348 requires same_as
<typename
_Tp::time_point::duration
,
349 typename
_Tp::duration
>;
351 inline constexpr bool is_clock_v
<_Tp
> = true;
353 template<typename _Tp
, typename
= void>
354 inline constexpr bool is_clock_v
= false;
356 template<typename _Tp
>
357 inline constexpr bool
358 is_clock_v
<_Tp
, void_t
<typename
_Tp::rep
, typename
_Tp::period
,
359 typename
_Tp::duration
,
360 typename
_Tp::time_point::duration
,
361 decltype(_Tp::is_steady
),
362 decltype(_Tp::now())>>
363 = __and_v
<is_same
<typename
_Tp::duration
,
364 duration
<typename
_Tp::rep
, typename
_Tp::period
>>,
365 is_same
<typename
_Tp::time_point::duration
,
366 typename
_Tp::duration
>,
367 is_same
<decltype(&_Tp::is_steady
), const bool*>,
368 is_same
<decltype(_Tp::now()), typename
_Tp::time_point
>>;
371 template<typename _Tp
>
373 : bool_constant
<is_clock_v
<_Tp
>>
377 #if __cplusplus >= 201703L // C++ >= 17
378 /** Convert a `duration` to type `ToDur` and round down.
380 * If the duration cannot be represented exactly in the result type,
381 * returns the closest value that is less than the argument.
383 * @tparam _ToDur The result type must be a `duration`.
384 * @param __d A duration.
385 * @return The value of `__d` converted to type `_ToDur`.
388 template<typename _ToDur
, typename _Rep
, typename _Period
>
389 [[nodiscard
]] constexpr __enable_if_is_duration
<_ToDur
>
390 floor(const duration
<_Rep
, _Period
>& __d
)
392 auto __to
= chrono::duration_cast
<_ToDur
>(__d
);
394 return __to
- _ToDur
{1};
398 /** Convert a `duration` to type `ToDur` and round up.
400 * If the duration cannot be represented exactly in the result type,
401 * returns the closest value that is greater than the argument.
403 * @tparam _ToDur The result type must be a `duration`.
404 * @param __d A duration.
405 * @return The value of `__d` converted to type `_ToDur`.
408 template<typename _ToDur
, typename _Rep
, typename _Period
>
409 [[nodiscard
]] constexpr __enable_if_is_duration
<_ToDur
>
410 ceil(const duration
<_Rep
, _Period
>& __d
)
412 auto __to
= chrono::duration_cast
<_ToDur
>(__d
);
414 return __to
+ _ToDur
{1};
418 /** Convert a `duration` to type `ToDur` and round to the closest value.
420 * If the duration cannot be represented exactly in the result type,
421 * returns the closest value, rounding ties to even.
423 * @tparam _ToDur The result type must be a `duration` with a
424 * non-floating-point `rep` type.
425 * @param __d A duration.
426 * @return The value of `__d` converted to type `_ToDur`.
429 template <typename _ToDur
, typename _Rep
, typename _Period
>
430 [[nodiscard
]] constexpr
432 __and_
<__is_duration
<_ToDur
>,
433 __not_
<treat_as_floating_point
<typename
_ToDur::rep
>>>::value
,
435 round(const duration
<_Rep
, _Period
>& __d
)
437 _ToDur __t0
= chrono::floor
<_ToDur
>(__d
);
438 _ToDur __t1
= __t0
+ _ToDur
{1};
439 auto __diff0
= __d
- __t0
;
440 auto __diff1
= __t1
- __d
;
441 if (__diff0
== __diff1
)
443 if (__t0
.count() & 1)
447 else if (__diff0
< __diff1
)
452 /** The absolute (non-negative) value of a duration.
454 * @param __d A duration with a signed `rep` type.
455 * @return A duration of the same type as the argument, with value |d|.
458 template<typename _Rep
, typename _Period
>
459 [[nodiscard
]] constexpr
460 enable_if_t
<numeric_limits
<_Rep
>::is_signed
, duration
<_Rep
, _Period
>>
461 abs(duration
<_Rep
, _Period
> __d
)
463 if (__d
>= __d
.zero())
468 // Make chrono::ceil<D> also usable as chrono::__detail::ceil<D>.
469 namespace __detail
{ using chrono::ceil
; }
471 #else // ! __glibcxx_chrono
473 // We want to use ceil even when compiling for earlier standards versions.
474 // C++11 only allows a single statement in a constexpr function, so we
475 // need to move the comparison into a separate function, __ceil_impl.
478 template<typename _Tp
, typename _Up
>
480 __ceil_impl(const _Tp
& __t
, const _Up
& __u
)
482 return (__t
< __u
) ? (__t
+ _Tp
{1}) : __t
;
485 // C++11-friendly version of std::chrono::ceil<D> for internal use.
486 template<typename _ToDur
, typename _Rep
, typename _Period
>
488 ceil(const duration
<_Rep
, _Period
>& __d
)
490 return __detail::__ceil_impl(chrono::duration_cast
<_ToDur
>(__d
), __d
);
493 #endif // __glibcxx_chrono
496 template<typename _Rep
>
497 struct duration_values
499 static constexpr _Rep
503 static constexpr _Rep
505 { return numeric_limits
<_Rep
>::max(); }
507 static constexpr _Rep
509 { return numeric_limits
<_Rep
>::lowest(); }
512 template<typename _Rep
, typename _Period
>
515 static_assert(!__is_duration
<_Rep
>::value
,
516 "rep cannot be a std::chrono::duration");
517 static_assert(__is_ratio
<_Period
>::value
,
518 "period must be a specialization of std::ratio");
519 static_assert(_Period::num
> 0, "period must be positive");
521 template<typename _Rep2
>
522 using __is_float
= treat_as_floating_point
<_Rep2
>;
524 static constexpr intmax_t
525 _S_gcd(intmax_t __m
, intmax_t __n
) noexcept
527 // Duration only allows positive periods so we don't need to
528 // handle negative values here (unlike __static_gcd and std::gcd).
529 #if __cplusplus >= 201402L
532 intmax_t __rem
= __m
% __n
;
539 // C++11 doesn't allow loops in constexpr functions, but this
540 // recursive version can be more expensive to evaluate.
541 return (__n
== 0) ? __m
: _S_gcd(__n
, __m
% __n
);
545 // _GLIBCXX_RESOLVE_LIB_DEFECTS
546 // 2094. overflow shouldn't participate in overload resolution
547 // 3090. What is [2094] intended to mean?
548 // This only produces a valid type if no overflow occurs.
549 template<typename _R1
, typename _R2
,
550 intmax_t __gcd1
= _S_gcd(_R1::num
, _R2::num
),
551 intmax_t __gcd2
= _S_gcd(_R1::den
, _R2::den
)>
552 using __divide
= ratio
<(_R1::num
/ __gcd1
) * (_R2::den
/ __gcd2
),
553 (_R1::den
/ __gcd2
) * (_R2::num
/ __gcd1
)>;
555 // _Period2 is an exact multiple of _Period
556 template<typename _Period2
>
558 = __bool_constant
<__divide
<_Period2
, _Period
>::den
== 1>;
563 using period
= typename
_Period::type
;
565 // 20.11.5.1 construction / copy / destroy
566 constexpr duration() = default;
568 duration(const duration
&) = default;
570 // _GLIBCXX_RESOLVE_LIB_DEFECTS
571 // 3050. Conversion specification problem in chrono::duration
572 template<typename _Rep2
, typename
= _Require
<
573 is_convertible
<const _Rep2
&, rep
>,
574 __or_
<__is_float
<rep
>, __not_
<__is_float
<_Rep2
>>>>>
575 constexpr explicit duration(const _Rep2
& __rep
)
576 : __r(static_cast<rep
>(__rep
)) { }
578 template<typename _Rep2
, typename _Period2
, typename
= _Require
<
579 is_convertible
<const _Rep2
&, rep
>,
580 __or_
<__is_float
<rep
>,
581 __and_
<__is_harmonic
<_Period2
>,
582 __not_
<__is_float
<_Rep2
>>>>>>
583 constexpr duration(const duration
<_Rep2
, _Period2
>& __d
)
584 : __r(duration_cast
<duration
>(__d
).count()) { }
586 ~duration() = default;
587 duration
& operator=(const duration
&) = default;
589 // 20.11.5.2 observer
594 // 20.11.5.3 arithmetic
596 constexpr duration
<typename common_type
<rep
>::type
, period
>
598 { return duration
<typename common_type
<rep
>::type
, period
>(__r
); }
600 constexpr duration
<typename common_type
<rep
>::type
, period
>
602 { return duration
<typename common_type
<rep
>::type
, period
>(-__r
); }
604 _GLIBCXX17_CONSTEXPR duration
&
611 _GLIBCXX17_CONSTEXPR duration
613 { return duration(__r
++); }
615 _GLIBCXX17_CONSTEXPR duration
&
622 _GLIBCXX17_CONSTEXPR duration
624 { return duration(__r
--); }
626 _GLIBCXX17_CONSTEXPR duration
&
627 operator+=(const duration
& __d
)
633 _GLIBCXX17_CONSTEXPR duration
&
634 operator-=(const duration
& __d
)
640 _GLIBCXX17_CONSTEXPR duration
&
641 operator*=(const rep
& __rhs
)
647 _GLIBCXX17_CONSTEXPR duration
&
648 operator/=(const rep
& __rhs
)
655 template<typename _Rep2
= rep
>
657 __enable_if_t
<!treat_as_floating_point
<_Rep2
>::value
, duration
&>
658 operator%=(const rep
& __rhs
)
664 template<typename _Rep2
= rep
>
666 __enable_if_t
<!treat_as_floating_point
<_Rep2
>::value
, duration
&>
667 operator%=(const duration
& __d
)
673 // 20.11.5.4 special values
674 static constexpr duration
676 { return duration(duration_values
<rep
>::zero()); }
678 static constexpr duration
680 { return duration(duration_values
<rep
>::min()); }
682 static constexpr duration
684 { return duration(duration_values
<rep
>::max()); }
691 /// @relates std::chrono::duration
693 /// The sum of two durations.
694 template<typename _Rep1
, typename _Period1
,
695 typename _Rep2
, typename _Period2
>
696 constexpr typename common_type
<duration
<_Rep1
, _Period1
>,
697 duration
<_Rep2
, _Period2
>>::type
698 operator+(const duration
<_Rep1
, _Period1
>& __lhs
,
699 const duration
<_Rep2
, _Period2
>& __rhs
)
701 typedef duration
<_Rep1
, _Period1
> __dur1
;
702 typedef duration
<_Rep2
, _Period2
> __dur2
;
703 typedef typename common_type
<__dur1
,__dur2
>::type __cd
;
704 return __cd(__cd(__lhs
).count() + __cd(__rhs
).count());
707 /// The difference between two durations.
708 template<typename _Rep1
, typename _Period1
,
709 typename _Rep2
, typename _Period2
>
710 constexpr typename common_type
<duration
<_Rep1
, _Period1
>,
711 duration
<_Rep2
, _Period2
>>::type
712 operator-(const duration
<_Rep1
, _Period1
>& __lhs
,
713 const duration
<_Rep2
, _Period2
>& __rhs
)
715 typedef duration
<_Rep1
, _Period1
> __dur1
;
716 typedef duration
<_Rep2
, _Period2
> __dur2
;
717 typedef typename common_type
<__dur1
,__dur2
>::type __cd
;
718 return __cd(__cd(__lhs
).count() - __cd(__rhs
).count());
723 /// @cond undocumented
725 // SFINAE helper to obtain common_type<_Rep1, _Rep2> only if _Rep2
726 // is implicitly convertible to it.
727 // _GLIBCXX_RESOLVE_LIB_DEFECTS
728 // 3050. Conversion specification problem in chrono::duration constructor
729 template<typename _Rep1
, typename _Rep2
,
730 typename _CRep
= typename common_type
<_Rep1
, _Rep2
>::type
>
731 using __common_rep_t
= typename
732 enable_if
<is_convertible
<const _Rep2
&, _CRep
>::value
, _CRep
>::type
;
737 * Arithmetic operators for chrono::duration
738 * @relates std::chrono::duration
741 template<typename _Rep1
, typename _Period
, typename _Rep2
>
742 constexpr duration
<__common_rep_t
<_Rep1
, _Rep2
>, _Period
>
743 operator*(const duration
<_Rep1
, _Period
>& __d
, const _Rep2
& __s
)
745 typedef duration
<typename common_type
<_Rep1
, _Rep2
>::type
, _Period
>
747 return __cd(__cd(__d
).count() * __s
);
750 template<typename _Rep1
, typename _Rep2
, typename _Period
>
751 constexpr duration
<__common_rep_t
<_Rep2
, _Rep1
>, _Period
>
752 operator*(const _Rep1
& __s
, const duration
<_Rep2
, _Period
>& __d
)
753 { return __d
* __s
; }
755 template<typename _Rep1
, typename _Period
, typename _Rep2
>
757 duration
<__common_rep_t
<_Rep1
, __disable_if_is_duration
<_Rep2
>>, _Period
>
758 operator/(const duration
<_Rep1
, _Period
>& __d
, const _Rep2
& __s
)
760 typedef duration
<typename common_type
<_Rep1
, _Rep2
>::type
, _Period
>
762 return __cd(__cd(__d
).count() / __s
);
765 template<typename _Rep1
, typename _Period1
,
766 typename _Rep2
, typename _Period2
>
767 constexpr typename common_type
<_Rep1
, _Rep2
>::type
768 operator/(const duration
<_Rep1
, _Period1
>& __lhs
,
769 const duration
<_Rep2
, _Period2
>& __rhs
)
771 typedef duration
<_Rep1
, _Period1
> __dur1
;
772 typedef duration
<_Rep2
, _Period2
> __dur2
;
773 typedef typename common_type
<__dur1
,__dur2
>::type __cd
;
774 return __cd(__lhs
).count() / __cd(__rhs
).count();
778 template<typename _Rep1
, typename _Period
, typename _Rep2
>
780 duration
<__common_rep_t
<_Rep1
, __disable_if_is_duration
<_Rep2
>>, _Period
>
781 operator%(const duration
<_Rep1
, _Period
>& __d
, const _Rep2
& __s
)
783 typedef duration
<typename common_type
<_Rep1
, _Rep2
>::type
, _Period
>
785 return __cd(__cd(__d
).count() % __s
);
788 template<typename _Rep1
, typename _Period1
,
789 typename _Rep2
, typename _Period2
>
790 constexpr typename common_type
<duration
<_Rep1
, _Period1
>,
791 duration
<_Rep2
, _Period2
>>::type
792 operator%(const duration
<_Rep1
, _Period1
>& __lhs
,
793 const duration
<_Rep2
, _Period2
>& __rhs
)
795 typedef duration
<_Rep1
, _Period1
> __dur1
;
796 typedef duration
<_Rep2
, _Period2
> __dur2
;
797 typedef typename common_type
<__dur1
,__dur2
>::type __cd
;
798 return __cd(__cd(__lhs
).count() % __cd(__rhs
).count());
805 * Comparisons for chrono::duration
806 * @relates std::chrono::duration
809 template<typename _Rep1
, typename _Period1
,
810 typename _Rep2
, typename _Period2
>
812 operator==(const duration
<_Rep1
, _Period1
>& __lhs
,
813 const duration
<_Rep2
, _Period2
>& __rhs
)
815 typedef duration
<_Rep1
, _Period1
> __dur1
;
816 typedef duration
<_Rep2
, _Period2
> __dur2
;
817 typedef typename common_type
<__dur1
,__dur2
>::type __ct
;
818 return __ct(__lhs
).count() == __ct(__rhs
).count();
821 template<typename _Rep1
, typename _Period1
,
822 typename _Rep2
, typename _Period2
>
824 operator<(const duration
<_Rep1
, _Period1
>& __lhs
,
825 const duration
<_Rep2
, _Period2
>& __rhs
)
827 typedef duration
<_Rep1
, _Period1
> __dur1
;
828 typedef duration
<_Rep2
, _Period2
> __dur2
;
829 typedef typename common_type
<__dur1
,__dur2
>::type __ct
;
830 return __ct(__lhs
).count() < __ct(__rhs
).count();
833 #if __cpp_lib_three_way_comparison
834 template<typename _Rep1
, typename _Period1
,
835 typename _Rep2
, typename _Period2
>
836 requires three_way_comparable
<common_type_t
<_Rep1
, _Rep2
>>
838 operator<=>(const duration
<_Rep1
, _Period1
>& __lhs
,
839 const duration
<_Rep2
, _Period2
>& __rhs
)
841 using __ct
= common_type_t
<duration
<_Rep1
, _Period1
>,
842 duration
<_Rep2
, _Period2
>>;
843 return __ct(__lhs
).count() <=> __ct(__rhs
).count();
846 template<typename _Rep1
, typename _Period1
,
847 typename _Rep2
, typename _Period2
>
849 operator!=(const duration
<_Rep1
, _Period1
>& __lhs
,
850 const duration
<_Rep2
, _Period2
>& __rhs
)
851 { return !(__lhs
== __rhs
); }
854 template<typename _Rep1
, typename _Period1
,
855 typename _Rep2
, typename _Period2
>
857 operator<=(const duration
<_Rep1
, _Period1
>& __lhs
,
858 const duration
<_Rep2
, _Period2
>& __rhs
)
859 { return !(__rhs
< __lhs
); }
861 template<typename _Rep1
, typename _Period1
,
862 typename _Rep2
, typename _Period2
>
864 operator>(const duration
<_Rep1
, _Period1
>& __lhs
,
865 const duration
<_Rep2
, _Period2
>& __rhs
)
866 { return __rhs
< __lhs
; }
868 template<typename _Rep1
, typename _Period1
,
869 typename _Rep2
, typename _Period2
>
871 operator>=(const duration
<_Rep1
, _Period1
>& __lhs
,
872 const duration
<_Rep2
, _Period2
>& __rhs
)
873 { return !(__lhs
< __rhs
); }
877 /// @cond undocumented
878 #ifdef _GLIBCXX_USE_C99_STDINT
879 # define _GLIBCXX_CHRONO_INT64_T int64_t
880 #elif defined __INT64_TYPE__
881 # define _GLIBCXX_CHRONO_INT64_T __INT64_TYPE__
883 static_assert(std::numeric_limits
<unsigned long long>::digits
>= 64,
884 "Representation type for nanoseconds must have at least 64 bits");
885 # define _GLIBCXX_CHRONO_INT64_T long long
890 using nanoseconds
= duration
<_GLIBCXX_CHRONO_INT64_T
, nano
>;
893 using microseconds
= duration
<_GLIBCXX_CHRONO_INT64_T
, micro
>;
896 using milliseconds
= duration
<_GLIBCXX_CHRONO_INT64_T
, milli
>;
899 using seconds
= duration
<_GLIBCXX_CHRONO_INT64_T
>;
902 using minutes
= duration
<_GLIBCXX_CHRONO_INT64_T
, ratio
< 60>>;
905 using hours
= duration
<_GLIBCXX_CHRONO_INT64_T
, ratio
<3600>>;
907 #if __cplusplus > 201703L
909 using days
= duration
<_GLIBCXX_CHRONO_INT64_T
, ratio
<86400>>;
912 using weeks
= duration
<_GLIBCXX_CHRONO_INT64_T
, ratio
<604800>>;
915 using years
= duration
<_GLIBCXX_CHRONO_INT64_T
, ratio
<31556952>>;
918 using months
= duration
<_GLIBCXX_CHRONO_INT64_T
, ratio
<2629746>>;
921 #undef _GLIBCXX_CHRONO_INT64_T
923 template<typename _Clock
, typename _Dur
>
926 static_assert(__is_duration
<_Dur
>::value
,
927 "duration must be a specialization of std::chrono::duration");
930 typedef _Clock clock
;
931 typedef _Dur duration
;
932 typedef typename
duration::rep rep
;
933 typedef typename
duration::period period
;
935 constexpr time_point() : __d(duration::zero())
938 constexpr explicit time_point(const duration
& __dur
)
943 template<typename _Dur2
,
944 typename
= _Require
<is_convertible
<_Dur2
, _Dur
>>>
945 constexpr time_point(const time_point
<clock
, _Dur2
>& __t
)
946 : __d(__t
.time_since_epoch())
951 time_since_epoch() const
954 #if __cplusplus > 201703L
955 constexpr time_point
&
964 { return time_point
{__d
++}; }
966 constexpr time_point
&
975 { return time_point
{__d
--}; }
979 _GLIBCXX17_CONSTEXPR time_point
&
980 operator+=(const duration
& __dur
)
986 _GLIBCXX17_CONSTEXPR time_point
&
987 operator-=(const duration
& __dur
)
994 static constexpr time_point
996 { return time_point(duration::min()); }
998 static constexpr time_point
1000 { return time_point(duration::max()); }
1006 /** Convert a `time_point` to use `duration` type `ToDur`.
1008 * The result is the same time point as measured by the same clock, but
1009 * using the specified `duration` to represent the time.
1010 * If the time point cannot be represented accurately in the result type,
1011 * returns the result of integer truncation (i.e., rounded towards zero).
1013 * @tparam _ToDur The `duration` type to use for the result.
1014 * @param __t A time point.
1015 * @return The value of `__t` converted to use type `_ToDur`.
1018 template<typename _ToDur
, typename _Clock
, typename _Dur
>
1019 _GLIBCXX_NODISCARD
constexpr
1020 __enable_if_t
<__is_duration
<_ToDur
>::value
, time_point
<_Clock
, _ToDur
>>
1021 time_point_cast(const time_point
<_Clock
, _Dur
>& __t
)
1023 typedef time_point
<_Clock
, _ToDur
> __time_point
;
1024 return __time_point(duration_cast
<_ToDur
>(__t
.time_since_epoch()));
1027 #if __cplusplus > 201402L
1028 /** Convert a `time_point` to type `ToDur` and round down.
1030 * The result is the same time point as measured by the same clock, but
1031 * using the specified `duration` to represent the time.
1032 * If the time point cannot be represented exactly in the result type,
1033 * returns the closest value that is less than the argument.
1035 * @tparam _ToDur The `duration` type to use for the result.
1036 * @param __t A time point.
1037 * @return The value of `__d` converted to type `_ToDur`.
1040 template<typename _ToDur
, typename _Clock
, typename _Dur
>
1041 [[nodiscard
]] constexpr
1042 enable_if_t
<__is_duration_v
<_ToDur
>, time_point
<_Clock
, _ToDur
>>
1043 floor(const time_point
<_Clock
, _Dur
>& __tp
)
1045 return time_point
<_Clock
, _ToDur
>{
1046 chrono::floor
<_ToDur
>(__tp
.time_since_epoch())};
1049 /** Convert a `time_point` to type `ToDur` and round up.
1051 * The result is the same time point as measured by the same clock, but
1052 * using the specified `duration` to represent the time.
1053 * If the time point cannot be represented exactly in the result type,
1054 * returns the closest value that is greater than the argument.
1056 * @tparam _ToDur The `duration` type to use for the result.
1057 * @param __t A time point.
1058 * @return The value of `__d` converted to type `_ToDur`.
1061 template<typename _ToDur
, typename _Clock
, typename _Dur
>
1062 [[nodiscard
]] constexpr
1063 enable_if_t
<__is_duration_v
<_ToDur
>, time_point
<_Clock
, _ToDur
>>
1064 ceil(const time_point
<_Clock
, _Dur
>& __tp
)
1066 return time_point
<_Clock
, _ToDur
>{
1067 chrono::ceil
<_ToDur
>(__tp
.time_since_epoch())};
1070 /** Convert a `time_point` to type `ToDur` and round to the closest value.
1072 * The result is the same time point as measured by the same clock, but
1073 * using the specified `duration` to represent the time.
1074 * If the time point cannot be represented exactly in the result type,
1075 * returns the closest value, rounding ties to even.
1077 * @tparam _ToDur The `duration` type to use for the result,
1078 * which must have a non-floating-point `rep` type.
1079 * @param __t A time point.
1080 * @return The value of `__d` converted to type `_ToDur`.
1083 template<typename _ToDur
, typename _Clock
, typename _Dur
>
1084 [[nodiscard
]] constexpr
1085 enable_if_t
<__is_duration_v
<_ToDur
>
1086 && !treat_as_floating_point_v
<typename
_ToDur::rep
>,
1087 time_point
<_Clock
, _ToDur
>>
1088 round(const time_point
<_Clock
, _Dur
>& __tp
)
1090 return time_point
<_Clock
, _ToDur
>{
1091 chrono::round
<_ToDur
>(__tp
.time_since_epoch())};
1096 /// @relates time_point
1098 /// Adjust a time point forwards by the given duration.
1099 template<typename _Clock
, typename _Dur1
,
1100 typename _Rep2
, typename _Period2
>
1101 constexpr time_point
<_Clock
,
1102 typename common_type
<_Dur1
, duration
<_Rep2
, _Period2
>>::type
>
1103 operator+(const time_point
<_Clock
, _Dur1
>& __lhs
,
1104 const duration
<_Rep2
, _Period2
>& __rhs
)
1106 typedef duration
<_Rep2
, _Period2
> __dur2
;
1107 typedef typename common_type
<_Dur1
,__dur2
>::type __ct
;
1108 typedef time_point
<_Clock
, __ct
> __time_point
;
1109 return __time_point(__lhs
.time_since_epoch() + __rhs
);
1112 /// Adjust a time point forwards by the given duration.
1113 template<typename _Rep1
, typename _Period1
,
1114 typename _Clock
, typename _Dur2
>
1115 constexpr time_point
<_Clock
,
1116 typename common_type
<duration
<_Rep1
, _Period1
>, _Dur2
>::type
>
1117 operator+(const duration
<_Rep1
, _Period1
>& __lhs
,
1118 const time_point
<_Clock
, _Dur2
>& __rhs
)
1120 typedef duration
<_Rep1
, _Period1
> __dur1
;
1121 typedef typename common_type
<__dur1
,_Dur2
>::type __ct
;
1122 typedef time_point
<_Clock
, __ct
> __time_point
;
1123 return __time_point(__rhs
.time_since_epoch() + __lhs
);
1126 /// Adjust a time point backwards by the given duration.
1127 template<typename _Clock
, typename _Dur1
,
1128 typename _Rep2
, typename _Period2
>
1129 constexpr time_point
<_Clock
,
1130 typename common_type
<_Dur1
, duration
<_Rep2
, _Period2
>>::type
>
1131 operator-(const time_point
<_Clock
, _Dur1
>& __lhs
,
1132 const duration
<_Rep2
, _Period2
>& __rhs
)
1134 typedef duration
<_Rep2
, _Period2
> __dur2
;
1135 typedef typename common_type
<_Dur1
,__dur2
>::type __ct
;
1136 typedef time_point
<_Clock
, __ct
> __time_point
;
1137 return __time_point(__lhs
.time_since_epoch() -__rhs
);
1140 /// The difference between two time points (as a duration)
1141 template<typename _Clock
, typename _Dur1
, typename _Dur2
>
1142 constexpr typename common_type
<_Dur1
, _Dur2
>::type
1143 operator-(const time_point
<_Clock
, _Dur1
>& __lhs
,
1144 const time_point
<_Clock
, _Dur2
>& __rhs
)
1145 { return __lhs
.time_since_epoch() - __rhs
.time_since_epoch(); }
1149 * Comparisons for time_point
1150 * @relates chrono::time_point
1153 template<typename _Clock
, typename _Dur1
, typename _Dur2
>
1155 operator==(const time_point
<_Clock
, _Dur1
>& __lhs
,
1156 const time_point
<_Clock
, _Dur2
>& __rhs
)
1157 { return __lhs
.time_since_epoch() == __rhs
.time_since_epoch(); }
1159 #if __cpp_lib_three_way_comparison
1160 template<typename _Clock
, typename _Dur1
,
1161 three_way_comparable_with
<_Dur1
> _Dur2
>
1163 operator<=>(const time_point
<_Clock
, _Dur1
>& __lhs
,
1164 const time_point
<_Clock
, _Dur2
>& __rhs
)
1165 { return __lhs
.time_since_epoch() <=> __rhs
.time_since_epoch(); }
1167 template<typename _Clock
, typename _Dur1
, typename _Dur2
>
1169 operator!=(const time_point
<_Clock
, _Dur1
>& __lhs
,
1170 const time_point
<_Clock
, _Dur2
>& __rhs
)
1171 { return !(__lhs
== __rhs
); }
1174 template<typename _Clock
, typename _Dur1
, typename _Dur2
>
1176 operator<(const time_point
<_Clock
, _Dur1
>& __lhs
,
1177 const time_point
<_Clock
, _Dur2
>& __rhs
)
1178 { return __lhs
.time_since_epoch() < __rhs
.time_since_epoch(); }
1180 template<typename _Clock
, typename _Dur1
, typename _Dur2
>
1182 operator<=(const time_point
<_Clock
, _Dur1
>& __lhs
,
1183 const time_point
<_Clock
, _Dur2
>& __rhs
)
1184 { return !(__rhs
< __lhs
); }
1186 template<typename _Clock
, typename _Dur1
, typename _Dur2
>
1188 operator>(const time_point
<_Clock
, _Dur1
>& __lhs
,
1189 const time_point
<_Clock
, _Dur2
>& __rhs
)
1190 { return __rhs
< __lhs
; }
1192 template<typename _Clock
, typename _Dur1
, typename _Dur2
>
1194 operator>=(const time_point
<_Clock
, _Dur1
>& __lhs
,
1195 const time_point
<_Clock
, _Dur2
>& __rhs
)
1196 { return !(__lhs
< __rhs
); }
1204 // Why nanosecond resolution as the default?
1205 // Why have std::system_clock always count in the highest
1206 // resolution (ie nanoseconds), even if on some OSes the low 3
1207 // or 9 decimal digits will be always zero? This allows later
1208 // implementations to change the system_clock::now()
1209 // implementation any time to provide better resolution without
1210 // changing function signature or units.
1212 // To support the (forward) evolution of the library's defined
1213 // clocks, wrap inside inline namespace so that the current
1214 // defintions of system_clock, steady_clock, and
1215 // high_resolution_clock types are uniquely mangled. This way, new
1216 // code can use the latests clocks, while the library can contain
1217 // compatibility definitions for previous versions. At some
1218 // point, when these clocks settle down, the inlined namespaces
1219 // can be removed. XXX GLIBCXX_ABI Deprecated
1220 _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2
)
1223 * @brief System clock.
1225 * Time returned represents wall time from the system-wide clock.
1230 typedef chrono::nanoseconds duration
;
1231 typedef duration::rep rep
;
1232 typedef duration::period period
;
1233 typedef chrono::time_point
<system_clock
, duration
> time_point
;
1235 static_assert(system_clock::duration::min()
1236 < system_clock::duration::zero(),
1237 "a clock's minimum duration cannot be less than its epoch");
1239 static constexpr bool is_steady
= false;
1246 to_time_t(const time_point
& __t
) noexcept
1248 return std::time_t(duration_cast
<chrono::seconds
>
1249 (__t
.time_since_epoch()).count());
1253 from_time_t(std::time_t __t
) noexcept
1255 typedef chrono::time_point
<system_clock
, seconds
> __from
;
1256 return time_point_cast
<system_clock::duration
>
1257 (__from(chrono::seconds(__t
)));
1263 * @brief Monotonic clock
1265 * Time returned has the property of only increasing at a uniform rate.
1270 typedef chrono::nanoseconds duration
;
1271 typedef duration::rep rep
;
1272 typedef duration::period period
;
1273 typedef chrono::time_point
<steady_clock
, duration
> time_point
;
1275 static constexpr bool is_steady
= true;
1283 * @brief Highest-resolution clock
1285 * This is the clock "with the shortest tick period." Alias to
1286 * std::system_clock until higher-than-nanosecond definitions
1290 using high_resolution_clock
= system_clock
;
1292 _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2
)
1294 #if __cplusplus >= 202002L
1295 /// @addtogroup chrono
1297 template<typename _Duration
>
1298 using sys_time
= time_point
<system_clock
, _Duration
>;
1299 using sys_seconds
= sys_time
<seconds
>;
1300 using sys_days
= sys_time
<days
>;
1302 using file_clock
= ::std::filesystem::__file_clock
;
1304 template<typename _Duration
>
1305 using file_time
= time_point
<file_clock
, _Duration
>;
1307 template<> struct is_clock
<system_clock
> : true_type
{ };
1308 template<> struct is_clock
<steady_clock
> : true_type
{ };
1309 template<> struct is_clock
<file_clock
> : true_type
{ };
1311 template<> inline constexpr bool is_clock_v
<system_clock
> = true;
1312 template<> inline constexpr bool is_clock_v
<steady_clock
> = true;
1313 template<> inline constexpr bool is_clock_v
<file_clock
> = true;
1316 #elif __cplusplus >= 202002L
1317 // Define a fake clock like chrono::local_t so that sys_time etc.
1318 // can be used for freestanding.
1320 template<typename _Duration
>
1321 using sys_time
= time_point
<__sys_t
, _Duration
>;
1322 using sys_seconds
= sys_time
<seconds
>;
1323 using sys_days
= sys_time
<days
>;
1324 #endif // _GLIBCXX_HOSTED
1325 } // namespace chrono
1327 #ifdef __glibcxx_chrono_udls // C++ >= 14
1328 inline namespace literals
1330 /** ISO C++ 2014 namespace for suffixes for duration literals.
1332 * These suffixes can be used to create `chrono::duration` values with
1333 * tick periods of hours, minutes, seconds, milliseconds, microseconds
1334 * or nanoseconds. For example, `std::chrono::seconds(5)` can be written
1335 * as `5s` after making the suffix visible in the current scope.
1336 * The suffixes can be made visible by a using-directive or
1337 * using-declaration such as:
1338 * - `using namespace std::chrono_literals;`
1339 * - `using namespace std::literals;`
1340 * - `using namespace std::chrono;`
1341 * - `using namespace std;`
1342 * - `using std::chrono_literals::operator""s;`
1344 * The result of these suffixes on an integer literal is one of the
1345 * standard typedefs such as `std::chrono::hours`.
1346 * The result on a floating-point literal is a duration type with the
1347 * specified tick period and an unspecified floating-point representation,
1348 * for example `1.5e2ms` might be equivalent to
1349 * `chrono::duration<long double, chrono::milli>(1.5e2)`.
1354 inline namespace chrono_literals
1356 /// @addtogroup chrono
1359 #pragma GCC diagnostic push
1360 #pragma GCC diagnostic ignored "-Wliteral-suffix"
1361 /// @cond undocumented
1362 template<typename _Dur
, char... _Digits
>
1363 constexpr _Dur
__check_overflow()
1365 using _Val
= __parse_int::_Parse_int
<_Digits
...>;
1366 constexpr typename
_Dur::rep __repval
= _Val::value
;
1367 static_assert(__repval
>= 0 && __repval
== _Val::value
,
1368 "literal value cannot be represented by duration type");
1369 return _Dur(__repval
);
1373 /// Literal suffix for durations representing non-integer hours
1374 constexpr chrono::duration
<long double, ratio
<3600,1>>
1375 operator""h(long double __hours
)
1376 { return chrono::duration
<long double, ratio
<3600,1>>{__hours
}; }
1378 /// Literal suffix for durations of type `std::chrono::hours`
1379 template <char... _Digits
>
1380 constexpr chrono::hours
1382 { return __check_overflow
<chrono::hours
, _Digits
...>(); }
1384 /// Literal suffix for durations representing non-integer minutes
1385 constexpr chrono::duration
<long double, ratio
<60,1>>
1386 operator""min(long double __mins
)
1387 { return chrono::duration
<long double, ratio
<60,1>>{__mins
}; }
1389 /// Literal suffix for durations of type `std::chrono::minutes`
1390 template <char... _Digits
>
1391 constexpr chrono::minutes
1393 { return __check_overflow
<chrono::minutes
, _Digits
...>(); }
1395 /// Literal suffix for durations representing non-integer seconds
1396 constexpr chrono::duration
<long double>
1397 operator""s(long double __secs
)
1398 { return chrono::duration
<long double>{__secs
}; }
1400 /// Literal suffix for durations of type `std::chrono::seconds`
1401 template <char... _Digits
>
1402 constexpr chrono::seconds
1404 { return __check_overflow
<chrono::seconds
, _Digits
...>(); }
1406 /// Literal suffix for durations representing non-integer milliseconds
1407 constexpr chrono::duration
<long double, milli
>
1408 operator""ms(long double __msecs
)
1409 { return chrono::duration
<long double, milli
>{__msecs
}; }
1411 /// Literal suffix for durations of type `std::chrono::milliseconds`
1412 template <char... _Digits
>
1413 constexpr chrono::milliseconds
1415 { return __check_overflow
<chrono::milliseconds
, _Digits
...>(); }
1417 /// Literal suffix for durations representing non-integer microseconds
1418 constexpr chrono::duration
<long double, micro
>
1419 operator""us(long double __usecs
)
1420 { return chrono::duration
<long double, micro
>{__usecs
}; }
1422 /// Literal suffix for durations of type `std::chrono::microseconds`
1423 template <char... _Digits
>
1424 constexpr chrono::microseconds
1426 { return __check_overflow
<chrono::microseconds
, _Digits
...>(); }
1428 /// Literal suffix for durations representing non-integer nanoseconds
1429 constexpr chrono::duration
<long double, nano
>
1430 operator""ns(long double __nsecs
)
1431 { return chrono::duration
<long double, nano
>{__nsecs
}; }
1433 /// Literal suffix for durations of type `std::chrono::nanoseconds`
1434 template <char... _Digits
>
1435 constexpr chrono::nanoseconds
1437 { return __check_overflow
<chrono::nanoseconds
, _Digits
...>(); }
1439 #pragma GCC diagnostic pop
1441 } // inline namespace chrono_literals
1442 } // inline namespace literals
1446 using namespace literals::chrono_literals
;
1447 } // namespace chrono
1448 #endif // __glibcxx_chrono_udls
1450 #if __cplusplus >= 201703L && _GLIBCXX_HOSTED
1451 namespace filesystem
1455 using duration
= chrono::nanoseconds
;
1456 using rep
= duration::rep
;
1457 using period
= duration::period
;
1458 using time_point
= chrono::time_point
<__file_clock
>;
1459 static constexpr bool is_steady
= false;
1463 { return _S_from_sys(chrono::system_clock::now()); }
1465 #if __cplusplus > 201703L
1466 template<typename _Dur
>
1468 chrono::file_time
<common_type_t
<_Dur
, chrono::seconds
>>
1469 from_sys(const chrono::sys_time
<_Dur
>& __t
) noexcept
1470 { return _S_from_sys(__t
); }
1472 // For internal use only
1473 template<typename _Dur
>
1475 chrono::sys_time
<common_type_t
<_Dur
, chrono::seconds
>>
1476 to_sys(const chrono::file_time
<_Dur
>& __t
) noexcept
1477 { return _S_to_sys(__t
); }
1481 using __sys_clock
= chrono::system_clock
;
1483 // This clock's (unspecified) epoch is 2174-01-01 00:00:00 UTC.
1484 // A signed 64-bit duration with nanosecond resolution gives roughly
1485 // +/- 292 years, which covers the 1901-2446 date range for ext4.
1486 static constexpr chrono::seconds _S_epoch_diff
{6437664000};
1489 // For internal use only
1490 template<typename _Dur
>
1492 chrono::time_point
<__file_clock
, common_type_t
<_Dur
, chrono::seconds
>>
1493 _S_from_sys(const chrono::time_point
<__sys_clock
, _Dur
>& __t
) noexcept
1495 using _CDur
= common_type_t
<_Dur
, chrono::seconds
>;
1496 using __file_time
= chrono::time_point
<__file_clock
, _CDur
>;
1497 return __file_time
{__t
.time_since_epoch()} - _S_epoch_diff
;
1500 // For internal use only
1501 template<typename _Dur
>
1503 chrono::time_point
<__sys_clock
, common_type_t
<_Dur
, chrono::seconds
>>
1504 _S_to_sys(const chrono::time_point
<__file_clock
, _Dur
>& __t
) noexcept
1506 using _CDur
= common_type_t
<_Dur
, chrono::seconds
>;
1507 using __sys_time
= chrono::time_point
<__sys_clock
, _CDur
>;
1508 return __sys_time
{__t
.time_since_epoch()} + _S_epoch_diff
;
1511 } // namespace filesystem
1512 #endif // C++17 && HOSTED
1514 _GLIBCXX_END_NAMESPACE_VERSION
1519 #endif //_GLIBCXX_CHRONO_H