3// Copyright (C) 2008-2021 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/chrono
26 * This is a Standard C++ Library header.
30#ifndef _GLIBCXX_CHRONO
31#define _GLIBCXX_CHRONO 1
33#pragma GCC system_header
35#if __cplusplus < 201103L
36# include <bits/c++0x_warning.h>
43#include <bits/parse_numbers.h> // for literals support.
44#if __cplusplus > 201703L
49namespace std _GLIBCXX_VISIBILITY(default)
51_GLIBCXX_BEGIN_NAMESPACE_VERSION
53#if __cplusplus >= 201703L
54 namespace filesystem { struct __file_clock; };
58 * @defgroup chrono Time
61 * Classes and functions for time.
66 /** @namespace std::chrono
67 * @brief ISO C++ 2011 namespace for date and time utilities
72 /// @addtogroup chrono
75 /// `chrono::duration` represents a distance between two points in time
76 template<typename _Rep, typename _Period = ratio<1>>
79 /// `chrono::time_point` represents a point in time as measured by a clock
80 template<typename _Clock, typename _Dur = typename _Clock::duration>
85 /// @addtogroup chrono
88 // 20.11.4.3 specialization of common_type (for duration, sfinae-friendly)
90 /// @cond undocumented
92 template<typename _CT, typename _Period1, typename _Period2, typename = void>
93 struct __duration_common_type
96 template<typename _CT, typename _Period1, typename _Period2>
97 struct __duration_common_type<_CT, _Period1, _Period2,
98 __void_t<typename _CT::type>>
101 using __gcd_num = __static_gcd<_Period1::num, _Period2::num>;
102 using __gcd_den = __static_gcd<_Period1::den, _Period2::den>;
103 using __cr = typename _CT::type;
104 using __r = ratio<__gcd_num::value,
105 (_Period1::den / __gcd_den::value) * _Period2::den>;
108 using type = chrono::duration<__cr, typename __r::type>;
114 /// @relates chrono::duration
116 /// Specialization of common_type for chrono::duration types.
117 template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2>
118 struct common_type<chrono::duration<_Rep1, _Period1>,
119 chrono::duration<_Rep2, _Period2>>
120 : __duration_common_type<common_type<_Rep1, _Rep2>,
121 typename _Period1::type,
122 typename _Period2::type>
125 /// Specialization of common_type for two identical chrono::duration types.
126 template<typename _Rep, typename _Period>
127 struct common_type<chrono::duration<_Rep, _Period>,
128 chrono::duration<_Rep, _Period>>
130 using type = chrono::duration<typename common_type<_Rep>::type,
131 typename _Period::type>;
134 /// Specialization of common_type for one chrono::duration type.
135 template<typename _Rep, typename _Period>
136 struct common_type<chrono::duration<_Rep, _Period>>
138 using type = chrono::duration<typename common_type<_Rep>::type,
139 typename _Period::type>;
143 // 20.11.4.3 specialization of common_type (for time_point, sfinae-friendly)
145 /// @cond undocumented
147 template<typename _CT, typename _Clock, typename = void>
148 struct __timepoint_common_type
151 template<typename _CT, typename _Clock>
152 struct __timepoint_common_type<_CT, _Clock, __void_t<typename _CT::type>>
154 using type = chrono::time_point<_Clock, typename _CT::type>;
160 /// @relates chrono::time_point
162 /// Specialization of common_type for chrono::time_point types.
163 template<typename _Clock, typename _Duration1, typename _Duration2>
164 struct common_type<chrono::time_point<_Clock, _Duration1>,
165 chrono::time_point<_Clock, _Duration2>>
166 : __timepoint_common_type<common_type<_Duration1, _Duration2>, _Clock>
169 /// Specialization of common_type for two identical chrono::time_point types.
170 template<typename _Clock, typename _Duration>
171 struct common_type<chrono::time_point<_Clock, _Duration>,
172 chrono::time_point<_Clock, _Duration>>
173 { using type = chrono::time_point<_Clock, _Duration>; };
175 /// Specialization of common_type for one chrono::time_point type.
176 template<typename _Clock, typename _Duration>
177 struct common_type<chrono::time_point<_Clock, _Duration>>
178 { using type = chrono::time_point<_Clock, _Duration>; };
185 /// @addtogroup chrono
188 /// @cond undocumented
190 // Primary template for duration_cast impl.
191 template<typename _ToDur, typename _CF, typename _CR,
192 bool _NumIsOne = false, bool _DenIsOne = false>
193 struct __duration_cast_impl
195 template<typename _Rep, typename _Period>
196 static constexpr _ToDur
197 __cast(const duration<_Rep, _Period>& __d)
199 typedef typename _ToDur::rep __to_rep;
200 return _ToDur(static_cast<__to_rep>(static_cast<_CR>(__d.count())
201 * static_cast<_CR>(_CF::num)
202 / static_cast<_CR>(_CF::den)));
206 template<typename _ToDur, typename _CF, typename _CR>
207 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
209 template<typename _Rep, typename _Period>
210 static constexpr _ToDur
211 __cast(const duration<_Rep, _Period>& __d)
213 typedef typename _ToDur::rep __to_rep;
214 return _ToDur(static_cast<__to_rep>(__d.count()));
218 template<typename _ToDur, typename _CF, typename _CR>
219 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
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::den)));
231 template<typename _ToDur, typename _CF, typename _CR>
232 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
234 template<typename _Rep, typename _Period>
235 static constexpr _ToDur
236 __cast(const duration<_Rep, _Period>& __d)
238 typedef typename _ToDur::rep __to_rep;
239 return _ToDur(static_cast<__to_rep>(
240 static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num)));
244 template<typename _Tp>
249 template<typename _Rep, typename _Period>
250 struct __is_duration<duration<_Rep, _Period>>
254 template<typename _Tp>
255 using __enable_if_is_duration
256 = typename enable_if<__is_duration<_Tp>::value, _Tp>::type;
258 template<typename _Tp>
259 using __disable_if_is_duration
260 = typename enable_if<!__is_duration<_Tp>::value, _Tp>::type;
265 template<typename _ToDur, typename _Rep, typename _Period>
266 constexpr __enable_if_is_duration<_ToDur>
267 duration_cast(const duration<_Rep, _Period>& __d)
269 typedef typename _ToDur::period __to_period;
270 typedef typename _ToDur::rep __to_rep;
271 typedef ratio_divide<_Period, __to_period> __cf;
272 typedef typename common_type<__to_rep, _Rep, intmax_t>::type
274 typedef __duration_cast_impl<_ToDur, __cf, __cr,
275 __cf::num == 1, __cf::den == 1> __dc;
276 return __dc::__cast(__d);
279 /// treat_as_floating_point
280 template<typename _Rep>
281 struct treat_as_floating_point
282 : is_floating_point<_Rep>
285#if __cplusplus > 201402L
286 template <typename _Rep>
287 inline constexpr bool treat_as_floating_point_v =
288 treat_as_floating_point<_Rep>::value;
291#if __cplusplus > 201703L
292 template<typename _Tp>
295 template<typename _Tp>
296 inline constexpr bool is_clock_v = is_clock<_Tp>::value;
298#if __cpp_lib_concepts
299 template<typename _Tp>
300 struct is_clock : false_type
303 template<typename _Tp>
306 typename _Tp::period;
307 typename _Tp::duration;
308 typename _Tp::time_point::clock;
309 typename _Tp::time_point::duration;
310 { &_Tp::is_steady } -> same_as<const bool*>;
311 { _Tp::now() } -> same_as<typename _Tp::time_point>;
312 requires same_as<typename _Tp::duration,
313 duration<typename _Tp::rep, typename _Tp::period>>;
314 requires same_as<typename _Tp::time_point::duration,
315 typename _Tp::duration>;
317 struct is_clock<_Tp> : true_type
320 template<typename _Tp, typename = void>
321 struct __is_clock_impl : false_type
324 template<typename _Tp>
325 struct __is_clock_impl<_Tp,
326 void_t<typename _Tp::rep, typename _Tp::period,
327 typename _Tp::duration,
328 typename _Tp::time_point::duration,
329 decltype(_Tp::is_steady),
330 decltype(_Tp::now())>>
331 : __and_<is_same<typename _Tp::duration,
332 duration<typename _Tp::rep, typename _Tp::period>>,
333 is_same<typename _Tp::time_point::duration,
334 typename _Tp::duration>,
335 is_same<decltype(&_Tp::is_steady), const bool*>,
336 is_same<decltype(_Tp::now()), typename _Tp::time_point>>::type
339 template<typename _Tp>
340 struct is_clock : __is_clock_impl<_Tp>::type
345#if __cplusplus >= 201703L
346# define __cpp_lib_chrono 201611
348 template<typename _ToDur, typename _Rep, typename _Period>
349 constexpr __enable_if_is_duration<_ToDur>
350 floor(const duration<_Rep, _Period>& __d)
352 auto __to = chrono::duration_cast<_ToDur>(__d);
354 return __to - _ToDur{1};
358 template<typename _ToDur, typename _Rep, typename _Period>
359 constexpr __enable_if_is_duration<_ToDur>
360 ceil(const duration<_Rep, _Period>& __d)
362 auto __to = chrono::duration_cast<_ToDur>(__d);
364 return __to + _ToDur{1};
368 template <typename _ToDur, typename _Rep, typename _Period>
369 constexpr enable_if_t<
370 __and_<__is_duration<_ToDur>,
371 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
373 round(const duration<_Rep, _Period>& __d)
375 _ToDur __t0 = chrono::floor<_ToDur>(__d);
376 _ToDur __t1 = __t0 + _ToDur{1};
377 auto __diff0 = __d - __t0;
378 auto __diff1 = __t1 - __d;
379 if (__diff0 == __diff1)
381 if (__t0.count() & 1)
385 else if (__diff0 < __diff1)
390 template<typename _Rep, typename _Period>
392 enable_if_t<numeric_limits<_Rep>::is_signed, duration<_Rep, _Period>>
393 abs(duration<_Rep, _Period> __d)
395 if (__d >= __d.zero())
400 // Make chrono::ceil<D> also usable as chrono::__detail::ceil<D>.
401 namespace __detail { using chrono::ceil; }
405 // We want to use ceil even when compiling for earlier standards versions.
406 // C++11 only allows a single statement in a constexpr function, so we
407 // need to move the comparison into a separate function, __ceil_impl.
410 template<typename _Tp, typename _Up>
412 __ceil_impl(const _Tp& __t, const _Up& __u)
414 return (__t < __u) ? (__t + _Tp{1}) : __t;
417 // C++11-friendly version of std::chrono::ceil<D> for internal use.
418 template<typename _ToDur, typename _Rep, typename _Period>
420 ceil(const duration<_Rep, _Period>& __d)
422 return __detail::__ceil_impl(chrono::duration_cast<_ToDur>(__d), __d);
428 template<typename _Rep>
429 struct duration_values
431 static constexpr _Rep
435 static constexpr _Rep
437 { return numeric_limits<_Rep>::max(); }
439 static constexpr _Rep
441 { return numeric_limits<_Rep>::lowest(); }
444 /// @cond undocumented
446 template<typename _Tp>
451 template<intmax_t _Num, intmax_t _Den>
452 struct __is_ratio<ratio<_Num, _Den>>
458 template<typename _Rep, typename _Period>
462 template<typename _Rep2>
463 using __is_float = treat_as_floating_point<_Rep2>;
465 static constexpr intmax_t
466 _S_gcd(intmax_t __m, intmax_t __n) noexcept
468 // Duration only allows positive periods so we don't need to
469 // handle negative values here (unlike __static_gcd and std::gcd).
470#if __cplusplus >= 201402L
473 intmax_t __rem = __m % __n;
480 // C++11 doesn't allow loops in constexpr functions, but this
481 // recursive version can be more expensive to evaluate.
482 return (__n == 0) ? __m : _S_gcd(__n, __m % __n);
486 // _GLIBCXX_RESOLVE_LIB_DEFECTS
487 // 2094. overflow shouldn't participate in overload resolution
488 // 3090. What is [2094] intended to mean?
489 // This only produces a valid type if no overflow occurs.
490 template<typename _R1, typename _R2,
491 intmax_t __gcd1 = _S_gcd(_R1::num, _R2::num),
492 intmax_t __gcd2 = _S_gcd(_R1::den, _R2::den)>
493 using __divide = ratio<(_R1::num / __gcd1) * (_R2::den / __gcd2),
494 (_R1::den / __gcd2) * (_R2::num / __gcd1)>;
496 // _Period2 is an exact multiple of _Period
497 template<typename _Period2>
499 = __bool_constant<__divide<_Period2, _Period>::den == 1>;
504 using period = typename _Period::type;
506 static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration");
507 static_assert(__is_ratio<_Period>::value,
508 "period must be a specialization of ratio");
509 static_assert(_Period::num > 0, "period must be positive");
511 // 20.11.5.1 construction / copy / destroy
512 constexpr duration() = default;
514 duration(const duration&) = default;
516 // _GLIBCXX_RESOLVE_LIB_DEFECTS
517 // 3050. Conversion specification problem in chrono::duration
518 template<typename _Rep2, typename = _Require<
519 is_convertible<const _Rep2&, rep>,
520 __or_<__is_float<rep>, __not_<__is_float<_Rep2>>>>>
521 constexpr explicit duration(const _Rep2& __rep)
522 : __r(static_cast<rep>(__rep)) { }
524 template<typename _Rep2, typename _Period2, typename = _Require<
525 is_convertible<const _Rep2&, rep>,
526 __or_<__is_float<rep>,
527 __and_<__is_harmonic<_Period2>,
528 __not_<__is_float<_Rep2>>>>>>
529 constexpr duration(const duration<_Rep2, _Period2>& __d)
530 : __r(duration_cast<duration>(__d).count()) { }
532 ~duration() = default;
533 duration& operator=(const duration&) = default;
535 // 20.11.5.2 observer
540 // 20.11.5.3 arithmetic
542 constexpr duration<typename common_type<rep>::type, period>
544 { return duration<typename common_type<rep>::type, period>(__r); }
546 constexpr duration<typename common_type<rep>::type, period>
548 { return duration<typename common_type<rep>::type, period>(-__r); }
550 _GLIBCXX17_CONSTEXPR duration&
557 _GLIBCXX17_CONSTEXPR duration
559 { return duration(__r++); }
561 _GLIBCXX17_CONSTEXPR duration&
568 _GLIBCXX17_CONSTEXPR duration
570 { return duration(__r--); }
572 _GLIBCXX17_CONSTEXPR duration&
573 operator+=(const duration& __d)
579 _GLIBCXX17_CONSTEXPR duration&
580 operator-=(const duration& __d)
586 _GLIBCXX17_CONSTEXPR duration&
587 operator*=(const rep& __rhs)
593 _GLIBCXX17_CONSTEXPR duration&
594 operator/=(const rep& __rhs)
601 template<typename _Rep2 = rep>
603 typename enable_if<!treat_as_floating_point<_Rep2>::value,
605 operator%=(const rep& __rhs)
611 template<typename _Rep2 = rep>
613 typename enable_if<!treat_as_floating_point<_Rep2>::value,
615 operator%=(const duration& __d)
621 // 20.11.5.4 special values
622 static constexpr duration
624 { return duration(duration_values<rep>::zero()); }
626 static constexpr duration
628 { return duration(duration_values<rep>::min()); }
630 static constexpr duration
632 { return duration(duration_values<rep>::max()); }
639 /// @relates std::chrono::duration
641 /// The sum of two durations.
642 template<typename _Rep1, typename _Period1,
643 typename _Rep2, typename _Period2>
644 constexpr typename common_type<duration<_Rep1, _Period1>,
645 duration<_Rep2, _Period2>>::type
646 operator+(const duration<_Rep1, _Period1>& __lhs,
647 const duration<_Rep2, _Period2>& __rhs)
649 typedef duration<_Rep1, _Period1> __dur1;
650 typedef duration<_Rep2, _Period2> __dur2;
651 typedef typename common_type<__dur1,__dur2>::type __cd;
652 return __cd(__cd(__lhs).count() + __cd(__rhs).count());
655 /// The difference between two durations.
656 template<typename _Rep1, typename _Period1,
657 typename _Rep2, typename _Period2>
658 constexpr typename common_type<duration<_Rep1, _Period1>,
659 duration<_Rep2, _Period2>>::type
660 operator-(const duration<_Rep1, _Period1>& __lhs,
661 const duration<_Rep2, _Period2>& __rhs)
663 typedef duration<_Rep1, _Period1> __dur1;
664 typedef duration<_Rep2, _Period2> __dur2;
665 typedef typename common_type<__dur1,__dur2>::type __cd;
666 return __cd(__cd(__lhs).count() - __cd(__rhs).count());
671 /// @cond undocumented
673 // SFINAE helper to obtain common_type<_Rep1, _Rep2> only if _Rep2
674 // is implicitly convertible to it.
675 // _GLIBCXX_RESOLVE_LIB_DEFECTS
676 // 3050. Conversion specification problem in chrono::duration constructor
677 template<typename _Rep1, typename _Rep2,
678 typename _CRep = typename common_type<_Rep1, _Rep2>::type>
679 using __common_rep_t = typename
680 enable_if<is_convertible<const _Rep2&, _CRep>::value, _CRep>::type;
685 * Arithmetic operators for chrono::duration
686 * @relates std::chrono::duration
689 template<typename _Rep1, typename _Period, typename _Rep2>
690 constexpr duration<__common_rep_t<_Rep1, _Rep2>, _Period>
691 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
693 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
695 return __cd(__cd(__d).count() * __s);
698 template<typename _Rep1, typename _Rep2, typename _Period>
699 constexpr duration<__common_rep_t<_Rep2, _Rep1>, _Period>
700 operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
701 { return __d * __s; }
703 template<typename _Rep1, typename _Period, typename _Rep2>
705 duration<__common_rep_t<_Rep1, __disable_if_is_duration<_Rep2>>, _Period>
706 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
708 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
710 return __cd(__cd(__d).count() / __s);
713 template<typename _Rep1, typename _Period1,
714 typename _Rep2, typename _Period2>
715 constexpr typename common_type<_Rep1, _Rep2>::type
716 operator/(const duration<_Rep1, _Period1>& __lhs,
717 const duration<_Rep2, _Period2>& __rhs)
719 typedef duration<_Rep1, _Period1> __dur1;
720 typedef duration<_Rep2, _Period2> __dur2;
721 typedef typename common_type<__dur1,__dur2>::type __cd;
722 return __cd(__lhs).count() / __cd(__rhs).count();
726 template<typename _Rep1, typename _Period, typename _Rep2>
728 duration<__common_rep_t<_Rep1, __disable_if_is_duration<_Rep2>>, _Period>
729 operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
731 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
733 return __cd(__cd(__d).count() % __s);
736 template<typename _Rep1, typename _Period1,
737 typename _Rep2, typename _Period2>
738 constexpr typename common_type<duration<_Rep1, _Period1>,
739 duration<_Rep2, _Period2>>::type
740 operator%(const duration<_Rep1, _Period1>& __lhs,
741 const duration<_Rep2, _Period2>& __rhs)
743 typedef duration<_Rep1, _Period1> __dur1;
744 typedef duration<_Rep2, _Period2> __dur2;
745 typedef typename common_type<__dur1,__dur2>::type __cd;
746 return __cd(__cd(__lhs).count() % __cd(__rhs).count());
753 * Comparisons for chrono::duration
754 * @relates std::chrono::duration
757 template<typename _Rep1, typename _Period1,
758 typename _Rep2, typename _Period2>
760 operator==(const duration<_Rep1, _Period1>& __lhs,
761 const duration<_Rep2, _Period2>& __rhs)
763 typedef duration<_Rep1, _Period1> __dur1;
764 typedef duration<_Rep2, _Period2> __dur2;
765 typedef typename common_type<__dur1,__dur2>::type __ct;
766 return __ct(__lhs).count() == __ct(__rhs).count();
769 template<typename _Rep1, typename _Period1,
770 typename _Rep2, typename _Period2>
772 operator<(const duration<_Rep1, _Period1>& __lhs,
773 const duration<_Rep2, _Period2>& __rhs)
775 typedef duration<_Rep1, _Period1> __dur1;
776 typedef duration<_Rep2, _Period2> __dur2;
777 typedef typename common_type<__dur1,__dur2>::type __ct;
778 return __ct(__lhs).count() < __ct(__rhs).count();
781#if __cpp_lib_three_way_comparison
782 template<typename _Rep1, typename _Period1,
783 typename _Rep2, typename _Period2>
784 requires three_way_comparable<common_type_t<_Rep1, _Rep2>>
786 operator<=>(const duration<_Rep1, _Period1>& __lhs,
787 const duration<_Rep2, _Period2>& __rhs)
789 using __ct = common_type_t<duration<_Rep1, _Period1>,
790 duration<_Rep2, _Period2>>;
791 return __ct(__lhs).count() <=> __ct(__rhs).count();
794 template<typename _Rep1, typename _Period1,
795 typename _Rep2, typename _Period2>
797 operator!=(const duration<_Rep1, _Period1>& __lhs,
798 const duration<_Rep2, _Period2>& __rhs)
799 { return !(__lhs == __rhs); }
802 template<typename _Rep1, typename _Period1,
803 typename _Rep2, typename _Period2>
805 operator<=(const duration<_Rep1, _Period1>& __lhs,
806 const duration<_Rep2, _Period2>& __rhs)
807 { return !(__rhs < __lhs); }
809 template<typename _Rep1, typename _Period1,
810 typename _Rep2, typename _Period2>
812 operator>(const duration<_Rep1, _Period1>& __lhs,
813 const duration<_Rep2, _Period2>& __rhs)
814 { return __rhs < __lhs; }
816 template<typename _Rep1, typename _Period1,
817 typename _Rep2, typename _Period2>
819 operator>=(const duration<_Rep1, _Period1>& __lhs,
820 const duration<_Rep2, _Period2>& __rhs)
821 { return !(__lhs < __rhs); }
825 /// @cond undocumented
826#ifdef _GLIBCXX_USE_C99_STDINT_TR1
827# define _GLIBCXX_CHRONO_INT64_T int64_t
828#elif defined __INT64_TYPE__
829# define _GLIBCXX_CHRONO_INT64_T __INT64_TYPE__
831 static_assert(std::numeric_limits<unsigned long long>::digits >= 64,
832 "Representation type for nanoseconds must have at least 64 bits");
833# define _GLIBCXX_CHRONO_INT64_T long long
838 using nanoseconds = duration<_GLIBCXX_CHRONO_INT64_T, nano>;
841 using microseconds = duration<_GLIBCXX_CHRONO_INT64_T, micro>;
844 using milliseconds = duration<_GLIBCXX_CHRONO_INT64_T, milli>;
847 using seconds = duration<_GLIBCXX_CHRONO_INT64_T>;
850 using minutes = duration<_GLIBCXX_CHRONO_INT64_T, ratio< 60>>;
853 using hours = duration<_GLIBCXX_CHRONO_INT64_T, ratio<3600>>;
855#if __cplusplus > 201703L
857 using days = duration<_GLIBCXX_CHRONO_INT64_T, ratio<86400>>;
860 using weeks = duration<_GLIBCXX_CHRONO_INT64_T, ratio<604800>>;
863 using years = duration<_GLIBCXX_CHRONO_INT64_T, ratio<31556952>>;
866 using months = duration<_GLIBCXX_CHRONO_INT64_T, ratio<2629746>>;
869#undef _GLIBCXX_CHRONO_INT64_T
871 template<typename _Clock, typename _Dur>
874 static_assert(__is_duration<_Dur>::value,
875 "duration must be a specialization of std::chrono::duration");
877 typedef _Clock clock;
878 typedef _Dur duration;
879 typedef typename duration::rep rep;
880 typedef typename duration::period period;
882 constexpr time_point() : __d(duration::zero())
885 constexpr explicit time_point(const duration& __dur)
890 template<typename _Dur2,
891 typename = _Require<is_convertible<_Dur2, _Dur>>>
892 constexpr time_point(const time_point<clock, _Dur2>& __t)
893 : __d(__t.time_since_epoch())
898 time_since_epoch() const
901#if __cplusplus > 201703L
902 constexpr time_point&
911 { return time_point{__d++}; }
913 constexpr time_point&
922 { return time_point{__d--}; }
926 _GLIBCXX17_CONSTEXPR time_point&
927 operator+=(const duration& __dur)
933 _GLIBCXX17_CONSTEXPR time_point&
934 operator-=(const duration& __dur)
941 static constexpr time_point
943 { return time_point(duration::min()); }
945 static constexpr time_point
947 { return time_point(duration::max()); }
954 template<typename _ToDur, typename _Clock, typename _Dur>
955 constexpr typename enable_if<__is_duration<_ToDur>::value,
956 time_point<_Clock, _ToDur>>::type
957 time_point_cast(const time_point<_Clock, _Dur>& __t)
959 typedef time_point<_Clock, _ToDur> __time_point;
960 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
963#if __cplusplus > 201402L
964 template<typename _ToDur, typename _Clock, typename _Dur>
966 enable_if_t<__is_duration<_ToDur>::value, time_point<_Clock, _ToDur>>
967 floor(const time_point<_Clock, _Dur>& __tp)
969 return time_point<_Clock, _ToDur>{
970 chrono::floor<_ToDur>(__tp.time_since_epoch())};
973 template<typename _ToDur, typename _Clock, typename _Dur>
975 enable_if_t<__is_duration<_ToDur>::value, time_point<_Clock, _ToDur>>
976 ceil(const time_point<_Clock, _Dur>& __tp)
978 return time_point<_Clock, _ToDur>{
979 chrono::ceil<_ToDur>(__tp.time_since_epoch())};
982 template<typename _ToDur, typename _Clock, typename _Dur>
983 constexpr enable_if_t<
984 __and_<__is_duration<_ToDur>,
985 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
986 time_point<_Clock, _ToDur>>
987 round(const time_point<_Clock, _Dur>& __tp)
989 return time_point<_Clock, _ToDur>{
990 chrono::round<_ToDur>(__tp.time_since_epoch())};
995 /// @relates time_point
997 /// Adjust a time point forwards by the given duration.
998 template<typename _Clock, typename _Dur1,
999 typename _Rep2, typename _Period2>
1000 constexpr time_point<_Clock,
1001 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
1002 operator+(const time_point<_Clock, _Dur1>& __lhs,
1003 const duration<_Rep2, _Period2>& __rhs)
1005 typedef duration<_Rep2, _Period2> __dur2;
1006 typedef typename common_type<_Dur1,__dur2>::type __ct;
1007 typedef time_point<_Clock, __ct> __time_point;
1008 return __time_point(__lhs.time_since_epoch() + __rhs);
1011 /// Adjust a time point forwards by the given duration.
1012 template<typename _Rep1, typename _Period1,
1013 typename _Clock, typename _Dur2>
1014 constexpr time_point<_Clock,
1015 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
1016 operator+(const duration<_Rep1, _Period1>& __lhs,
1017 const time_point<_Clock, _Dur2>& __rhs)
1019 typedef duration<_Rep1, _Period1> __dur1;
1020 typedef typename common_type<__dur1,_Dur2>::type __ct;
1021 typedef time_point<_Clock, __ct> __time_point;
1022 return __time_point(__rhs.time_since_epoch() + __lhs);
1025 /// Adjust a time point backwards by the given duration.
1026 template<typename _Clock, typename _Dur1,
1027 typename _Rep2, typename _Period2>
1028 constexpr time_point<_Clock,
1029 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
1030 operator-(const time_point<_Clock, _Dur1>& __lhs,
1031 const duration<_Rep2, _Period2>& __rhs)
1033 typedef duration<_Rep2, _Period2> __dur2;
1034 typedef typename common_type<_Dur1,__dur2>::type __ct;
1035 typedef time_point<_Clock, __ct> __time_point;
1036 return __time_point(__lhs.time_since_epoch() -__rhs);
1039 /// The difference between two time points (as a duration)
1040 template<typename _Clock, typename _Dur1, typename _Dur2>
1041 constexpr typename common_type<_Dur1, _Dur2>::type
1042 operator-(const time_point<_Clock, _Dur1>& __lhs,
1043 const time_point<_Clock, _Dur2>& __rhs)
1044 { return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
1048 * Comparisons for time_point
1049 * @relates chrono::time_point
1052 template<typename _Clock, typename _Dur1, typename _Dur2>
1054 operator==(const time_point<_Clock, _Dur1>& __lhs,
1055 const time_point<_Clock, _Dur2>& __rhs)
1056 { return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
1058#if __cpp_lib_three_way_comparison
1059 template<typename _Clock, typename _Dur1,
1060 three_way_comparable_with<_Dur1> _Dur2>
1062 operator<=>(const time_point<_Clock, _Dur1>& __lhs,
1063 const time_point<_Clock, _Dur2>& __rhs)
1064 { return __lhs.time_since_epoch() <=> __rhs.time_since_epoch(); }
1066 template<typename _Clock, typename _Dur1, typename _Dur2>
1068 operator!=(const time_point<_Clock, _Dur1>& __lhs,
1069 const time_point<_Clock, _Dur2>& __rhs)
1070 { return !(__lhs == __rhs); }
1073 template<typename _Clock, typename _Dur1, typename _Dur2>
1075 operator<(const time_point<_Clock, _Dur1>& __lhs,
1076 const time_point<_Clock, _Dur2>& __rhs)
1077 { return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
1079 template<typename _Clock, typename _Dur1, typename _Dur2>
1081 operator<=(const time_point<_Clock, _Dur1>& __lhs,
1082 const time_point<_Clock, _Dur2>& __rhs)
1083 { return !(__rhs < __lhs); }
1085 template<typename _Clock, typename _Dur1, typename _Dur2>
1087 operator>(const time_point<_Clock, _Dur1>& __lhs,
1088 const time_point<_Clock, _Dur2>& __rhs)
1089 { return __rhs < __lhs; }
1091 template<typename _Clock, typename _Dur1, typename _Dur2>
1093 operator>=(const time_point<_Clock, _Dur1>& __lhs,
1094 const time_point<_Clock, _Dur2>& __rhs)
1095 { return !(__lhs < __rhs); }
1101 // Why nanosecond resolution as the default?
1102 // Why have std::system_clock always count in the highest
1103 // resolution (ie nanoseconds), even if on some OSes the low 3
1104 // or 9 decimal digits will be always zero? This allows later
1105 // implementations to change the system_clock::now()
1106 // implementation any time to provide better resolution without
1107 // changing function signature or units.
1109 // To support the (forward) evolution of the library's defined
1110 // clocks, wrap inside inline namespace so that the current
1111 // defintions of system_clock, steady_clock, and
1112 // high_resolution_clock types are uniquely mangled. This way, new
1113 // code can use the latests clocks, while the library can contain
1114 // compatibility definitions for previous versions. At some
1115 // point, when these clocks settle down, the inlined namespaces
1116 // can be removed. XXX GLIBCXX_ABI Deprecated
1117 inline namespace _V2 {
1120 * @brief System clock.
1122 * Time returned represents wall time from the system-wide clock.
1127 typedef chrono::nanoseconds duration;
1128 typedef duration::rep rep;
1129 typedef duration::period period;
1130 typedef chrono::time_point<system_clock, duration> time_point;
1132 static_assert(system_clock::duration::min()
1133 < system_clock::duration::zero(),
1134 "a clock's minimum duration cannot be less than its epoch");
1136 static constexpr bool is_steady = false;
1143 to_time_t(const time_point& __t) noexcept
1145 return std::time_t(duration_cast<chrono::seconds>
1146 (__t.time_since_epoch()).count());
1150 from_time_t(std::time_t __t) noexcept
1152 typedef chrono::time_point<system_clock, seconds> __from;
1153 return time_point_cast<system_clock::duration>
1154 (__from(chrono::seconds(__t)));
1160 * @brief Monotonic clock
1162 * Time returned has the property of only increasing at a uniform rate.
1167 typedef chrono::nanoseconds duration;
1168 typedef duration::rep rep;
1169 typedef duration::period period;
1170 typedef chrono::time_point<steady_clock, duration> time_point;
1172 static constexpr bool is_steady = true;
1180 * @brief Highest-resolution clock
1182 * This is the clock "with the shortest tick period." Alias to
1183 * std::system_clock until higher-than-nanosecond definitions
1187 using high_resolution_clock = system_clock;
1189 } // end inline namespace _V2
1191#if __cplusplus > 201703L
1192 template<typename _Duration>
1193 using sys_time = time_point<system_clock, _Duration>;
1194 using sys_seconds = sys_time<seconds>;
1195 using sys_days = sys_time<days>;
1197 using file_clock = ::std::filesystem::__file_clock;
1199 template<typename _Duration>
1200 using file_time = time_point<file_clock, _Duration>;
1202 template<> struct is_clock<system_clock> : true_type { };
1203 template<> struct is_clock<steady_clock> : true_type { };
1204 template<> struct is_clock<file_clock> : true_type { };
1206 template<> inline constexpr bool is_clock_v<system_clock> = true;
1207 template<> inline constexpr bool is_clock_v<steady_clock> = true;
1208 template<> inline constexpr bool is_clock_v<file_clock> = true;
1211 template<typename _Duration>
1212 using local_time = time_point<local_t, _Duration>;
1213 using local_seconds = local_time<seconds>;
1214 using local_days = local_time<days>;
1220 template<typename _Duration>
1221 using utc_time = time_point<utc_clock, _Duration>;
1222 using utc_seconds = utc_time<seconds>;
1224 template<typename _Duration>
1225 using tai_time = time_point<tai_clock, _Duration>;
1226 using tai_seconds = tai_time<seconds>;
1228 template<typename _Duration>
1229 using gps_time = time_point<gps_clock, _Duration>;
1230 using gps_seconds = gps_time<seconds>;
1232 template<> struct is_clock<utc_clock> : true_type { };
1233 template<> struct is_clock<tai_clock> : true_type { };
1234 template<> struct is_clock<gps_clock> : true_type { };
1236 template<> inline constexpr bool is_clock_v<utc_clock> = true;
1237 template<> inline constexpr bool is_clock_v<tai_clock> = true;
1238 template<> inline constexpr bool is_clock_v<gps_clock> = true;
1240 struct leap_second_info
1242 bool is_leap_second;
1246 // CALENDRICAL TYPES
1248 // CLASS DECLARATIONS
1253 class weekday_indexed;
1256 class month_day_last;
1257 class month_weekday;
1258 class month_weekday_last;
1260 class year_month_day;
1261 class year_month_day_last;
1262 class year_month_weekday;
1263 class year_month_weekday_last;
1267 explicit last_spec() = default;
1269 friend constexpr month_day_last
1270 operator/(int __m, last_spec) noexcept;
1272 friend constexpr month_day_last
1273 operator/(last_spec, int __m) noexcept;
1276 inline constexpr last_spec last{};
1280 // Compute the remainder of the Euclidean division of __n divided by __d.
1281 // Euclidean division truncates toward negative infinity and always
1282 // produces a remainder in the range of [0,__d-1] (whereas standard
1283 // division truncates toward zero and yields a nonpositive remainder
1284 // for negative __n).
1286 __modulo(long long __n, unsigned __d)
1291 return (__d + (__n % __d)) % __d;
1294 inline constexpr unsigned __days_per_month[12]
1295 = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
1309 day(unsigned __d) noexcept
1314 operator++() noexcept
1321 operator++(int) noexcept
1329 operator--() noexcept
1336 operator--(int) noexcept
1344 operator+=(const days& __d) noexcept
1346 *this = *this + __d;
1351 operator-=(const days& __d) noexcept
1353 *this = *this - __d;
1358 operator unsigned() const noexcept
1363 { return 1 <= _M_d && _M_d <= 31; }
1365 friend constexpr bool
1366 operator==(const day& __x, const day& __y) noexcept
1367 { return unsigned{__x} == unsigned{__y}; }
1369 friend constexpr strong_ordering
1370 operator<=>(const day& __x, const day& __y) noexcept
1371 { return unsigned{__x} <=> unsigned{__y}; }
1373 friend constexpr day
1374 operator+(const day& __x, const days& __y) noexcept
1375 { return day(unsigned{__x} + __y.count()); }
1377 friend constexpr day
1378 operator+(const days& __x, const day& __y) noexcept
1379 { return __y + __x; }
1381 friend constexpr day
1382 operator-(const day& __x, const days& __y) noexcept
1383 { return __x + -__y; }
1385 friend constexpr days
1386 operator-(const day& __x, const day& __y) noexcept
1387 { return days{int(unsigned{__x}) - int(unsigned{__y})}; }
1389 friend constexpr month_day
1390 operator/(const month& __m, const day& __d) noexcept;
1392 friend constexpr month_day
1393 operator/(int __m, const day& __d) noexcept;
1395 friend constexpr month_day
1396 operator/(const day& __d, const month& __m) noexcept;
1398 friend constexpr month_day
1399 operator/(const day& __d, int __m) noexcept;
1401 friend constexpr year_month_day
1402 operator/(const year_month& __ym, const day& __d) noexcept;
1404 // TODO: Implement operator<<, to_stream, from_stream.
1418 month(unsigned __m) noexcept
1423 operator++() noexcept
1430 operator++(int) noexcept
1438 operator--() noexcept
1445 operator--(int) noexcept
1453 operator+=(const months& __m) noexcept
1455 *this = *this + __m;
1460 operator-=(const months& __m) noexcept
1462 *this = *this - __m;
1467 operator unsigned() const noexcept
1472 { return 1 <= _M_m && _M_m <= 12; }
1474 friend constexpr bool
1475 operator==(const month& __x, const month& __y) noexcept
1476 { return unsigned{__x} == unsigned{__y}; }
1478 friend constexpr strong_ordering
1479 operator<=>(const month& __x, const month& __y) noexcept
1480 { return unsigned{__x} <=> unsigned{__y}; }
1482 friend constexpr month
1483 operator+(const month& __x, const months& __y) noexcept
1485 auto __n = static_cast<long long>(unsigned{__x}) + (__y.count() - 1);
1486 return month{__detail::__modulo(__n, 12) + 1};
1489 friend constexpr month
1490 operator+(const months& __x, const month& __y) noexcept
1491 { return __y + __x; }
1493 friend constexpr month
1494 operator-(const month& __x, const months& __y) noexcept
1495 { return __x + -__y; }
1497 friend constexpr months
1498 operator-(const month& __x, const month& __y) noexcept
1500 const auto __dm = int(unsigned(__x)) - int(unsigned(__y));
1501 return months{__dm < 0 ? 12 + __dm : __dm};
1504 friend constexpr year_month
1505 operator/(const year& __y, const month& __m) noexcept;
1507 friend constexpr month_day
1508 operator/(const month& __m, int __d) noexcept;
1510 friend constexpr month_day_last
1511 operator/(const month& __m, last_spec) noexcept;
1513 friend constexpr month_day_last
1514 operator/(last_spec, const month& __m) noexcept;
1516 friend constexpr month_weekday
1517 operator/(const month& __m, const weekday_indexed& __wdi) noexcept;
1519 friend constexpr month_weekday
1520 operator/(const weekday_indexed& __wdi, const month& __m) noexcept;
1522 friend constexpr month_weekday_last
1523 operator/(const month& __m, const weekday_last& __wdl) noexcept;
1525 friend constexpr month_weekday_last
1526 operator/(const weekday_last& __wdl, const month& __m) noexcept;
1528 // TODO: Implement operator<<, to_stream, from_stream.
1531 inline constexpr month January{1};
1532 inline constexpr month February{2};
1533 inline constexpr month March{3};
1534 inline constexpr month April{4};
1535 inline constexpr month May{5};
1536 inline constexpr month June{6};
1537 inline constexpr month July{7};
1538 inline constexpr month August{8};
1539 inline constexpr month September{9};
1540 inline constexpr month October{10};
1541 inline constexpr month November{11};
1542 inline constexpr month December{12};
1555 year(int __y) noexcept
1556 : _M_y{static_cast<short>(__y)}
1559 static constexpr year
1561 { return year{-32767}; }
1563 static constexpr year
1565 { return year{32767}; }
1568 operator++() noexcept
1575 operator++(int) noexcept
1583 operator--() noexcept
1590 operator--(int) noexcept
1598 operator+=(const years& __y) noexcept
1600 *this = *this + __y;
1605 operator-=(const years& __y) noexcept
1607 *this = *this - __y;
1612 operator+() const noexcept
1616 operator-() const noexcept
1617 { return year{-_M_y}; }
1620 is_leap() const noexcept
1622 // Testing divisibility by 100 first gives better performance, that is,
1623 // return (_M_y % 100 != 0 || _M_y % 400 == 0) && _M_y % 4 == 0;
1625 // It gets even faster if _M_y is in [-536870800, 536870999]
1626 // (which is the case here) and _M_y % 100 is replaced by
1627 // __is_multiple_of_100 below.
1630 // [1] https://github.com/cassioneri/calendar
1631 // [2] https://accu.org/journals/overload/28/155/overload155.pdf#page=16
1633 constexpr uint32_t __multiplier = 42949673;
1634 constexpr uint32_t __bound = 42949669;
1635 constexpr uint32_t __max_dividend = 1073741799;
1636 constexpr uint32_t __offset = __max_dividend / 2 / 100 * 100;
1637 const bool __is_multiple_of_100
1638 = __multiplier * (_M_y + __offset) < __bound;
1639 return (!__is_multiple_of_100 || _M_y % 400 == 0) && _M_y % 4 == 0;
1643 operator int() const noexcept
1648 { return min()._M_y <= _M_y && _M_y <= max()._M_y; }
1650 friend constexpr bool
1651 operator==(const year& __x, const year& __y) noexcept
1652 { return int{__x} == int{__y}; }
1654 friend constexpr strong_ordering
1655 operator<=>(const year& __x, const year& __y) noexcept
1656 { return int{__x} <=> int{__y}; }
1658 friend constexpr year
1659 operator+(const year& __x, const years& __y) noexcept
1660 { return year{int{__x} + static_cast<int>(__y.count())}; }
1662 friend constexpr year
1663 operator+(const years& __x, const year& __y) noexcept
1664 { return __y + __x; }
1666 friend constexpr year
1667 operator-(const year& __x, const years& __y) noexcept
1668 { return __x + -__y; }
1670 friend constexpr years
1671 operator-(const year& __x, const year& __y) noexcept
1672 { return years{int{__x} - int{__y}}; }
1674 friend constexpr year_month
1675 operator/(const year& __y, int __m) noexcept;
1677 friend constexpr year_month_day
1678 operator/(const year& __y, const month_day& __md) noexcept;
1680 friend constexpr year_month_day
1681 operator/(const month_day& __md, const year& __y) noexcept;
1683 friend constexpr year_month_day_last
1684 operator/(const year& __y, const month_day_last& __mdl) noexcept;
1686 friend constexpr year_month_day_last
1687 operator/(const month_day_last& __mdl, const year& __y) noexcept;
1689 friend constexpr year_month_weekday
1690 operator/(const year& __y, const month_weekday& __mwd) noexcept;
1692 friend constexpr year_month_weekday
1693 operator/(const month_weekday& __mwd, const year& __y) noexcept;
1695 friend constexpr year_month_weekday_last
1696 operator/(const year& __y, const month_weekday_last& __mwdl) noexcept;
1698 friend constexpr year_month_weekday_last
1699 operator/(const month_weekday_last& __mwdl, const year& __y) noexcept;
1701 // TODO: Implement operator<<, to_stream, from_stream.
1709 unsigned char _M_wd;
1711 static constexpr weekday
1712 _S_from_days(const days& __d)
1714 auto __n = __d.count();
1715 return weekday(__n >= -4 ? (__n + 4) % 7 : (__n + 5) % 7 + 6);
1719 weekday() = default;
1722 weekday(unsigned __wd) noexcept
1723 : _M_wd(__wd == 7 ? 0 : __wd) // __wd % 7 ?
1727 weekday(const sys_days& __dp) noexcept
1728 : weekday{_S_from_days(__dp.time_since_epoch())}
1732 weekday(const local_days& __dp) noexcept
1733 : weekday{sys_days{__dp.time_since_epoch()}}
1737 operator++() noexcept
1744 operator++(int) noexcept
1752 operator--() noexcept
1759 operator--(int) noexcept
1767 operator+=(const days& __d) noexcept
1769 *this = *this + __d;
1774 operator-=(const days& __d) noexcept
1776 *this = *this - __d;
1781 c_encoding() const noexcept
1785 iso_encoding() const noexcept
1786 { return _M_wd == 0u ? 7u : _M_wd; }
1790 { return _M_wd <= 6; }
1792 constexpr weekday_indexed
1793 operator[](unsigned __index) const noexcept;
1795 constexpr weekday_last
1796 operator[](last_spec) const noexcept;
1798 friend constexpr bool
1799 operator==(const weekday& __x, const weekday& __y) noexcept
1800 { return __x._M_wd == __y._M_wd; }
1802 friend constexpr weekday
1803 operator+(const weekday& __x, const days& __y) noexcept
1805 auto __n = static_cast<long long>(__x._M_wd) + __y.count();
1806 return weekday{__detail::__modulo(__n, 7)};
1809 friend constexpr weekday
1810 operator+(const days& __x, const weekday& __y) noexcept
1811 { return __y + __x; }
1813 friend constexpr weekday
1814 operator-(const weekday& __x, const days& __y) noexcept
1815 { return __x + -__y; }
1817 friend constexpr days
1818 operator-(const weekday& __x, const weekday& __y) noexcept
1820 auto __n = static_cast<long long>(__x._M_wd) - __y._M_wd;
1821 return days{__detail::__modulo(__n, 7)};
1824 // TODO: operator<<, from_stream.
1827 inline constexpr weekday Sunday{0};
1828 inline constexpr weekday Monday{1};
1829 inline constexpr weekday Tuesday{2};
1830 inline constexpr weekday Wednesday{3};
1831 inline constexpr weekday Thursday{4};
1832 inline constexpr weekday Friday{5};
1833 inline constexpr weekday Saturday{6};
1837 class weekday_indexed
1840 chrono::weekday _M_wd;
1841 unsigned char _M_index;
1844 weekday_indexed() = default;
1847 weekday_indexed(const chrono::weekday& __wd, unsigned __index) noexcept
1848 : _M_wd(__wd), _M_index(__index)
1851 constexpr chrono::weekday
1852 weekday() const noexcept
1856 index() const noexcept
1857 { return _M_index; };
1861 { return _M_wd.ok() && 1 <= _M_index && _M_index <= 5; }
1863 friend constexpr bool
1864 operator==(const weekday_indexed& __x, const weekday_indexed& __y) noexcept
1865 { return __x.weekday() == __y.weekday() && __x.index() == __y.index(); }
1867 friend constexpr month_weekday
1868 operator/(const month& __m, const weekday_indexed& __wdi) noexcept;
1870 friend constexpr month_weekday
1871 operator/(int __m, const weekday_indexed& __wdi) noexcept;
1873 friend constexpr month_weekday
1874 operator/(const weekday_indexed& __wdi, const month& __m) noexcept;
1876 friend constexpr month_weekday
1877 operator/(const weekday_indexed& __wdi, int __m) noexcept;
1879 friend constexpr year_month_weekday
1880 operator/(const year_month& __ym, const weekday_indexed& __wdi) noexcept;
1882 // TODO: Implement operator<<.
1885 constexpr weekday_indexed
1886 weekday::operator[](unsigned __index) const noexcept
1887 { return {*this, __index}; }
1894 chrono::weekday _M_wd;
1898 weekday_last(const chrono::weekday& __wd) noexcept
1902 constexpr chrono::weekday
1903 weekday() const noexcept
1908 { return _M_wd.ok(); }
1910 friend constexpr bool
1911 operator==(const weekday_last& __x, const weekday_last& __y) noexcept
1912 { return __x.weekday() == __y.weekday(); }
1914 friend constexpr month_weekday_last
1915 operator/(int __m, const weekday_last& __wdl) noexcept;
1917 friend constexpr month_weekday_last
1918 operator/(const weekday_last& __wdl, int __m) noexcept;
1920 friend constexpr year_month_weekday_last
1921 operator/(const year_month& __ym, const weekday_last& __wdl) noexcept;
1923 // TODO: Implement operator<<.
1926 constexpr weekday_last
1927 weekday::operator[](last_spec) const noexcept
1928 { return weekday_last{*this}; }
1939 month_day() = default;
1942 month_day(const chrono::month& __m, const chrono::day& __d) noexcept
1943 : _M_m{__m}, _M_d{__d}
1946 constexpr chrono::month
1947 month() const noexcept
1950 constexpr chrono::day
1951 day() const noexcept
1958 && 1u <= unsigned(_M_d)
1959 && unsigned(_M_d) <= __detail::__days_per_month[unsigned(_M_m) - 1];
1962 friend constexpr bool
1963 operator==(const month_day& __x, const month_day& __y) noexcept
1964 { return __x.month() == __y.month() && __x.day() == __y.day(); }
1966 friend constexpr strong_ordering
1967 operator<=>(const month_day& __x, const month_day& __y) noexcept
1970 friend constexpr month_day
1971 operator/(const chrono::month& __m, const chrono::day& __d) noexcept
1972 { return {__m, __d}; }
1974 friend constexpr month_day
1975 operator/(const chrono::month& __m, int __d) noexcept
1976 { return {__m, chrono::day(unsigned(__d))}; }
1978 friend constexpr month_day
1979 operator/(int __m, const chrono::day& __d) noexcept
1980 { return {chrono::month(unsigned(__m)), __d}; }
1982 friend constexpr month_day
1983 operator/(const chrono::day& __d, const chrono::month& __m) noexcept
1984 { return {__m, __d}; }
1986 friend constexpr month_day
1987 operator/(const chrono::day& __d, int __m) noexcept
1988 { return {chrono::month(unsigned(__m)), __d}; }
1990 friend constexpr year_month_day
1991 operator/(int __y, const month_day& __md) noexcept;
1993 friend constexpr year_month_day
1994 operator/(const month_day& __md, int __y) noexcept;
1996 // TODO: Implement operator<<, from_stream.
2001 class month_day_last
2008 month_day_last(const chrono::month& __m) noexcept
2012 constexpr chrono::month
2013 month() const noexcept
2018 { return _M_m.ok(); }
2020 friend constexpr bool
2021 operator==(const month_day_last& __x, const month_day_last& __y) noexcept
2022 { return __x.month() == __y.month(); }
2024 friend constexpr strong_ordering
2025 operator<=>(const month_day_last& __x, const month_day_last& __y) noexcept
2028 friend constexpr month_day_last
2029 operator/(const chrono::month& __m, last_spec) noexcept
2030 { return month_day_last{__m}; }
2032 friend constexpr month_day_last
2033 operator/(int __m, last_spec) noexcept
2034 { return chrono::month(unsigned(__m)) / last; }
2036 friend constexpr month_day_last
2037 operator/(last_spec, const chrono::month& __m) noexcept
2038 { return __m / last; }
2040 friend constexpr month_day_last
2041 operator/(last_spec, int __m) noexcept
2042 { return __m / last; }
2044 friend constexpr year_month_day_last
2045 operator/(int __y, const month_day_last& __mdl) noexcept;
2047 friend constexpr year_month_day_last
2048 operator/(const month_day_last& __mdl, int __y) noexcept;
2050 // TODO: Implement operator<<.
2059 chrono::weekday_indexed _M_wdi;
2063 month_weekday(const chrono::month& __m,
2064 const chrono::weekday_indexed& __wdi) noexcept
2065 : _M_m{__m}, _M_wdi{__wdi}
2068 constexpr chrono::month
2069 month() const noexcept
2072 constexpr chrono::weekday_indexed
2073 weekday_indexed() const noexcept
2078 { return _M_m.ok() && _M_wdi.ok(); }
2080 friend constexpr bool
2081 operator==(const month_weekday& __x, const month_weekday& __y) noexcept
2083 return __x.month() == __y.month()
2084 && __x.weekday_indexed() == __y.weekday_indexed();
2087 friend constexpr month_weekday
2088 operator/(const chrono::month& __m,
2089 const chrono::weekday_indexed& __wdi) noexcept
2090 { return {__m, __wdi}; }
2092 friend constexpr month_weekday
2093 operator/(int __m, const chrono::weekday_indexed& __wdi) noexcept
2094 { return chrono::month(unsigned(__m)) / __wdi; }
2096 friend constexpr month_weekday
2097 operator/(const chrono::weekday_indexed& __wdi,
2098 const chrono::month& __m) noexcept
2099 { return __m / __wdi; }
2101 friend constexpr month_weekday
2102 operator/(const chrono::weekday_indexed& __wdi, int __m) noexcept
2103 { return __m / __wdi; }
2105 friend constexpr year_month_weekday
2106 operator/(int __y, const month_weekday& __mwd) noexcept;
2108 friend constexpr year_month_weekday
2109 operator/(const month_weekday& __mwd, int __y) noexcept;
2111 // TODO: Implement operator<<.
2114 // MONTH_WEEKDAY_LAST
2116 class month_weekday_last
2120 chrono::weekday_last _M_wdl;
2124 month_weekday_last(const chrono::month& __m,
2125 const chrono::weekday_last& __wdl) noexcept
2126 :_M_m{__m}, _M_wdl{__wdl}
2129 constexpr chrono::month
2130 month() const noexcept
2133 constexpr chrono::weekday_last
2134 weekday_last() const noexcept
2139 { return _M_m.ok() && _M_wdl.ok(); }
2141 friend constexpr bool
2142 operator==(const month_weekday_last& __x,
2143 const month_weekday_last& __y) noexcept
2145 return __x.month() == __y.month()
2146 && __x.weekday_last() == __y.weekday_last();
2149 friend constexpr month_weekday_last
2150 operator/(const chrono::month& __m,
2151 const chrono::weekday_last& __wdl) noexcept
2152 { return {__m, __wdl}; }
2154 friend constexpr month_weekday_last
2155 operator/(int __m, const chrono::weekday_last& __wdl) noexcept
2156 { return chrono::month(unsigned(__m)) / __wdl; }
2158 friend constexpr month_weekday_last
2159 operator/(const chrono::weekday_last& __wdl,
2160 const chrono::month& __m) noexcept
2161 { return __m / __wdl; }
2163 friend constexpr month_weekday_last
2164 operator/(const chrono::weekday_last& __wdl, int __m) noexcept
2165 { return chrono::month(unsigned(__m)) / __wdl; }
2167 friend constexpr year_month_weekday_last
2168 operator/(int __y, const month_weekday_last& __mwdl) noexcept;
2170 friend constexpr year_month_weekday_last
2171 operator/(const month_weekday_last& __mwdl, int __y) noexcept;
2173 // TODO: Implement operator<<.
2180 // [time.cal.ym], [time.cal.ymd], etc constrain the 'months'-based
2181 // addition/subtraction operator overloads like so:
2183 // Constraints: if the argument supplied by the caller for the months
2184 // parameter is convertible to years, its implicit conversion sequence
2185 // to years is worse than its implicit conversion sequence to months.
2187 // We realize this constraint by templatizing the 'months'-based
2188 // overloads (using a dummy defaulted template parameter), so that
2189 // overload resolution doesn't select the 'months'-based overload unless
2190 // the implicit conversion sequence to 'months' is better than that to
2192 using __months_years_conversion_disambiguator = void;
2202 year_month() = default;
2205 year_month(const chrono::year& __y, const chrono::month& __m) noexcept
2206 : _M_y{__y}, _M_m{__m}
2209 constexpr chrono::year
2210 year() const noexcept
2213 constexpr chrono::month
2214 month() const noexcept
2217 template<typename = __detail::__months_years_conversion_disambiguator>
2218 constexpr year_month&
2219 operator+=(const months& __dm) noexcept
2221 *this = *this + __dm;
2225 template<typename = __detail::__months_years_conversion_disambiguator>
2226 constexpr year_month&
2227 operator-=(const months& __dm) noexcept
2229 *this = *this - __dm;
2233 constexpr year_month&
2234 operator+=(const years& __dy) noexcept
2236 *this = *this + __dy;
2240 constexpr year_month&
2241 operator-=(const years& __dy) noexcept
2243 *this = *this - __dy;
2249 { return _M_y.ok() && _M_m.ok(); }
2251 friend constexpr bool
2252 operator==(const year_month& __x, const year_month& __y) noexcept
2253 { return __x.year() == __y.year() && __x.month() == __y.month(); }
2255 friend constexpr strong_ordering
2256 operator<=>(const year_month& __x, const year_month& __y) noexcept
2259 template<typename = __detail::__months_years_conversion_disambiguator>
2260 friend constexpr year_month
2261 operator+(const year_month& __ym, const months& __dm) noexcept
2264 auto __m = __ym.month() + __dm;
2265 auto __i = int(unsigned(__ym.month())) - 1 + __dm.count();
2267 ? __ym.year() + years{(__i - 11) / 12}
2268 : __ym.year() + years{__i / 12});
2272 template<typename = __detail::__months_years_conversion_disambiguator>
2273 friend constexpr year_month
2274 operator+(const months& __dm, const year_month& __ym) noexcept
2275 { return __ym + __dm; }
2277 template<typename = __detail::__months_years_conversion_disambiguator>
2278 friend constexpr year_month
2279 operator-(const year_month& __ym, const months& __dm) noexcept
2280 { return __ym + -__dm; }
2282 friend constexpr months
2283 operator-(const year_month& __x, const year_month& __y) noexcept
2285 return (__x.year() - __y.year()
2286 + months{static_cast<int>(unsigned{__x.month()})
2287 - static_cast<int>(unsigned{__y.month()})});
2290 friend constexpr year_month
2291 operator+(const year_month& __ym, const years& __dy) noexcept
2292 { return (__ym.year() + __dy) / __ym.month(); }
2294 friend constexpr year_month
2295 operator+(const years& __dy, const year_month& __ym) noexcept
2296 { return __ym + __dy; }
2298 friend constexpr year_month
2299 operator-(const year_month& __ym, const years& __dy) noexcept
2300 { return __ym + -__dy; }
2302 friend constexpr year_month
2303 operator/(const chrono::year& __y, const chrono::month& __m) noexcept
2304 { return {__y, __m}; }
2306 friend constexpr year_month
2307 operator/(const chrono::year& __y, int __m) noexcept
2308 { return {__y, chrono::month(unsigned(__m))}; }
2310 friend constexpr year_month_day
2311 operator/(const year_month& __ym, int __d) noexcept;
2313 friend constexpr year_month_day_last
2314 operator/(const year_month& __ym, last_spec) noexcept;
2316 // TODO: Implement operator<<, from_stream.
2321 class year_month_day
2328 static constexpr year_month_day _S_from_days(const days& __dp) noexcept;
2330 constexpr days _M_days_since_epoch() const noexcept;
2333 year_month_day() = default;
2336 year_month_day(const chrono::year& __y, const chrono::month& __m,
2337 const chrono::day& __d) noexcept
2338 : _M_y{__y}, _M_m{__m}, _M_d{__d}
2342 year_month_day(const year_month_day_last& __ymdl) noexcept;
2345 year_month_day(const sys_days& __dp) noexcept
2346 : year_month_day(_S_from_days(__dp.time_since_epoch()))
2350 year_month_day(const local_days& __dp) noexcept
2351 : year_month_day(sys_days{__dp.time_since_epoch()})
2354 template<typename = __detail::__months_years_conversion_disambiguator>
2355 constexpr year_month_day&
2356 operator+=(const months& __m) noexcept
2358 *this = *this + __m;
2362 template<typename = __detail::__months_years_conversion_disambiguator>
2363 constexpr year_month_day&
2364 operator-=(const months& __m) noexcept
2366 *this = *this - __m;
2370 constexpr year_month_day&
2371 operator+=(const years& __y) noexcept
2373 *this = *this + __y;
2377 constexpr year_month_day&
2378 operator-=(const years& __y) noexcept
2380 *this = *this - __y;
2384 constexpr chrono::year
2385 year() const noexcept
2388 constexpr chrono::month
2389 month() const noexcept
2392 constexpr chrono::day
2393 day() const noexcept
2397 operator sys_days() const noexcept
2398 { return sys_days{_M_days_since_epoch()}; }
2401 operator local_days() const noexcept
2402 { return local_days{sys_days{*this}.time_since_epoch()}; }
2404 constexpr bool ok() const noexcept;
2406 friend constexpr bool
2407 operator==(const year_month_day& __x, const year_month_day& __y) noexcept
2409 return __x.year() == __y.year()
2410 && __x.month() == __y.month()
2411 && __x.day() == __y.day();
2414 friend constexpr strong_ordering
2415 operator<=>(const year_month_day& __x, const year_month_day& __y) noexcept
2418 template<typename = __detail::__months_years_conversion_disambiguator>
2419 friend constexpr year_month_day
2420 operator+(const year_month_day& __ymd, const months& __dm) noexcept
2421 { return (__ymd.year() / __ymd.month() + __dm) / __ymd.day(); }
2423 template<typename = __detail::__months_years_conversion_disambiguator>
2424 friend constexpr year_month_day
2425 operator+(const months& __dm, const year_month_day& __ymd) noexcept
2426 { return __ymd + __dm; }
2428 friend constexpr year_month_day
2429 operator+(const year_month_day& __ymd, const years& __dy) noexcept
2430 { return (__ymd.year() + __dy) / __ymd.month() / __ymd.day(); }
2432 friend constexpr year_month_day
2433 operator+(const years& __dy, const year_month_day& __ymd) noexcept
2434 { return __ymd + __dy; }
2436 template<typename = __detail::__months_years_conversion_disambiguator>
2437 friend constexpr year_month_day
2438 operator-(const year_month_day& __ymd, const months& __dm) noexcept
2439 { return __ymd + -__dm; }
2441 friend constexpr year_month_day
2442 operator-(const year_month_day& __ymd, const years& __dy) noexcept
2443 { return __ymd + -__dy; }
2445 friend constexpr year_month_day
2446 operator/(const year_month& __ym, const chrono::day& __d) noexcept
2447 { return {__ym.year(), __ym.month(), __d}; }
2449 friend constexpr year_month_day
2450 operator/(const year_month& __ym, int __d) noexcept
2451 { return __ym / chrono::day{unsigned(__d)}; }
2453 friend constexpr year_month_day
2454 operator/(const chrono::year& __y, const month_day& __md) noexcept
2455 { return __y / __md.month() / __md.day(); }
2457 friend constexpr year_month_day
2458 operator/(int __y, const month_day& __md) noexcept
2459 { return chrono::year{__y} / __md; }
2461 friend constexpr year_month_day
2462 operator/(const month_day& __md, const chrono::year& __y) noexcept
2463 { return __y / __md; }
2465 friend constexpr year_month_day
2466 operator/(const month_day& __md, int __y) noexcept
2467 { return chrono::year(__y) / __md; }
2469 // TODO: Implement operator<<, from_stream.
2472 // Construct from days since 1970/01/01.
2473 // Proposition 6.3 of Neri and Schneider,
2474 // "Euclidean Affine Functions and Applications to Calendar Algorithms".
2475 // https://arxiv.org/abs/2102.06959
2476 constexpr year_month_day
2477 year_month_day::_S_from_days(const days& __dp) noexcept
2479 constexpr auto __z2 = static_cast<uint32_t>(-1468000);
2480 constexpr auto __r2_e3 = static_cast<uint32_t>(536895458);
2482 const auto __r0 = static_cast<uint32_t>(__dp.count()) + __r2_e3;
2484 const auto __n1 = 4 * __r0 + 3;
2485 const auto __q1 = __n1 / 146097;
2486 const auto __r1 = __n1 % 146097 / 4;
2488 constexpr auto __p32 = static_cast<uint64_t>(1) << 32;
2489 const auto __n2 = 4 * __r1 + 3;
2490 const auto __u2 = static_cast<uint64_t>(2939745) * __n2;
2491 const auto __q2 = static_cast<uint32_t>(__u2 / __p32);
2492 const auto __r2 = static_cast<uint32_t>(__u2 % __p32) / 2939745 / 4;
2494 constexpr auto __p16 = static_cast<uint32_t>(1) << 16;
2495 const auto __n3 = 2141 * __r2 + 197913;
2496 const auto __q3 = __n3 / __p16;
2497 const auto __r3 = __n3 % __p16 / 2141;
2499 const auto __y0 = 100 * __q1 + __q2;
2500 const auto __m0 = __q3;
2501 const auto __d0 = __r3;
2503 const auto __j = __r2 >= 306;
2504 const auto __y1 = __y0 + __j;
2505 const auto __m1 = __j ? __m0 - 12 : __m0;
2506 const auto __d1 = __d0 + 1;
2508 return year_month_day{chrono::year{static_cast<int>(__y1 + __z2)},
2509 chrono::month{__m1}, chrono::day{__d1}};
2512 // Days since 1970/01/01.
2513 // Proposition 6.2 of Neri and Schneider,
2514 // "Euclidean Affine Functions and Applications to Calendar Algorithms".
2515 // https://arxiv.org/abs/2102.06959
2517 year_month_day::_M_days_since_epoch() const noexcept
2519 auto constexpr __z2 = static_cast<uint32_t>(-1468000);
2520 auto constexpr __r2_e3 = static_cast<uint32_t>(536895458);
2522 const auto __y1 = static_cast<uint32_t>(static_cast<int>(_M_y)) - __z2;
2523 const auto __m1 = static_cast<uint32_t>(static_cast<unsigned>(_M_m));
2524 const auto __d1 = static_cast<uint32_t>(static_cast<unsigned>(_M_d));
2526 const auto __j = static_cast<uint32_t>(__m1 < 3);
2527 const auto __y0 = __y1 - __j;
2528 const auto __m0 = __j ? __m1 + 12 : __m1;
2529 const auto __d0 = __d1 - 1;
2531 const auto __q1 = __y0 / 100;
2532 const auto __yc = 1461 * __y0 / 4 - __q1 + __q1 / 4;
2533 const auto __mc = (979 *__m0 - 2919) / 32;
2534 const auto __dc = __d0;
2536 return days{static_cast<int32_t>(__yc + __mc + __dc - __r2_e3)};
2539 // YEAR_MONTH_DAY_LAST
2541 class year_month_day_last
2545 chrono::month_day_last _M_mdl;
2549 year_month_day_last(const chrono::year& __y,
2550 const chrono::month_day_last& __mdl) noexcept
2551 : _M_y{__y}, _M_mdl{__mdl}
2554 template<typename = __detail::__months_years_conversion_disambiguator>
2555 constexpr year_month_day_last&
2556 operator+=(const months& __m) noexcept
2558 *this = *this + __m;
2562 template<typename = __detail::__months_years_conversion_disambiguator>
2563 constexpr year_month_day_last&
2564 operator-=(const months& __m) noexcept
2566 *this = *this - __m;
2570 constexpr year_month_day_last&
2571 operator+=(const years& __y) noexcept
2573 *this = *this + __y;
2577 constexpr year_month_day_last&
2578 operator-=(const years& __y) noexcept
2580 *this = *this - __y;
2584 constexpr chrono::year
2585 year() const noexcept
2588 constexpr chrono::month
2589 month() const noexcept
2590 { return _M_mdl.month(); }
2592 constexpr chrono::month_day_last
2593 month_day_last() const noexcept
2596 // Return A day representing the last day of this year, month pair.
2597 constexpr chrono::day
2598 day() const noexcept
2600 const auto __m = static_cast<unsigned>(month());
2602 // Excluding February, the last day of month __m is either 30 or 31 or,
2603 // in another words, it is 30 + b = 30 | b, where b is in {0, 1}.
2605 // If __m in {1, 3, 4, 5, 6, 7}, then b is 1 if, and only if __m is odd.
2606 // Hence, b = __m & 1 = (__m ^ 0) & 1.
2608 // If __m in {8, 9, 10, 11, 12}, then b is 1 if, and only if __m is even.
2609 // Hence, b = (__m ^ 1) & 1.
2611 // Therefore, b = (__m ^ c) & 1, where c = 0, if __m < 8, or c = 1 if
2612 // __m >= 8, that is, c = __m >> 3.
2614 // The above mathematically justifies this implementation whose
2615 // performance does not depend on look-up tables being on the L1 cache.
2616 return chrono::day{__m != 2 ? ((__m ^ (__m >> 3)) & 1) | 30
2617 : _M_y.is_leap() ? 29 : 28};
2621 operator sys_days() const noexcept
2622 { return sys_days{year() / month() / day()}; }
2625 operator local_days() const noexcept
2626 { return local_days{sys_days{*this}.time_since_epoch()}; }
2630 { return _M_y.ok() && _M_mdl.ok(); }
2632 friend constexpr bool
2633 operator==(const year_month_day_last& __x,
2634 const year_month_day_last& __y) noexcept
2636 return __x.year() == __y.year()
2637 && __x.month_day_last() == __y.month_day_last();
2640 friend constexpr strong_ordering
2641 operator<=>(const year_month_day_last& __x,
2642 const year_month_day_last& __y) noexcept
2645 template<typename = __detail::__months_years_conversion_disambiguator>
2646 friend constexpr year_month_day_last
2647 operator+(const year_month_day_last& __ymdl,
2648 const months& __dm) noexcept
2649 { return (__ymdl.year() / __ymdl.month() + __dm) / last; }
2651 template<typename = __detail::__months_years_conversion_disambiguator>
2652 friend constexpr year_month_day_last
2653 operator+(const months& __dm,
2654 const year_month_day_last& __ymdl) noexcept
2655 { return __ymdl + __dm; }
2657 template<typename = __detail::__months_years_conversion_disambiguator>
2658 friend constexpr year_month_day_last
2659 operator-(const year_month_day_last& __ymdl,
2660 const months& __dm) noexcept
2661 { return __ymdl + -__dm; }
2663 friend constexpr year_month_day_last
2664 operator+(const year_month_day_last& __ymdl,
2665 const years& __dy) noexcept
2666 { return {__ymdl.year() + __dy, __ymdl.month_day_last()}; }
2668 friend constexpr year_month_day_last
2669 operator+(const years& __dy,
2670 const year_month_day_last& __ymdl) noexcept
2671 { return __ymdl + __dy; }
2673 friend constexpr year_month_day_last
2674 operator-(const year_month_day_last& __ymdl,
2675 const years& __dy) noexcept
2676 { return __ymdl + -__dy; }
2678 friend constexpr year_month_day_last
2679 operator/(const year_month& __ym, last_spec) noexcept
2680 { return {__ym.year(), chrono::month_day_last{__ym.month()}}; }
2682 friend constexpr year_month_day_last
2683 operator/(const chrono::year& __y,
2684 const chrono::month_day_last& __mdl) noexcept
2685 { return {__y, __mdl}; }
2687 friend constexpr year_month_day_last
2688 operator/(int __y, const chrono::month_day_last& __mdl) noexcept
2689 { return chrono::year(__y) / __mdl; }
2691 friend constexpr year_month_day_last
2692 operator/(const chrono::month_day_last& __mdl,
2693 const chrono::year& __y) noexcept
2694 { return __y / __mdl; }
2696 friend constexpr year_month_day_last
2697 operator/(const chrono::month_day_last& __mdl, int __y) noexcept
2698 { return chrono::year(__y) / __mdl; }
2700 // TODO: Implement operator<<.
2703 // year_month_day ctor from year_month_day_last
2705 year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
2706 : _M_y{__ymdl.year()}, _M_m{__ymdl.month()}, _M_d{__ymdl.day()}
2710 year_month_day::ok() const noexcept
2712 if (!_M_y.ok() || !_M_m.ok())
2714 return chrono::day{1} <= _M_d && _M_d <= (_M_y / _M_m / last).day();
2717 // YEAR_MONTH_WEEKDAY
2719 class year_month_weekday
2724 chrono::weekday_indexed _M_wdi;
2726 static constexpr year_month_weekday
2727 _S_from_sys_days(const sys_days& __dp)
2729 year_month_day __ymd{__dp};
2730 chrono::weekday __wd{__dp};
2731 auto __index = __wd[(unsigned{__ymd.day()} - 1) / 7 + 1];
2732 return {__ymd.year(), __ymd.month(), __index};
2736 year_month_weekday() = default;
2739 year_month_weekday(const chrono::year& __y, const chrono::month& __m,
2740 const chrono::weekday_indexed& __wdi) noexcept
2741 : _M_y{__y}, _M_m{__m}, _M_wdi{__wdi}
2745 year_month_weekday(const sys_days& __dp) noexcept
2746 : year_month_weekday{_S_from_sys_days(__dp)}
2750 year_month_weekday(const local_days& __dp) noexcept
2751 : year_month_weekday{sys_days{__dp.time_since_epoch()}}
2754 template<typename = __detail::__months_years_conversion_disambiguator>
2755 constexpr year_month_weekday&
2756 operator+=(const months& __m) noexcept
2758 *this = *this + __m;
2762 template<typename = __detail::__months_years_conversion_disambiguator>
2763 constexpr year_month_weekday&
2764 operator-=(const months& __m) noexcept
2766 *this = *this - __m;
2770 constexpr year_month_weekday&
2771 operator+=(const years& __y) noexcept
2773 *this = *this + __y;
2777 constexpr year_month_weekday&
2778 operator-=(const years& __y) noexcept
2780 *this = *this - __y;
2784 constexpr chrono::year
2785 year() const noexcept
2788 constexpr chrono::month
2789 month() const noexcept
2792 constexpr chrono::weekday
2793 weekday() const noexcept
2794 { return _M_wdi.weekday(); }
2797 index() const noexcept
2798 { return _M_wdi.index(); }
2800 constexpr chrono::weekday_indexed
2801 weekday_indexed() const noexcept
2805 operator sys_days() const noexcept
2807 auto __d = sys_days{year() / month() / 1};
2808 return __d + (weekday() - chrono::weekday(__d)
2809 + days{(static_cast<int>(index())-1)*7});
2813 operator local_days() const noexcept
2814 { return local_days{sys_days{*this}.time_since_epoch()}; }
2819 if (!_M_y.ok() || !_M_m.ok() || !_M_wdi.ok())
2821 if (_M_wdi.index() <= 4)
2823 days __d = (_M_wdi.weekday()
2824 - chrono::weekday{sys_days{_M_y / _M_m / 1}}
2825 + days((_M_wdi.index()-1)*7 + 1));
2826 __glibcxx_assert(__d.count() >= 1);
2827 return __d.count() <= unsigned{(_M_y / _M_m / last).day()};
2830 friend constexpr bool
2831 operator==(const year_month_weekday& __x,
2832 const year_month_weekday& __y) noexcept
2834 return __x.year() == __y.year()
2835 && __x.month() == __y.month()
2836 && __x.weekday_indexed() == __y.weekday_indexed();
2839 template<typename = __detail::__months_years_conversion_disambiguator>
2840 friend constexpr year_month_weekday
2841 operator+(const year_month_weekday& __ymwd, const months& __dm) noexcept
2843 return ((__ymwd.year() / __ymwd.month() + __dm)
2844 / __ymwd.weekday_indexed());
2847 template<typename = __detail::__months_years_conversion_disambiguator>
2848 friend constexpr year_month_weekday
2849 operator+(const months& __dm, const year_month_weekday& __ymwd) noexcept
2850 { return __ymwd + __dm; }
2852 friend constexpr year_month_weekday
2853 operator+(const year_month_weekday& __ymwd, const years& __dy) noexcept
2854 { return {__ymwd.year() + __dy, __ymwd.month(), __ymwd.weekday_indexed()}; }
2856 friend constexpr year_month_weekday
2857 operator+(const years& __dy, const year_month_weekday& __ymwd) noexcept
2858 { return __ymwd + __dy; }
2860 template<typename = __detail::__months_years_conversion_disambiguator>
2861 friend constexpr year_month_weekday
2862 operator-(const year_month_weekday& __ymwd, const months& __dm) noexcept
2863 { return __ymwd + -__dm; }
2865 friend constexpr year_month_weekday
2866 operator-(const year_month_weekday& __ymwd, const years& __dy) noexcept
2867 { return __ymwd + -__dy; }
2869 friend constexpr year_month_weekday
2870 operator/(const year_month& __ym,
2871 const chrono::weekday_indexed& __wdi) noexcept
2872 { return {__ym.year(), __ym.month(), __wdi}; }
2874 friend constexpr year_month_weekday
2875 operator/(const chrono::year& __y, const month_weekday& __mwd) noexcept
2876 { return {__y, __mwd.month(), __mwd.weekday_indexed()}; }
2878 friend constexpr year_month_weekday
2879 operator/(int __y, const month_weekday& __mwd) noexcept
2880 { return chrono::year(__y) / __mwd; }
2882 friend constexpr year_month_weekday
2883 operator/(const month_weekday& __mwd, const chrono::year& __y) noexcept
2884 { return __y / __mwd; }
2886 friend constexpr year_month_weekday
2887 operator/(const month_weekday& __mwd, int __y) noexcept
2888 { return chrono::year(__y) / __mwd; }
2890 // TODO: Implement operator<<.
2893 // YEAR_MONTH_WEEKDAY_LAST
2895 class year_month_weekday_last
2900 chrono::weekday_last _M_wdl;
2904 year_month_weekday_last(const chrono::year& __y, const chrono::month& __m,
2905 const chrono::weekday_last& __wdl) noexcept
2906 : _M_y{__y}, _M_m{__m}, _M_wdl{__wdl}
2909 template<typename = __detail::__months_years_conversion_disambiguator>
2910 constexpr year_month_weekday_last&
2911 operator+=(const months& __m) noexcept
2913 *this = *this + __m;
2917 template<typename = __detail::__months_years_conversion_disambiguator>
2918 constexpr year_month_weekday_last&
2919 operator-=(const months& __m) noexcept
2921 *this = *this - __m;
2925 constexpr year_month_weekday_last&
2926 operator+=(const years& __y) noexcept
2928 *this = *this + __y;
2932 constexpr year_month_weekday_last&
2933 operator-=(const years& __y) noexcept
2935 *this = *this - __y;
2939 constexpr chrono::year
2940 year() const noexcept
2943 constexpr chrono::month
2944 month() const noexcept
2947 constexpr chrono::weekday
2948 weekday() const noexcept
2949 { return _M_wdl.weekday(); }
2951 constexpr chrono::weekday_last
2952 weekday_last() const noexcept
2956 operator sys_days() const noexcept
2958 const auto __d = sys_days{_M_y / _M_m / last};
2959 return sys_days{(__d - (chrono::weekday{__d}
2960 - _M_wdl.weekday())).time_since_epoch()};
2964 operator local_days() const noexcept
2965 { return local_days{sys_days{*this}.time_since_epoch()}; }
2969 { return _M_y.ok() && _M_m.ok() && _M_wdl.ok(); }
2971 friend constexpr bool
2972 operator==(const year_month_weekday_last& __x,
2973 const year_month_weekday_last& __y) noexcept
2975 return __x.year() == __y.year()
2976 && __x.month() == __y.month()
2977 && __x.weekday_last() == __y.weekday_last();
2980 template<typename = __detail::__months_years_conversion_disambiguator>
2981 friend constexpr year_month_weekday_last
2982 operator+(const year_month_weekday_last& __ymwdl,
2983 const months& __dm) noexcept
2985 return ((__ymwdl.year() / __ymwdl.month() + __dm)
2986 / __ymwdl.weekday_last());
2989 template<typename = __detail::__months_years_conversion_disambiguator>
2990 friend constexpr year_month_weekday_last
2991 operator+(const months& __dm,
2992 const year_month_weekday_last& __ymwdl) noexcept
2993 { return __ymwdl + __dm; }
2995 friend constexpr year_month_weekday_last
2996 operator+(const year_month_weekday_last& __ymwdl,
2997 const years& __dy) noexcept
2998 { return {__ymwdl.year() + __dy, __ymwdl.month(), __ymwdl.weekday_last()}; }
3000 friend constexpr year_month_weekday_last
3001 operator+(const years& __dy,
3002 const year_month_weekday_last& __ymwdl) noexcept
3003 { return __ymwdl + __dy; }
3005 template<typename = __detail::__months_years_conversion_disambiguator>
3006 friend constexpr year_month_weekday_last
3007 operator-(const year_month_weekday_last& __ymwdl,
3008 const months& __dm) noexcept
3009 { return __ymwdl + -__dm; }
3011 friend constexpr year_month_weekday_last
3012 operator-(const year_month_weekday_last& __ymwdl,
3013 const years& __dy) noexcept
3014 { return __ymwdl + -__dy; }
3016 friend constexpr year_month_weekday_last
3017 operator/(const year_month& __ym,
3018 const chrono::weekday_last& __wdl) noexcept
3019 { return {__ym.year(), __ym.month(), __wdl}; }
3021 friend constexpr year_month_weekday_last
3022 operator/(const chrono::year& __y,
3023 const chrono::month_weekday_last& __mwdl) noexcept
3024 { return {__y, __mwdl.month(), __mwdl.weekday_last()}; }
3026 friend constexpr year_month_weekday_last
3027 operator/(int __y, const chrono::month_weekday_last& __mwdl) noexcept
3028 { return chrono::year(__y) / __mwdl; }
3030 friend constexpr year_month_weekday_last
3031 operator/(const chrono::month_weekday_last& __mwdl,
3032 const chrono::year& __y) noexcept
3033 { return __y / __mwdl; }
3035 friend constexpr year_month_weekday_last
3036 operator/(const chrono::month_weekday_last& __mwdl, int __y) noexcept
3037 { return chrono::year(__y) / __mwdl; }
3039 // TODO: Implement operator<<.
3047 __pow10(unsigned __n)
3056 template<typename _Duration>
3060 static constexpr int
3061 _S_fractional_width()
3063 int __multiplicity_2 = 0;
3064 int __multiplicity_5 = 0;
3065 auto __den = _Duration::period::den;
3066 while ((__den % 2) == 0)
3071 while ((__den % 5) == 0)
3079 int __width = (__multiplicity_2 > __multiplicity_5
3080 ? __multiplicity_2 : __multiplicity_5);
3087 hh_mm_ss(_Duration __d, bool __is_neg)
3088 : _M_is_neg(__is_neg),
3089 _M_h (duration_cast<chrono::hours>(__d)),
3090 _M_m (duration_cast<chrono::minutes>(__d - hours())),
3091 _M_s (duration_cast<chrono::seconds>(__d - hours() - minutes()))
3093 auto __ss = __d - hours() - minutes() - seconds();
3094 if constexpr (treat_as_floating_point_v<typename precision::rep>)
3097 _M_ss = duration_cast<precision>(__ss);
3100 static constexpr _Duration
3101 _S_abs(_Duration __d)
3103 if constexpr (numeric_limits<typename _Duration::rep>::is_signed)
3104 return chrono::abs(__d);
3110 static constexpr unsigned fractional_width = {_S_fractional_width()};
3113 = duration<common_type_t<typename _Duration::rep,
3114 chrono::seconds::rep>,
3115 ratio<1, __detail::__pow10(fractional_width)>>;
3119 : hh_mm_ss{_Duration::zero()}
3123 hh_mm_ss(_Duration __d)
3124 : hh_mm_ss(_S_abs(__d), __d < _Duration::zero())
3128 is_negative() const noexcept
3129 { return _M_is_neg; }
3131 constexpr chrono::hours
3132 hours() const noexcept
3135 constexpr chrono::minutes
3136 minutes() const noexcept
3139 constexpr chrono::seconds
3140 seconds() const noexcept
3144 subseconds() const noexcept
3148 operator precision() const noexcept
3149 { return to_duration(); }
3152 to_duration() const noexcept
3155 return -(_M_h + _M_m + _M_s + _M_ss);
3157 return _M_h + _M_m + _M_s + _M_ss;
3160 // TODO: Implement operator<<.
3165 chrono::minutes _M_m;
3166 chrono::seconds _M_s;
3172 } // namespace chrono
3174#if __cplusplus > 201103L
3176#define __cpp_lib_chrono_udls 201304
3178 inline namespace literals
3180 /** ISO C++ 2014 namespace for suffixes for duration literals.
3182 * These suffixes can be used to create `chrono::duration` values with
3183 * tick periods of hours, minutes, seconds, milliseconds, microseconds
3184 * or nanoseconds. For example, `std::chrono::seconds(5)` can be written
3185 * as `5s` after making the suffix visible in the current scope.
3186 * The suffixes can be made visible by a using-directive or
3187 * using-declaration such as:
3188 * - `using namespace std::chrono_literals;`
3189 * - `using namespace std::literals;`
3190 * - `using namespace std::chrono;`
3191 * - `using namespace std;`
3192 * - `using std::chrono_literals::operator""s;`
3194 * The result of these suffixes on an integer literal is one of the
3195 * standard typedefs such as `std::chrono::hours`.
3196 * The result on a floating-point literal is a duration type with the
3197 * specified tick period and an unspecified floating-point representation,
3198 * for example `1.5e2ms` might be equivalent to
3199 * `chrono::duration<long double, chrono::milli>(1.5e2)`.
3203 inline namespace chrono_literals
3205 /// @addtogroup chrono
3208#pragma GCC diagnostic push
3209#pragma GCC diagnostic ignored "-Wliteral-suffix"
3210 /// @cond undocumented
3211 template<typename _Dur, char... _Digits>
3212 constexpr _Dur __check_overflow()
3214 using _Val = __parse_int::_Parse_int<_Digits...>;
3215 constexpr typename _Dur::rep __repval = _Val::value;
3216 static_assert(__repval >= 0 && __repval == _Val::value,
3217 "literal value cannot be represented by duration type");
3218 return _Dur(__repval);
3222 /// Literal suffix for durations representing non-integer hours
3223 constexpr chrono::duration<long double, ratio<3600,1>>
3224 operator""h(long double __hours)
3225 { return chrono::duration<long double, ratio<3600,1>>{__hours}; }
3227 /// Literal suffix for durations of type `std::chrono::hours`
3228 template <char... _Digits>
3229 constexpr chrono::hours
3231 { return __check_overflow<chrono::hours, _Digits...>(); }
3233 /// Literal suffix for durations representing non-integer minutes
3234 constexpr chrono::duration<long double, ratio<60,1>>
3235 operator""min(long double __mins)
3236 { return chrono::duration<long double, ratio<60,1>>{__mins}; }
3238 /// Literal suffix for durations of type `std::chrono::minutes`
3239 template <char... _Digits>
3240 constexpr chrono::minutes
3242 { return __check_overflow<chrono::minutes, _Digits...>(); }
3244 /// Literal suffix for durations representing non-integer seconds
3245 constexpr chrono::duration<long double>
3246 operator""s(long double __secs)
3247 { return chrono::duration<long double>{__secs}; }
3249 /// Literal suffix for durations of type `std::chrono::seconds`
3250 template <char... _Digits>
3251 constexpr chrono::seconds
3253 { return __check_overflow<chrono::seconds, _Digits...>(); }
3255 /// Literal suffix for durations representing non-integer milliseconds
3256 constexpr chrono::duration<long double, milli>
3257 operator""ms(long double __msecs)
3258 { return chrono::duration<long double, milli>{__msecs}; }
3260 /// Literal suffix for durations of type `std::chrono::milliseconds`
3261 template <char... _Digits>
3262 constexpr chrono::milliseconds
3264 { return __check_overflow<chrono::milliseconds, _Digits...>(); }
3266 /// Literal suffix for durations representing non-integer microseconds
3267 constexpr chrono::duration<long double, micro>
3268 operator""us(long double __usecs)
3269 { return chrono::duration<long double, micro>{__usecs}; }
3271 /// Literal suffix for durations of type `std::chrono::microseconds`
3272 template <char... _Digits>
3273 constexpr chrono::microseconds
3275 { return __check_overflow<chrono::microseconds, _Digits...>(); }
3277 /// Literal suffix for durations representing non-integer nanoseconds
3278 constexpr chrono::duration<long double, nano>
3279 operator""ns(long double __nsecs)
3280 { return chrono::duration<long double, nano>{__nsecs}; }
3282 /// Literal suffix for durations of type `std::chrono::nanoseconds`
3283 template <char... _Digits>
3284 constexpr chrono::nanoseconds
3286 { return __check_overflow<chrono::nanoseconds, _Digits...>(); }
3288#if __cplusplus > 201703L
3289 constexpr chrono::day
3290 operator""d(unsigned long long __d) noexcept
3291 { return chrono::day{static_cast<unsigned>(__d)}; }
3293 constexpr chrono::year
3294 operator""y(unsigned long long __y) noexcept
3295 { return chrono::year{static_cast<int>(__y)}; }
3298#pragma GCC diagnostic pop
3300 } // inline namespace chrono_literals
3301 } // inline namespace literals
3305 using namespace literals::chrono_literals;
3306 } // namespace chrono
3308#if __cplusplus > 201703L
3311 /// @addtogroup chrono
3314 // 12/24 HOURS FUNCTIONS
3317 is_am(const hours& __h) noexcept
3318 { return 0h <= __h && __h <= 11h; }
3321 is_pm(const hours& __h) noexcept
3322 { return 12h <= __h && __h <= 23h; }
3325 make12(const hours& __h) noexcept
3335 make24(const hours& __h, bool __is_pm) noexcept
3353 } // namespace chrono
3356#if __cplusplus >= 201703L
3357 namespace filesystem
3361 using duration = chrono::nanoseconds;
3362 using rep = duration::rep;
3363 using period = duration::period;
3364 using time_point = chrono::time_point<__file_clock>;
3365 static constexpr bool is_steady = false;
3369 { return _S_from_sys(chrono::system_clock::now()); }
3371#if __cplusplus > 201703L
3372 template<typename _Dur>
3374 chrono::file_time<_Dur>
3375 from_sys(const chrono::sys_time<_Dur>& __t) noexcept
3376 { return _S_from_sys(__t); }
3378 // For internal use only
3379 template<typename _Dur>
3381 chrono::sys_time<_Dur>
3382 to_sys(const chrono::file_time<_Dur>& __t) noexcept
3383 { return _S_to_sys(__t); }
3387 using __sys_clock = chrono::system_clock;
3389 // This clock's (unspecified) epoch is 2174-01-01 00:00:00 UTC.
3390 // A signed 64-bit duration with nanosecond resolution gives roughly
3391 // +/- 292 years, which covers the 1901-2446 date range for ext4.
3392 static constexpr chrono::seconds _S_epoch_diff{6437664000};
3395 // For internal use only
3396 template<typename _Dur>
3398 chrono::time_point<__file_clock, _Dur>
3399 _S_from_sys(const chrono::time_point<__sys_clock, _Dur>& __t) noexcept
3401 using __file_time = chrono::time_point<__file_clock, _Dur>;
3402 return __file_time{__t.time_since_epoch()} - _S_epoch_diff;
3405 // For internal use only
3406 template<typename _Dur>
3408 chrono::time_point<__sys_clock, _Dur>
3409 _S_to_sys(const chrono::time_point<__file_clock, _Dur>& __t) noexcept
3411 using __sys_time = chrono::time_point<__sys_clock, _Dur>;
3412 return __sys_time{__t.time_since_epoch()} + _S_epoch_diff;
3415 } // namespace filesystem
3419_GLIBCXX_END_NAMESPACE_VERSION
3424#endif //_GLIBCXX_CHRONO