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;
1142 _GLIBCXX_TIME_BITS64_ABI_TAG
1144 to_time_t(const time_point& __t) noexcept
1146 return std::time_t(duration_cast<chrono::seconds>
1147 (__t.time_since_epoch()).count());
1150 _GLIBCXX_TIME_BITS64_ABI_TAG
1152 from_time_t(std::time_t __t) noexcept
1154 typedef chrono::time_point<system_clock, seconds> __from;
1155 return time_point_cast<system_clock::duration>
1156 (__from(chrono::seconds(__t)));
1162 * @brief Monotonic clock
1164 * Time returned has the property of only increasing at a uniform rate.
1169 typedef chrono::nanoseconds duration;
1170 typedef duration::rep rep;
1171 typedef duration::period period;
1172 typedef chrono::time_point<steady_clock, duration> time_point;
1174 static constexpr bool is_steady = true;
1182 * @brief Highest-resolution clock
1184 * This is the clock "with the shortest tick period." Alias to
1185 * std::system_clock until higher-than-nanosecond definitions
1189 using high_resolution_clock = system_clock;
1191 } // end inline namespace _V2
1193#if __cplusplus > 201703L
1194 template<typename _Duration>
1195 using sys_time = time_point<system_clock, _Duration>;
1196 using sys_seconds = sys_time<seconds>;
1197 using sys_days = sys_time<days>;
1199 using file_clock = ::std::filesystem::__file_clock;
1201 template<typename _Duration>
1202 using file_time = time_point<file_clock, _Duration>;
1204 template<> struct is_clock<system_clock> : true_type { };
1205 template<> struct is_clock<steady_clock> : true_type { };
1206 template<> struct is_clock<file_clock> : true_type { };
1208 template<> inline constexpr bool is_clock_v<system_clock> = true;
1209 template<> inline constexpr bool is_clock_v<steady_clock> = true;
1210 template<> inline constexpr bool is_clock_v<file_clock> = true;
1213 template<typename _Duration>
1214 using local_time = time_point<local_t, _Duration>;
1215 using local_seconds = local_time<seconds>;
1216 using local_days = local_time<days>;
1222 template<typename _Duration>
1223 using utc_time = time_point<utc_clock, _Duration>;
1224 using utc_seconds = utc_time<seconds>;
1226 template<typename _Duration>
1227 using tai_time = time_point<tai_clock, _Duration>;
1228 using tai_seconds = tai_time<seconds>;
1230 template<typename _Duration>
1231 using gps_time = time_point<gps_clock, _Duration>;
1232 using gps_seconds = gps_time<seconds>;
1234 template<> struct is_clock<utc_clock> : true_type { };
1235 template<> struct is_clock<tai_clock> : true_type { };
1236 template<> struct is_clock<gps_clock> : true_type { };
1238 template<> inline constexpr bool is_clock_v<utc_clock> = true;
1239 template<> inline constexpr bool is_clock_v<tai_clock> = true;
1240 template<> inline constexpr bool is_clock_v<gps_clock> = true;
1242 struct leap_second_info
1244 bool is_leap_second;
1248 // CALENDRICAL TYPES
1250 // CLASS DECLARATIONS
1255 class weekday_indexed;
1258 class month_day_last;
1259 class month_weekday;
1260 class month_weekday_last;
1262 class year_month_day;
1263 class year_month_day_last;
1264 class year_month_weekday;
1265 class year_month_weekday_last;
1269 explicit last_spec() = default;
1271 friend constexpr month_day_last
1272 operator/(int __m, last_spec) noexcept;
1274 friend constexpr month_day_last
1275 operator/(last_spec, int __m) noexcept;
1278 inline constexpr last_spec last{};
1282 // Compute the remainder of the Euclidean division of __n divided by __d.
1283 // Euclidean division truncates toward negative infinity and always
1284 // produces a remainder in the range of [0,__d-1] (whereas standard
1285 // division truncates toward zero and yields a nonpositive remainder
1286 // for negative __n).
1288 __modulo(long long __n, unsigned __d)
1293 return (__d + (__n % __d)) % __d;
1296 inline constexpr unsigned __days_per_month[12]
1297 = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
1311 day(unsigned __d) noexcept
1316 operator++() noexcept
1323 operator++(int) noexcept
1331 operator--() noexcept
1338 operator--(int) noexcept
1346 operator+=(const days& __d) noexcept
1348 *this = *this + __d;
1353 operator-=(const days& __d) noexcept
1355 *this = *this - __d;
1360 operator unsigned() const noexcept
1365 { return 1 <= _M_d && _M_d <= 31; }
1367 friend constexpr bool
1368 operator==(const day& __x, const day& __y) noexcept
1369 { return unsigned{__x} == unsigned{__y}; }
1371 friend constexpr strong_ordering
1372 operator<=>(const day& __x, const day& __y) noexcept
1373 { return unsigned{__x} <=> unsigned{__y}; }
1375 friend constexpr day
1376 operator+(const day& __x, const days& __y) noexcept
1377 { return day(unsigned{__x} + __y.count()); }
1379 friend constexpr day
1380 operator+(const days& __x, const day& __y) noexcept
1381 { return __y + __x; }
1383 friend constexpr day
1384 operator-(const day& __x, const days& __y) noexcept
1385 { return __x + -__y; }
1387 friend constexpr days
1388 operator-(const day& __x, const day& __y) noexcept
1389 { return days{int(unsigned{__x}) - int(unsigned{__y})}; }
1391 friend constexpr month_day
1392 operator/(const month& __m, const day& __d) noexcept;
1394 friend constexpr month_day
1395 operator/(int __m, const day& __d) noexcept;
1397 friend constexpr month_day
1398 operator/(const day& __d, const month& __m) noexcept;
1400 friend constexpr month_day
1401 operator/(const day& __d, int __m) noexcept;
1403 friend constexpr year_month_day
1404 operator/(const year_month& __ym, const day& __d) noexcept;
1406 // TODO: Implement operator<<, to_stream, from_stream.
1420 month(unsigned __m) noexcept
1425 operator++() noexcept
1432 operator++(int) noexcept
1440 operator--() noexcept
1447 operator--(int) noexcept
1455 operator+=(const months& __m) noexcept
1457 *this = *this + __m;
1462 operator-=(const months& __m) noexcept
1464 *this = *this - __m;
1469 operator unsigned() const noexcept
1474 { return 1 <= _M_m && _M_m <= 12; }
1476 friend constexpr bool
1477 operator==(const month& __x, const month& __y) noexcept
1478 { return unsigned{__x} == unsigned{__y}; }
1480 friend constexpr strong_ordering
1481 operator<=>(const month& __x, const month& __y) noexcept
1482 { return unsigned{__x} <=> unsigned{__y}; }
1484 friend constexpr month
1485 operator+(const month& __x, const months& __y) noexcept
1487 auto __n = static_cast<long long>(unsigned{__x}) + (__y.count() - 1);
1488 return month{__detail::__modulo(__n, 12) + 1};
1491 friend constexpr month
1492 operator+(const months& __x, const month& __y) noexcept
1493 { return __y + __x; }
1495 friend constexpr month
1496 operator-(const month& __x, const months& __y) noexcept
1497 { return __x + -__y; }
1499 friend constexpr months
1500 operator-(const month& __x, const month& __y) noexcept
1502 const auto __dm = int(unsigned(__x)) - int(unsigned(__y));
1503 return months{__dm < 0 ? 12 + __dm : __dm};
1506 friend constexpr year_month
1507 operator/(const year& __y, const month& __m) noexcept;
1509 friend constexpr month_day
1510 operator/(const month& __m, int __d) noexcept;
1512 friend constexpr month_day_last
1513 operator/(const month& __m, last_spec) noexcept;
1515 friend constexpr month_day_last
1516 operator/(last_spec, const month& __m) noexcept;
1518 friend constexpr month_weekday
1519 operator/(const month& __m, const weekday_indexed& __wdi) noexcept;
1521 friend constexpr month_weekday
1522 operator/(const weekday_indexed& __wdi, const month& __m) noexcept;
1524 friend constexpr month_weekday_last
1525 operator/(const month& __m, const weekday_last& __wdl) noexcept;
1527 friend constexpr month_weekday_last
1528 operator/(const weekday_last& __wdl, const month& __m) noexcept;
1530 // TODO: Implement operator<<, to_stream, from_stream.
1533 inline constexpr month January{1};
1534 inline constexpr month February{2};
1535 inline constexpr month March{3};
1536 inline constexpr month April{4};
1537 inline constexpr month May{5};
1538 inline constexpr month June{6};
1539 inline constexpr month July{7};
1540 inline constexpr month August{8};
1541 inline constexpr month September{9};
1542 inline constexpr month October{10};
1543 inline constexpr month November{11};
1544 inline constexpr month December{12};
1557 year(int __y) noexcept
1558 : _M_y{static_cast<short>(__y)}
1561 static constexpr year
1563 { return year{-32767}; }
1565 static constexpr year
1567 { return year{32767}; }
1570 operator++() noexcept
1577 operator++(int) noexcept
1585 operator--() noexcept
1592 operator--(int) noexcept
1600 operator+=(const years& __y) noexcept
1602 *this = *this + __y;
1607 operator-=(const years& __y) noexcept
1609 *this = *this - __y;
1614 operator+() const noexcept
1618 operator-() const noexcept
1619 { return year{-_M_y}; }
1622 is_leap() const noexcept
1624 // Testing divisibility by 100 first gives better performance, that is,
1625 // return (_M_y % 100 != 0 || _M_y % 400 == 0) && _M_y % 4 == 0;
1627 // It gets even faster if _M_y is in [-536870800, 536870999]
1628 // (which is the case here) and _M_y % 100 is replaced by
1629 // __is_multiple_of_100 below.
1632 // [1] https://github.com/cassioneri/calendar
1633 // [2] https://accu.org/journals/overload/28/155/overload155.pdf#page=16
1635 constexpr uint32_t __multiplier = 42949673;
1636 constexpr uint32_t __bound = 42949669;
1637 constexpr uint32_t __max_dividend = 1073741799;
1638 constexpr uint32_t __offset = __max_dividend / 2 / 100 * 100;
1639 const bool __is_multiple_of_100
1640 = __multiplier * (_M_y + __offset) < __bound;
1641 return (!__is_multiple_of_100 || _M_y % 400 == 0) && _M_y % 4 == 0;
1645 operator int() const noexcept
1650 { return min()._M_y <= _M_y && _M_y <= max()._M_y; }
1652 friend constexpr bool
1653 operator==(const year& __x, const year& __y) noexcept
1654 { return int{__x} == int{__y}; }
1656 friend constexpr strong_ordering
1657 operator<=>(const year& __x, const year& __y) noexcept
1658 { return int{__x} <=> int{__y}; }
1660 friend constexpr year
1661 operator+(const year& __x, const years& __y) noexcept
1662 { return year{int{__x} + static_cast<int>(__y.count())}; }
1664 friend constexpr year
1665 operator+(const years& __x, const year& __y) noexcept
1666 { return __y + __x; }
1668 friend constexpr year
1669 operator-(const year& __x, const years& __y) noexcept
1670 { return __x + -__y; }
1672 friend constexpr years
1673 operator-(const year& __x, const year& __y) noexcept
1674 { return years{int{__x} - int{__y}}; }
1676 friend constexpr year_month
1677 operator/(const year& __y, int __m) noexcept;
1679 friend constexpr year_month_day
1680 operator/(const year& __y, const month_day& __md) noexcept;
1682 friend constexpr year_month_day
1683 operator/(const month_day& __md, const year& __y) noexcept;
1685 friend constexpr year_month_day_last
1686 operator/(const year& __y, const month_day_last& __mdl) noexcept;
1688 friend constexpr year_month_day_last
1689 operator/(const month_day_last& __mdl, const year& __y) noexcept;
1691 friend constexpr year_month_weekday
1692 operator/(const year& __y, const month_weekday& __mwd) noexcept;
1694 friend constexpr year_month_weekday
1695 operator/(const month_weekday& __mwd, const year& __y) noexcept;
1697 friend constexpr year_month_weekday_last
1698 operator/(const year& __y, const month_weekday_last& __mwdl) noexcept;
1700 friend constexpr year_month_weekday_last
1701 operator/(const month_weekday_last& __mwdl, const year& __y) noexcept;
1703 // TODO: Implement operator<<, to_stream, from_stream.
1711 unsigned char _M_wd;
1713 static constexpr weekday
1714 _S_from_days(const days& __d)
1716 auto __n = __d.count();
1717 return weekday(__n >= -4 ? (__n + 4) % 7 : (__n + 5) % 7 + 6);
1721 weekday() = default;
1724 weekday(unsigned __wd) noexcept
1725 : _M_wd(__wd == 7 ? 0 : __wd) // __wd % 7 ?
1729 weekday(const sys_days& __dp) noexcept
1730 : weekday{_S_from_days(__dp.time_since_epoch())}
1734 weekday(const local_days& __dp) noexcept
1735 : weekday{sys_days{__dp.time_since_epoch()}}
1739 operator++() noexcept
1746 operator++(int) noexcept
1754 operator--() noexcept
1761 operator--(int) noexcept
1769 operator+=(const days& __d) noexcept
1771 *this = *this + __d;
1776 operator-=(const days& __d) noexcept
1778 *this = *this - __d;
1783 c_encoding() const noexcept
1787 iso_encoding() const noexcept
1788 { return _M_wd == 0u ? 7u : _M_wd; }
1792 { return _M_wd <= 6; }
1794 constexpr weekday_indexed
1795 operator[](unsigned __index) const noexcept;
1797 constexpr weekday_last
1798 operator[](last_spec) const noexcept;
1800 friend constexpr bool
1801 operator==(const weekday& __x, const weekday& __y) noexcept
1802 { return __x._M_wd == __y._M_wd; }
1804 friend constexpr weekday
1805 operator+(const weekday& __x, const days& __y) noexcept
1807 auto __n = static_cast<long long>(__x._M_wd) + __y.count();
1808 return weekday{__detail::__modulo(__n, 7)};
1811 friend constexpr weekday
1812 operator+(const days& __x, const weekday& __y) noexcept
1813 { return __y + __x; }
1815 friend constexpr weekday
1816 operator-(const weekday& __x, const days& __y) noexcept
1817 { return __x + -__y; }
1819 friend constexpr days
1820 operator-(const weekday& __x, const weekday& __y) noexcept
1822 auto __n = static_cast<long long>(__x._M_wd) - __y._M_wd;
1823 return days{__detail::__modulo(__n, 7)};
1826 // TODO: operator<<, from_stream.
1829 inline constexpr weekday Sunday{0};
1830 inline constexpr weekday Monday{1};
1831 inline constexpr weekday Tuesday{2};
1832 inline constexpr weekday Wednesday{3};
1833 inline constexpr weekday Thursday{4};
1834 inline constexpr weekday Friday{5};
1835 inline constexpr weekday Saturday{6};
1839 class weekday_indexed
1842 chrono::weekday _M_wd;
1843 unsigned char _M_index;
1846 weekday_indexed() = default;
1849 weekday_indexed(const chrono::weekday& __wd, unsigned __index) noexcept
1850 : _M_wd(__wd), _M_index(__index)
1853 constexpr chrono::weekday
1854 weekday() const noexcept
1858 index() const noexcept
1859 { return _M_index; };
1863 { return _M_wd.ok() && 1 <= _M_index && _M_index <= 5; }
1865 friend constexpr bool
1866 operator==(const weekday_indexed& __x, const weekday_indexed& __y) noexcept
1867 { return __x.weekday() == __y.weekday() && __x.index() == __y.index(); }
1869 friend constexpr month_weekday
1870 operator/(const month& __m, const weekday_indexed& __wdi) noexcept;
1872 friend constexpr month_weekday
1873 operator/(int __m, const weekday_indexed& __wdi) noexcept;
1875 friend constexpr month_weekday
1876 operator/(const weekday_indexed& __wdi, const month& __m) noexcept;
1878 friend constexpr month_weekday
1879 operator/(const weekday_indexed& __wdi, int __m) noexcept;
1881 friend constexpr year_month_weekday
1882 operator/(const year_month& __ym, const weekday_indexed& __wdi) noexcept;
1884 // TODO: Implement operator<<.
1887 constexpr weekday_indexed
1888 weekday::operator[](unsigned __index) const noexcept
1889 { return {*this, __index}; }
1896 chrono::weekday _M_wd;
1900 weekday_last(const chrono::weekday& __wd) noexcept
1904 constexpr chrono::weekday
1905 weekday() const noexcept
1910 { return _M_wd.ok(); }
1912 friend constexpr bool
1913 operator==(const weekday_last& __x, const weekday_last& __y) noexcept
1914 { return __x.weekday() == __y.weekday(); }
1916 friend constexpr month_weekday_last
1917 operator/(int __m, const weekday_last& __wdl) noexcept;
1919 friend constexpr month_weekday_last
1920 operator/(const weekday_last& __wdl, int __m) noexcept;
1922 friend constexpr year_month_weekday_last
1923 operator/(const year_month& __ym, const weekday_last& __wdl) noexcept;
1925 // TODO: Implement operator<<.
1928 constexpr weekday_last
1929 weekday::operator[](last_spec) const noexcept
1930 { return weekday_last{*this}; }
1941 month_day() = default;
1944 month_day(const chrono::month& __m, const chrono::day& __d) noexcept
1945 : _M_m{__m}, _M_d{__d}
1948 constexpr chrono::month
1949 month() const noexcept
1952 constexpr chrono::day
1953 day() const noexcept
1960 && 1u <= unsigned(_M_d)
1961 && unsigned(_M_d) <= __detail::__days_per_month[unsigned(_M_m) - 1];
1964 friend constexpr bool
1965 operator==(const month_day& __x, const month_day& __y) noexcept
1966 { return __x.month() == __y.month() && __x.day() == __y.day(); }
1968 friend constexpr strong_ordering
1969 operator<=>(const month_day& __x, const month_day& __y) noexcept
1972 friend constexpr month_day
1973 operator/(const chrono::month& __m, const chrono::day& __d) noexcept
1974 { return {__m, __d}; }
1976 friend constexpr month_day
1977 operator/(const chrono::month& __m, int __d) noexcept
1978 { return {__m, chrono::day(unsigned(__d))}; }
1980 friend constexpr month_day
1981 operator/(int __m, const chrono::day& __d) noexcept
1982 { return {chrono::month(unsigned(__m)), __d}; }
1984 friend constexpr month_day
1985 operator/(const chrono::day& __d, const chrono::month& __m) noexcept
1986 { return {__m, __d}; }
1988 friend constexpr month_day
1989 operator/(const chrono::day& __d, int __m) noexcept
1990 { return {chrono::month(unsigned(__m)), __d}; }
1992 friend constexpr year_month_day
1993 operator/(int __y, const month_day& __md) noexcept;
1995 friend constexpr year_month_day
1996 operator/(const month_day& __md, int __y) noexcept;
1998 // TODO: Implement operator<<, from_stream.
2003 class month_day_last
2010 month_day_last(const chrono::month& __m) noexcept
2014 constexpr chrono::month
2015 month() const noexcept
2020 { return _M_m.ok(); }
2022 friend constexpr bool
2023 operator==(const month_day_last& __x, const month_day_last& __y) noexcept
2024 { return __x.month() == __y.month(); }
2026 friend constexpr strong_ordering
2027 operator<=>(const month_day_last& __x, const month_day_last& __y) noexcept
2030 friend constexpr month_day_last
2031 operator/(const chrono::month& __m, last_spec) noexcept
2032 { return month_day_last{__m}; }
2034 friend constexpr month_day_last
2035 operator/(int __m, last_spec) noexcept
2036 { return chrono::month(unsigned(__m)) / last; }
2038 friend constexpr month_day_last
2039 operator/(last_spec, const chrono::month& __m) noexcept
2040 { return __m / last; }
2042 friend constexpr month_day_last
2043 operator/(last_spec, int __m) noexcept
2044 { return __m / last; }
2046 friend constexpr year_month_day_last
2047 operator/(int __y, const month_day_last& __mdl) noexcept;
2049 friend constexpr year_month_day_last
2050 operator/(const month_day_last& __mdl, int __y) noexcept;
2052 // TODO: Implement operator<<.
2061 chrono::weekday_indexed _M_wdi;
2065 month_weekday(const chrono::month& __m,
2066 const chrono::weekday_indexed& __wdi) noexcept
2067 : _M_m{__m}, _M_wdi{__wdi}
2070 constexpr chrono::month
2071 month() const noexcept
2074 constexpr chrono::weekday_indexed
2075 weekday_indexed() const noexcept
2080 { return _M_m.ok() && _M_wdi.ok(); }
2082 friend constexpr bool
2083 operator==(const month_weekday& __x, const month_weekday& __y) noexcept
2085 return __x.month() == __y.month()
2086 && __x.weekday_indexed() == __y.weekday_indexed();
2089 friend constexpr month_weekday
2090 operator/(const chrono::month& __m,
2091 const chrono::weekday_indexed& __wdi) noexcept
2092 { return {__m, __wdi}; }
2094 friend constexpr month_weekday
2095 operator/(int __m, const chrono::weekday_indexed& __wdi) noexcept
2096 { return chrono::month(unsigned(__m)) / __wdi; }
2098 friend constexpr month_weekday
2099 operator/(const chrono::weekday_indexed& __wdi,
2100 const chrono::month& __m) noexcept
2101 { return __m / __wdi; }
2103 friend constexpr month_weekday
2104 operator/(const chrono::weekday_indexed& __wdi, int __m) noexcept
2105 { return __m / __wdi; }
2107 friend constexpr year_month_weekday
2108 operator/(int __y, const month_weekday& __mwd) noexcept;
2110 friend constexpr year_month_weekday
2111 operator/(const month_weekday& __mwd, int __y) noexcept;
2113 // TODO: Implement operator<<.
2116 // MONTH_WEEKDAY_LAST
2118 class month_weekday_last
2122 chrono::weekday_last _M_wdl;
2126 month_weekday_last(const chrono::month& __m,
2127 const chrono::weekday_last& __wdl) noexcept
2128 :_M_m{__m}, _M_wdl{__wdl}
2131 constexpr chrono::month
2132 month() const noexcept
2135 constexpr chrono::weekday_last
2136 weekday_last() const noexcept
2141 { return _M_m.ok() && _M_wdl.ok(); }
2143 friend constexpr bool
2144 operator==(const month_weekday_last& __x,
2145 const month_weekday_last& __y) noexcept
2147 return __x.month() == __y.month()
2148 && __x.weekday_last() == __y.weekday_last();
2151 friend constexpr month_weekday_last
2152 operator/(const chrono::month& __m,
2153 const chrono::weekday_last& __wdl) noexcept
2154 { return {__m, __wdl}; }
2156 friend constexpr month_weekday_last
2157 operator/(int __m, const chrono::weekday_last& __wdl) noexcept
2158 { return chrono::month(unsigned(__m)) / __wdl; }
2160 friend constexpr month_weekday_last
2161 operator/(const chrono::weekday_last& __wdl,
2162 const chrono::month& __m) noexcept
2163 { return __m / __wdl; }
2165 friend constexpr month_weekday_last
2166 operator/(const chrono::weekday_last& __wdl, int __m) noexcept
2167 { return chrono::month(unsigned(__m)) / __wdl; }
2169 friend constexpr year_month_weekday_last
2170 operator/(int __y, const month_weekday_last& __mwdl) noexcept;
2172 friend constexpr year_month_weekday_last
2173 operator/(const month_weekday_last& __mwdl, int __y) noexcept;
2175 // TODO: Implement operator<<.
2182 // [time.cal.ym], [time.cal.ymd], etc constrain the 'months'-based
2183 // addition/subtraction operator overloads like so:
2185 // Constraints: if the argument supplied by the caller for the months
2186 // parameter is convertible to years, its implicit conversion sequence
2187 // to years is worse than its implicit conversion sequence to months.
2189 // We realize this constraint by templatizing the 'months'-based
2190 // overloads (using a dummy defaulted template parameter), so that
2191 // overload resolution doesn't select the 'months'-based overload unless
2192 // the implicit conversion sequence to 'months' is better than that to
2194 using __months_years_conversion_disambiguator = void;
2204 year_month() = default;
2207 year_month(const chrono::year& __y, const chrono::month& __m) noexcept
2208 : _M_y{__y}, _M_m{__m}
2211 constexpr chrono::year
2212 year() const noexcept
2215 constexpr chrono::month
2216 month() const noexcept
2219 template<typename = __detail::__months_years_conversion_disambiguator>
2220 constexpr year_month&
2221 operator+=(const months& __dm) noexcept
2223 *this = *this + __dm;
2227 template<typename = __detail::__months_years_conversion_disambiguator>
2228 constexpr year_month&
2229 operator-=(const months& __dm) noexcept
2231 *this = *this - __dm;
2235 constexpr year_month&
2236 operator+=(const years& __dy) noexcept
2238 *this = *this + __dy;
2242 constexpr year_month&
2243 operator-=(const years& __dy) noexcept
2245 *this = *this - __dy;
2251 { return _M_y.ok() && _M_m.ok(); }
2253 friend constexpr bool
2254 operator==(const year_month& __x, const year_month& __y) noexcept
2255 { return __x.year() == __y.year() && __x.month() == __y.month(); }
2257 friend constexpr strong_ordering
2258 operator<=>(const year_month& __x, const year_month& __y) noexcept
2261 template<typename = __detail::__months_years_conversion_disambiguator>
2262 friend constexpr year_month
2263 operator+(const year_month& __ym, const months& __dm) noexcept
2266 auto __m = __ym.month() + __dm;
2267 auto __i = int(unsigned(__ym.month())) - 1 + __dm.count();
2269 ? __ym.year() + years{(__i - 11) / 12}
2270 : __ym.year() + years{__i / 12});
2274 template<typename = __detail::__months_years_conversion_disambiguator>
2275 friend constexpr year_month
2276 operator+(const months& __dm, const year_month& __ym) noexcept
2277 { return __ym + __dm; }
2279 template<typename = __detail::__months_years_conversion_disambiguator>
2280 friend constexpr year_month
2281 operator-(const year_month& __ym, const months& __dm) noexcept
2282 { return __ym + -__dm; }
2284 friend constexpr months
2285 operator-(const year_month& __x, const year_month& __y) noexcept
2287 return (__x.year() - __y.year()
2288 + months{static_cast<int>(unsigned{__x.month()})
2289 - static_cast<int>(unsigned{__y.month()})});
2292 friend constexpr year_month
2293 operator+(const year_month& __ym, const years& __dy) noexcept
2294 { return (__ym.year() + __dy) / __ym.month(); }
2296 friend constexpr year_month
2297 operator+(const years& __dy, const year_month& __ym) noexcept
2298 { return __ym + __dy; }
2300 friend constexpr year_month
2301 operator-(const year_month& __ym, const years& __dy) noexcept
2302 { return __ym + -__dy; }
2304 friend constexpr year_month
2305 operator/(const chrono::year& __y, const chrono::month& __m) noexcept
2306 { return {__y, __m}; }
2308 friend constexpr year_month
2309 operator/(const chrono::year& __y, int __m) noexcept
2310 { return {__y, chrono::month(unsigned(__m))}; }
2312 friend constexpr year_month_day
2313 operator/(const year_month& __ym, int __d) noexcept;
2315 friend constexpr year_month_day_last
2316 operator/(const year_month& __ym, last_spec) noexcept;
2318 // TODO: Implement operator<<, from_stream.
2323 class year_month_day
2330 static constexpr year_month_day _S_from_days(const days& __dp) noexcept;
2332 constexpr days _M_days_since_epoch() const noexcept;
2335 year_month_day() = default;
2338 year_month_day(const chrono::year& __y, const chrono::month& __m,
2339 const chrono::day& __d) noexcept
2340 : _M_y{__y}, _M_m{__m}, _M_d{__d}
2344 year_month_day(const year_month_day_last& __ymdl) noexcept;
2347 year_month_day(const sys_days& __dp) noexcept
2348 : year_month_day(_S_from_days(__dp.time_since_epoch()))
2352 year_month_day(const local_days& __dp) noexcept
2353 : year_month_day(sys_days{__dp.time_since_epoch()})
2356 template<typename = __detail::__months_years_conversion_disambiguator>
2357 constexpr year_month_day&
2358 operator+=(const months& __m) noexcept
2360 *this = *this + __m;
2364 template<typename = __detail::__months_years_conversion_disambiguator>
2365 constexpr year_month_day&
2366 operator-=(const months& __m) noexcept
2368 *this = *this - __m;
2372 constexpr year_month_day&
2373 operator+=(const years& __y) noexcept
2375 *this = *this + __y;
2379 constexpr year_month_day&
2380 operator-=(const years& __y) noexcept
2382 *this = *this - __y;
2386 constexpr chrono::year
2387 year() const noexcept
2390 constexpr chrono::month
2391 month() const noexcept
2394 constexpr chrono::day
2395 day() const noexcept
2399 operator sys_days() const noexcept
2400 { return sys_days{_M_days_since_epoch()}; }
2403 operator local_days() const noexcept
2404 { return local_days{sys_days{*this}.time_since_epoch()}; }
2406 constexpr bool ok() const noexcept;
2408 friend constexpr bool
2409 operator==(const year_month_day& __x, const year_month_day& __y) noexcept
2411 return __x.year() == __y.year()
2412 && __x.month() == __y.month()
2413 && __x.day() == __y.day();
2416 friend constexpr strong_ordering
2417 operator<=>(const year_month_day& __x, const year_month_day& __y) noexcept
2420 template<typename = __detail::__months_years_conversion_disambiguator>
2421 friend constexpr year_month_day
2422 operator+(const year_month_day& __ymd, const months& __dm) noexcept
2423 { return (__ymd.year() / __ymd.month() + __dm) / __ymd.day(); }
2425 template<typename = __detail::__months_years_conversion_disambiguator>
2426 friend constexpr year_month_day
2427 operator+(const months& __dm, const year_month_day& __ymd) noexcept
2428 { return __ymd + __dm; }
2430 friend constexpr year_month_day
2431 operator+(const year_month_day& __ymd, const years& __dy) noexcept
2432 { return (__ymd.year() + __dy) / __ymd.month() / __ymd.day(); }
2434 friend constexpr year_month_day
2435 operator+(const years& __dy, const year_month_day& __ymd) noexcept
2436 { return __ymd + __dy; }
2438 template<typename = __detail::__months_years_conversion_disambiguator>
2439 friend constexpr year_month_day
2440 operator-(const year_month_day& __ymd, const months& __dm) noexcept
2441 { return __ymd + -__dm; }
2443 friend constexpr year_month_day
2444 operator-(const year_month_day& __ymd, const years& __dy) noexcept
2445 { return __ymd + -__dy; }
2447 friend constexpr year_month_day
2448 operator/(const year_month& __ym, const chrono::day& __d) noexcept
2449 { return {__ym.year(), __ym.month(), __d}; }
2451 friend constexpr year_month_day
2452 operator/(const year_month& __ym, int __d) noexcept
2453 { return __ym / chrono::day{unsigned(__d)}; }
2455 friend constexpr year_month_day
2456 operator/(const chrono::year& __y, const month_day& __md) noexcept
2457 { return __y / __md.month() / __md.day(); }
2459 friend constexpr year_month_day
2460 operator/(int __y, const month_day& __md) noexcept
2461 { return chrono::year{__y} / __md; }
2463 friend constexpr year_month_day
2464 operator/(const month_day& __md, const chrono::year& __y) noexcept
2465 { return __y / __md; }
2467 friend constexpr year_month_day
2468 operator/(const month_day& __md, int __y) noexcept
2469 { return chrono::year(__y) / __md; }
2471 // TODO: Implement operator<<, from_stream.
2474 // Construct from days since 1970/01/01.
2475 // Proposition 6.3 of Neri and Schneider,
2476 // "Euclidean Affine Functions and Applications to Calendar Algorithms".
2477 // https://arxiv.org/abs/2102.06959
2478 constexpr year_month_day
2479 year_month_day::_S_from_days(const days& __dp) noexcept
2481 constexpr auto __z2 = static_cast<uint32_t>(-1468000);
2482 constexpr auto __r2_e3 = static_cast<uint32_t>(536895458);
2484 const auto __r0 = static_cast<uint32_t>(__dp.count()) + __r2_e3;
2486 const auto __n1 = 4 * __r0 + 3;
2487 const auto __q1 = __n1 / 146097;
2488 const auto __r1 = __n1 % 146097 / 4;
2490 constexpr auto __p32 = static_cast<uint64_t>(1) << 32;
2491 const auto __n2 = 4 * __r1 + 3;
2492 const auto __u2 = static_cast<uint64_t>(2939745) * __n2;
2493 const auto __q2 = static_cast<uint32_t>(__u2 / __p32);
2494 const auto __r2 = static_cast<uint32_t>(__u2 % __p32) / 2939745 / 4;
2496 constexpr auto __p16 = static_cast<uint32_t>(1) << 16;
2497 const auto __n3 = 2141 * __r2 + 197913;
2498 const auto __q3 = __n3 / __p16;
2499 const auto __r3 = __n3 % __p16 / 2141;
2501 const auto __y0 = 100 * __q1 + __q2;
2502 const auto __m0 = __q3;
2503 const auto __d0 = __r3;
2505 const auto __j = __r2 >= 306;
2506 const auto __y1 = __y0 + __j;
2507 const auto __m1 = __j ? __m0 - 12 : __m0;
2508 const auto __d1 = __d0 + 1;
2510 return year_month_day{chrono::year{static_cast<int>(__y1 + __z2)},
2511 chrono::month{__m1}, chrono::day{__d1}};
2514 // Days since 1970/01/01.
2515 // Proposition 6.2 of Neri and Schneider,
2516 // "Euclidean Affine Functions and Applications to Calendar Algorithms".
2517 // https://arxiv.org/abs/2102.06959
2519 year_month_day::_M_days_since_epoch() const noexcept
2521 auto constexpr __z2 = static_cast<uint32_t>(-1468000);
2522 auto constexpr __r2_e3 = static_cast<uint32_t>(536895458);
2524 const auto __y1 = static_cast<uint32_t>(static_cast<int>(_M_y)) - __z2;
2525 const auto __m1 = static_cast<uint32_t>(static_cast<unsigned>(_M_m));
2526 const auto __d1 = static_cast<uint32_t>(static_cast<unsigned>(_M_d));
2528 const auto __j = static_cast<uint32_t>(__m1 < 3);
2529 const auto __y0 = __y1 - __j;
2530 const auto __m0 = __j ? __m1 + 12 : __m1;
2531 const auto __d0 = __d1 - 1;
2533 const auto __q1 = __y0 / 100;
2534 const auto __yc = 1461 * __y0 / 4 - __q1 + __q1 / 4;
2535 const auto __mc = (979 *__m0 - 2919) / 32;
2536 const auto __dc = __d0;
2538 return days{static_cast<int32_t>(__yc + __mc + __dc - __r2_e3)};
2541 // YEAR_MONTH_DAY_LAST
2543 class year_month_day_last
2547 chrono::month_day_last _M_mdl;
2551 year_month_day_last(const chrono::year& __y,
2552 const chrono::month_day_last& __mdl) noexcept
2553 : _M_y{__y}, _M_mdl{__mdl}
2556 template<typename = __detail::__months_years_conversion_disambiguator>
2557 constexpr year_month_day_last&
2558 operator+=(const months& __m) noexcept
2560 *this = *this + __m;
2564 template<typename = __detail::__months_years_conversion_disambiguator>
2565 constexpr year_month_day_last&
2566 operator-=(const months& __m) noexcept
2568 *this = *this - __m;
2572 constexpr year_month_day_last&
2573 operator+=(const years& __y) noexcept
2575 *this = *this + __y;
2579 constexpr year_month_day_last&
2580 operator-=(const years& __y) noexcept
2582 *this = *this - __y;
2586 constexpr chrono::year
2587 year() const noexcept
2590 constexpr chrono::month
2591 month() const noexcept
2592 { return _M_mdl.month(); }
2594 constexpr chrono::month_day_last
2595 month_day_last() const noexcept
2598 // Return A day representing the last day of this year, month pair.
2599 constexpr chrono::day
2600 day() const noexcept
2602 const auto __m = static_cast<unsigned>(month());
2604 // Excluding February, the last day of month __m is either 30 or 31 or,
2605 // in another words, it is 30 + b = 30 | b, where b is in {0, 1}.
2607 // If __m in {1, 3, 4, 5, 6, 7}, then b is 1 if, and only if __m is odd.
2608 // Hence, b = __m & 1 = (__m ^ 0) & 1.
2610 // If __m in {8, 9, 10, 11, 12}, then b is 1 if, and only if __m is even.
2611 // Hence, b = (__m ^ 1) & 1.
2613 // Therefore, b = (__m ^ c) & 1, where c = 0, if __m < 8, or c = 1 if
2614 // __m >= 8, that is, c = __m >> 3.
2616 // The above mathematically justifies this implementation whose
2617 // performance does not depend on look-up tables being on the L1 cache.
2618 return chrono::day{__m != 2 ? ((__m ^ (__m >> 3)) & 1) | 30
2619 : _M_y.is_leap() ? 29 : 28};
2623 operator sys_days() const noexcept
2624 { return sys_days{year() / month() / day()}; }
2627 operator local_days() const noexcept
2628 { return local_days{sys_days{*this}.time_since_epoch()}; }
2632 { return _M_y.ok() && _M_mdl.ok(); }
2634 friend constexpr bool
2635 operator==(const year_month_day_last& __x,
2636 const year_month_day_last& __y) noexcept
2638 return __x.year() == __y.year()
2639 && __x.month_day_last() == __y.month_day_last();
2642 friend constexpr strong_ordering
2643 operator<=>(const year_month_day_last& __x,
2644 const year_month_day_last& __y) noexcept
2647 template<typename = __detail::__months_years_conversion_disambiguator>
2648 friend constexpr year_month_day_last
2649 operator+(const year_month_day_last& __ymdl,
2650 const months& __dm) noexcept
2651 { return (__ymdl.year() / __ymdl.month() + __dm) / last; }
2653 template<typename = __detail::__months_years_conversion_disambiguator>
2654 friend constexpr year_month_day_last
2655 operator+(const months& __dm,
2656 const year_month_day_last& __ymdl) noexcept
2657 { return __ymdl + __dm; }
2659 template<typename = __detail::__months_years_conversion_disambiguator>
2660 friend constexpr year_month_day_last
2661 operator-(const year_month_day_last& __ymdl,
2662 const months& __dm) noexcept
2663 { return __ymdl + -__dm; }
2665 friend constexpr year_month_day_last
2666 operator+(const year_month_day_last& __ymdl,
2667 const years& __dy) noexcept
2668 { return {__ymdl.year() + __dy, __ymdl.month_day_last()}; }
2670 friend constexpr year_month_day_last
2671 operator+(const years& __dy,
2672 const year_month_day_last& __ymdl) noexcept
2673 { return __ymdl + __dy; }
2675 friend constexpr year_month_day_last
2676 operator-(const year_month_day_last& __ymdl,
2677 const years& __dy) noexcept
2678 { return __ymdl + -__dy; }
2680 friend constexpr year_month_day_last
2681 operator/(const year_month& __ym, last_spec) noexcept
2682 { return {__ym.year(), chrono::month_day_last{__ym.month()}}; }
2684 friend constexpr year_month_day_last
2685 operator/(const chrono::year& __y,
2686 const chrono::month_day_last& __mdl) noexcept
2687 { return {__y, __mdl}; }
2689 friend constexpr year_month_day_last
2690 operator/(int __y, const chrono::month_day_last& __mdl) noexcept
2691 { return chrono::year(__y) / __mdl; }
2693 friend constexpr year_month_day_last
2694 operator/(const chrono::month_day_last& __mdl,
2695 const chrono::year& __y) noexcept
2696 { return __y / __mdl; }
2698 friend constexpr year_month_day_last
2699 operator/(const chrono::month_day_last& __mdl, int __y) noexcept
2700 { return chrono::year(__y) / __mdl; }
2702 // TODO: Implement operator<<.
2705 // year_month_day ctor from year_month_day_last
2707 year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
2708 : _M_y{__ymdl.year()}, _M_m{__ymdl.month()}, _M_d{__ymdl.day()}
2712 year_month_day::ok() const noexcept
2714 if (!_M_y.ok() || !_M_m.ok())
2716 return chrono::day{1} <= _M_d && _M_d <= (_M_y / _M_m / last).day();
2719 // YEAR_MONTH_WEEKDAY
2721 class year_month_weekday
2726 chrono::weekday_indexed _M_wdi;
2728 static constexpr year_month_weekday
2729 _S_from_sys_days(const sys_days& __dp)
2731 year_month_day __ymd{__dp};
2732 chrono::weekday __wd{__dp};
2733 auto __index = __wd[(unsigned{__ymd.day()} - 1) / 7 + 1];
2734 return {__ymd.year(), __ymd.month(), __index};
2738 year_month_weekday() = default;
2741 year_month_weekday(const chrono::year& __y, const chrono::month& __m,
2742 const chrono::weekday_indexed& __wdi) noexcept
2743 : _M_y{__y}, _M_m{__m}, _M_wdi{__wdi}
2747 year_month_weekday(const sys_days& __dp) noexcept
2748 : year_month_weekday{_S_from_sys_days(__dp)}
2752 year_month_weekday(const local_days& __dp) noexcept
2753 : year_month_weekday{sys_days{__dp.time_since_epoch()}}
2756 template<typename = __detail::__months_years_conversion_disambiguator>
2757 constexpr year_month_weekday&
2758 operator+=(const months& __m) noexcept
2760 *this = *this + __m;
2764 template<typename = __detail::__months_years_conversion_disambiguator>
2765 constexpr year_month_weekday&
2766 operator-=(const months& __m) noexcept
2768 *this = *this - __m;
2772 constexpr year_month_weekday&
2773 operator+=(const years& __y) noexcept
2775 *this = *this + __y;
2779 constexpr year_month_weekday&
2780 operator-=(const years& __y) noexcept
2782 *this = *this - __y;
2786 constexpr chrono::year
2787 year() const noexcept
2790 constexpr chrono::month
2791 month() const noexcept
2794 constexpr chrono::weekday
2795 weekday() const noexcept
2796 { return _M_wdi.weekday(); }
2799 index() const noexcept
2800 { return _M_wdi.index(); }
2802 constexpr chrono::weekday_indexed
2803 weekday_indexed() const noexcept
2807 operator sys_days() const noexcept
2809 auto __d = sys_days{year() / month() / 1};
2810 return __d + (weekday() - chrono::weekday(__d)
2811 + days{(static_cast<int>(index())-1)*7});
2815 operator local_days() const noexcept
2816 { return local_days{sys_days{*this}.time_since_epoch()}; }
2821 if (!_M_y.ok() || !_M_m.ok() || !_M_wdi.ok())
2823 if (_M_wdi.index() <= 4)
2825 days __d = (_M_wdi.weekday()
2826 - chrono::weekday{sys_days{_M_y / _M_m / 1}}
2827 + days((_M_wdi.index()-1)*7 + 1));
2828 __glibcxx_assert(__d.count() >= 1);
2829 return __d.count() <= unsigned{(_M_y / _M_m / last).day()};
2832 friend constexpr bool
2833 operator==(const year_month_weekday& __x,
2834 const year_month_weekday& __y) noexcept
2836 return __x.year() == __y.year()
2837 && __x.month() == __y.month()
2838 && __x.weekday_indexed() == __y.weekday_indexed();
2841 template<typename = __detail::__months_years_conversion_disambiguator>
2842 friend constexpr year_month_weekday
2843 operator+(const year_month_weekday& __ymwd, const months& __dm) noexcept
2845 return ((__ymwd.year() / __ymwd.month() + __dm)
2846 / __ymwd.weekday_indexed());
2849 template<typename = __detail::__months_years_conversion_disambiguator>
2850 friend constexpr year_month_weekday
2851 operator+(const months& __dm, const year_month_weekday& __ymwd) noexcept
2852 { return __ymwd + __dm; }
2854 friend constexpr year_month_weekday
2855 operator+(const year_month_weekday& __ymwd, const years& __dy) noexcept
2856 { return {__ymwd.year() + __dy, __ymwd.month(), __ymwd.weekday_indexed()}; }
2858 friend constexpr year_month_weekday
2859 operator+(const years& __dy, const year_month_weekday& __ymwd) noexcept
2860 { return __ymwd + __dy; }
2862 template<typename = __detail::__months_years_conversion_disambiguator>
2863 friend constexpr year_month_weekday
2864 operator-(const year_month_weekday& __ymwd, const months& __dm) noexcept
2865 { return __ymwd + -__dm; }
2867 friend constexpr year_month_weekday
2868 operator-(const year_month_weekday& __ymwd, const years& __dy) noexcept
2869 { return __ymwd + -__dy; }
2871 friend constexpr year_month_weekday
2872 operator/(const year_month& __ym,
2873 const chrono::weekday_indexed& __wdi) noexcept
2874 { return {__ym.year(), __ym.month(), __wdi}; }
2876 friend constexpr year_month_weekday
2877 operator/(const chrono::year& __y, const month_weekday& __mwd) noexcept
2878 { return {__y, __mwd.month(), __mwd.weekday_indexed()}; }
2880 friend constexpr year_month_weekday
2881 operator/(int __y, const month_weekday& __mwd) noexcept
2882 { return chrono::year(__y) / __mwd; }
2884 friend constexpr year_month_weekday
2885 operator/(const month_weekday& __mwd, const chrono::year& __y) noexcept
2886 { return __y / __mwd; }
2888 friend constexpr year_month_weekday
2889 operator/(const month_weekday& __mwd, int __y) noexcept
2890 { return chrono::year(__y) / __mwd; }
2892 // TODO: Implement operator<<.
2895 // YEAR_MONTH_WEEKDAY_LAST
2897 class year_month_weekday_last
2902 chrono::weekday_last _M_wdl;
2906 year_month_weekday_last(const chrono::year& __y, const chrono::month& __m,
2907 const chrono::weekday_last& __wdl) noexcept
2908 : _M_y{__y}, _M_m{__m}, _M_wdl{__wdl}
2911 template<typename = __detail::__months_years_conversion_disambiguator>
2912 constexpr year_month_weekday_last&
2913 operator+=(const months& __m) noexcept
2915 *this = *this + __m;
2919 template<typename = __detail::__months_years_conversion_disambiguator>
2920 constexpr year_month_weekday_last&
2921 operator-=(const months& __m) noexcept
2923 *this = *this - __m;
2927 constexpr year_month_weekday_last&
2928 operator+=(const years& __y) noexcept
2930 *this = *this + __y;
2934 constexpr year_month_weekday_last&
2935 operator-=(const years& __y) noexcept
2937 *this = *this - __y;
2941 constexpr chrono::year
2942 year() const noexcept
2945 constexpr chrono::month
2946 month() const noexcept
2949 constexpr chrono::weekday
2950 weekday() const noexcept
2951 { return _M_wdl.weekday(); }
2953 constexpr chrono::weekday_last
2954 weekday_last() const noexcept
2958 operator sys_days() const noexcept
2960 const auto __d = sys_days{_M_y / _M_m / last};
2961 return sys_days{(__d - (chrono::weekday{__d}
2962 - _M_wdl.weekday())).time_since_epoch()};
2966 operator local_days() const noexcept
2967 { return local_days{sys_days{*this}.time_since_epoch()}; }
2971 { return _M_y.ok() && _M_m.ok() && _M_wdl.ok(); }
2973 friend constexpr bool
2974 operator==(const year_month_weekday_last& __x,
2975 const year_month_weekday_last& __y) noexcept
2977 return __x.year() == __y.year()
2978 && __x.month() == __y.month()
2979 && __x.weekday_last() == __y.weekday_last();
2982 template<typename = __detail::__months_years_conversion_disambiguator>
2983 friend constexpr year_month_weekday_last
2984 operator+(const year_month_weekday_last& __ymwdl,
2985 const months& __dm) noexcept
2987 return ((__ymwdl.year() / __ymwdl.month() + __dm)
2988 / __ymwdl.weekday_last());
2991 template<typename = __detail::__months_years_conversion_disambiguator>
2992 friend constexpr year_month_weekday_last
2993 operator+(const months& __dm,
2994 const year_month_weekday_last& __ymwdl) noexcept
2995 { return __ymwdl + __dm; }
2997 friend constexpr year_month_weekday_last
2998 operator+(const year_month_weekday_last& __ymwdl,
2999 const years& __dy) noexcept
3000 { return {__ymwdl.year() + __dy, __ymwdl.month(), __ymwdl.weekday_last()}; }
3002 friend constexpr year_month_weekday_last
3003 operator+(const years& __dy,
3004 const year_month_weekday_last& __ymwdl) noexcept
3005 { return __ymwdl + __dy; }
3007 template<typename = __detail::__months_years_conversion_disambiguator>
3008 friend constexpr year_month_weekday_last
3009 operator-(const year_month_weekday_last& __ymwdl,
3010 const months& __dm) noexcept
3011 { return __ymwdl + -__dm; }
3013 friend constexpr year_month_weekday_last
3014 operator-(const year_month_weekday_last& __ymwdl,
3015 const years& __dy) noexcept
3016 { return __ymwdl + -__dy; }
3018 friend constexpr year_month_weekday_last
3019 operator/(const year_month& __ym,
3020 const chrono::weekday_last& __wdl) noexcept
3021 { return {__ym.year(), __ym.month(), __wdl}; }
3023 friend constexpr year_month_weekday_last
3024 operator/(const chrono::year& __y,
3025 const chrono::month_weekday_last& __mwdl) noexcept
3026 { return {__y, __mwdl.month(), __mwdl.weekday_last()}; }
3028 friend constexpr year_month_weekday_last
3029 operator/(int __y, const chrono::month_weekday_last& __mwdl) noexcept
3030 { return chrono::year(__y) / __mwdl; }
3032 friend constexpr year_month_weekday_last
3033 operator/(const chrono::month_weekday_last& __mwdl,
3034 const chrono::year& __y) noexcept
3035 { return __y / __mwdl; }
3037 friend constexpr year_month_weekday_last
3038 operator/(const chrono::month_weekday_last& __mwdl, int __y) noexcept
3039 { return chrono::year(__y) / __mwdl; }
3041 // TODO: Implement operator<<.
3049 __pow10(unsigned __n)
3058 template<typename _Duration>
3062 static constexpr int
3063 _S_fractional_width()
3065 int __multiplicity_2 = 0;
3066 int __multiplicity_5 = 0;
3067 auto __den = _Duration::period::den;
3068 while ((__den % 2) == 0)
3073 while ((__den % 5) == 0)
3081 int __width = (__multiplicity_2 > __multiplicity_5
3082 ? __multiplicity_2 : __multiplicity_5);
3089 hh_mm_ss(_Duration __d, bool __is_neg)
3090 : _M_is_neg(__is_neg),
3091 _M_h (duration_cast<chrono::hours>(__d)),
3092 _M_m (duration_cast<chrono::minutes>(__d - hours())),
3093 _M_s (duration_cast<chrono::seconds>(__d - hours() - minutes()))
3095 auto __ss = __d - hours() - minutes() - seconds();
3096 if constexpr (treat_as_floating_point_v<typename precision::rep>)
3099 _M_ss = duration_cast<precision>(__ss);
3102 static constexpr _Duration
3103 _S_abs(_Duration __d)
3105 if constexpr (numeric_limits<typename _Duration::rep>::is_signed)
3106 return chrono::abs(__d);
3112 static constexpr unsigned fractional_width = {_S_fractional_width()};
3115 = duration<common_type_t<typename _Duration::rep,
3116 chrono::seconds::rep>,
3117 ratio<1, __detail::__pow10(fractional_width)>>;
3121 : hh_mm_ss{_Duration::zero()}
3125 hh_mm_ss(_Duration __d)
3126 : hh_mm_ss(_S_abs(__d), __d < _Duration::zero())
3130 is_negative() const noexcept
3131 { return _M_is_neg; }
3133 constexpr chrono::hours
3134 hours() const noexcept
3137 constexpr chrono::minutes
3138 minutes() const noexcept
3141 constexpr chrono::seconds
3142 seconds() const noexcept
3146 subseconds() const noexcept
3150 operator precision() const noexcept
3151 { return to_duration(); }
3154 to_duration() const noexcept
3157 return -(_M_h + _M_m + _M_s + _M_ss);
3159 return _M_h + _M_m + _M_s + _M_ss;
3162 // TODO: Implement operator<<.
3167 chrono::minutes _M_m;
3168 chrono::seconds _M_s;
3174 } // namespace chrono
3176#if __cplusplus > 201103L
3178#define __cpp_lib_chrono_udls 201304
3180 inline namespace literals
3182 /** ISO C++ 2014 namespace for suffixes for duration literals.
3184 * These suffixes can be used to create `chrono::duration` values with
3185 * tick periods of hours, minutes, seconds, milliseconds, microseconds
3186 * or nanoseconds. For example, `std::chrono::seconds(5)` can be written
3187 * as `5s` after making the suffix visible in the current scope.
3188 * The suffixes can be made visible by a using-directive or
3189 * using-declaration such as:
3190 * - `using namespace std::chrono_literals;`
3191 * - `using namespace std::literals;`
3192 * - `using namespace std::chrono;`
3193 * - `using namespace std;`
3194 * - `using std::chrono_literals::operator""s;`
3196 * The result of these suffixes on an integer literal is one of the
3197 * standard typedefs such as `std::chrono::hours`.
3198 * The result on a floating-point literal is a duration type with the
3199 * specified tick period and an unspecified floating-point representation,
3200 * for example `1.5e2ms` might be equivalent to
3201 * `chrono::duration<long double, chrono::milli>(1.5e2)`.
3205 inline namespace chrono_literals
3207 /// @addtogroup chrono
3210#pragma GCC diagnostic push
3211#pragma GCC diagnostic ignored "-Wliteral-suffix"
3212 /// @cond undocumented
3213 template<typename _Dur, char... _Digits>
3214 constexpr _Dur __check_overflow()
3216 using _Val = __parse_int::_Parse_int<_Digits...>;
3217 constexpr typename _Dur::rep __repval = _Val::value;
3218 static_assert(__repval >= 0 && __repval == _Val::value,
3219 "literal value cannot be represented by duration type");
3220 return _Dur(__repval);
3224 /// Literal suffix for durations representing non-integer hours
3225 constexpr chrono::duration<long double, ratio<3600,1>>
3226 operator""h(long double __hours)
3227 { return chrono::duration<long double, ratio<3600,1>>{__hours}; }
3229 /// Literal suffix for durations of type `std::chrono::hours`
3230 template <char... _Digits>
3231 constexpr chrono::hours
3233 { return __check_overflow<chrono::hours, _Digits...>(); }
3235 /// Literal suffix for durations representing non-integer minutes
3236 constexpr chrono::duration<long double, ratio<60,1>>
3237 operator""min(long double __mins)
3238 { return chrono::duration<long double, ratio<60,1>>{__mins}; }
3240 /// Literal suffix for durations of type `std::chrono::minutes`
3241 template <char... _Digits>
3242 constexpr chrono::minutes
3244 { return __check_overflow<chrono::minutes, _Digits...>(); }
3246 /// Literal suffix for durations representing non-integer seconds
3247 constexpr chrono::duration<long double>
3248 operator""s(long double __secs)
3249 { return chrono::duration<long double>{__secs}; }
3251 /// Literal suffix for durations of type `std::chrono::seconds`
3252 template <char... _Digits>
3253 constexpr chrono::seconds
3255 { return __check_overflow<chrono::seconds, _Digits...>(); }
3257 /// Literal suffix for durations representing non-integer milliseconds
3258 constexpr chrono::duration<long double, milli>
3259 operator""ms(long double __msecs)
3260 { return chrono::duration<long double, milli>{__msecs}; }
3262 /// Literal suffix for durations of type `std::chrono::milliseconds`
3263 template <char... _Digits>
3264 constexpr chrono::milliseconds
3266 { return __check_overflow<chrono::milliseconds, _Digits...>(); }
3268 /// Literal suffix for durations representing non-integer microseconds
3269 constexpr chrono::duration<long double, micro>
3270 operator""us(long double __usecs)
3271 { return chrono::duration<long double, micro>{__usecs}; }
3273 /// Literal suffix for durations of type `std::chrono::microseconds`
3274 template <char... _Digits>
3275 constexpr chrono::microseconds
3277 { return __check_overflow<chrono::microseconds, _Digits...>(); }
3279 /// Literal suffix for durations representing non-integer nanoseconds
3280 constexpr chrono::duration<long double, nano>
3281 operator""ns(long double __nsecs)
3282 { return chrono::duration<long double, nano>{__nsecs}; }
3284 /// Literal suffix for durations of type `std::chrono::nanoseconds`
3285 template <char... _Digits>
3286 constexpr chrono::nanoseconds
3288 { return __check_overflow<chrono::nanoseconds, _Digits...>(); }
3290#if __cplusplus > 201703L
3291 constexpr chrono::day
3292 operator""d(unsigned long long __d) noexcept
3293 { return chrono::day{static_cast<unsigned>(__d)}; }
3295 constexpr chrono::year
3296 operator""y(unsigned long long __y) noexcept
3297 { return chrono::year{static_cast<int>(__y)}; }
3300#pragma GCC diagnostic pop
3302 } // inline namespace chrono_literals
3303 } // inline namespace literals
3307 using namespace literals::chrono_literals;
3308 } // namespace chrono
3310#if __cplusplus > 201703L
3313 /// @addtogroup chrono
3316 // 12/24 HOURS FUNCTIONS
3319 is_am(const hours& __h) noexcept
3320 { return 0h <= __h && __h <= 11h; }
3323 is_pm(const hours& __h) noexcept
3324 { return 12h <= __h && __h <= 23h; }
3327 make12(const hours& __h) noexcept
3337 make24(const hours& __h, bool __is_pm) noexcept
3355 } // namespace chrono
3358#if __cplusplus >= 201703L
3359 namespace filesystem
3363 using duration = chrono::nanoseconds;
3364 using rep = duration::rep;
3365 using period = duration::period;
3366 using time_point = chrono::time_point<__file_clock>;
3367 static constexpr bool is_steady = false;
3371 { return _S_from_sys(chrono::system_clock::now()); }
3373#if __cplusplus > 201703L
3374 template<typename _Dur>
3376 chrono::file_time<_Dur>
3377 from_sys(const chrono::sys_time<_Dur>& __t) noexcept
3378 { return _S_from_sys(__t); }
3380 // For internal use only
3381 template<typename _Dur>
3383 chrono::sys_time<_Dur>
3384 to_sys(const chrono::file_time<_Dur>& __t) noexcept
3385 { return _S_to_sys(__t); }
3389 using __sys_clock = chrono::system_clock;
3391 // This clock's (unspecified) epoch is 2174-01-01 00:00:00 UTC.
3392 // A signed 64-bit duration with nanosecond resolution gives roughly
3393 // +/- 292 years, which covers the 1901-2446 date range for ext4.
3394 static constexpr chrono::seconds _S_epoch_diff{6437664000};
3397 // For internal use only
3398 template<typename _Dur>
3400 chrono::time_point<__file_clock, _Dur>
3401 _S_from_sys(const chrono::time_point<__sys_clock, _Dur>& __t) noexcept
3403 using __file_time = chrono::time_point<__file_clock, _Dur>;
3404 return __file_time{__t.time_since_epoch()} - _S_epoch_diff;
3407 // For internal use only
3408 template<typename _Dur>
3410 chrono::time_point<__sys_clock, _Dur>
3411 _S_to_sys(const chrono::time_point<__file_clock, _Dur>& __t) noexcept
3413 using __sys_time = chrono::time_point<__sys_clock, _Dur>;
3414 return __sys_time{__t.time_since_epoch()} + _S_epoch_diff;
3417 } // namespace filesystem
3421_GLIBCXX_END_NAMESPACE_VERSION
3426#endif //_GLIBCXX_CHRONO