Home | History | Annotate | Download | only in include
      1 // -*- C++ -*-
      2 //===---------------------------- chrono ----------------------------------===//
      3 //
      4 //                     The LLVM Compiler Infrastructure
      5 //
      6 // This file is dual licensed under the MIT and the University of Illinois Open
      7 // Source Licenses. See LICENSE.TXT for details.
      8 //
      9 //===----------------------------------------------------------------------===//
     10 
     11 #ifndef _LIBCPP_CHRONO
     12 #define _LIBCPP_CHRONO
     13 
     14 /*
     15     chrono synopsis
     16 
     17 namespace std
     18 {
     19 namespace chrono
     20 {
     21 
     22 template <class ToDuration, class Rep, class Period>
     23 constexpr
     24 ToDuration
     25 duration_cast(const duration<Rep, Period>& fd);
     26 
     27 template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
     28 
     29 template <class Rep> inline constexpr bool treat_as_floating_point_v
     30     = treat_as_floating_point<Rep>::value;                       // C++17
     31 
     32 template <class Rep>
     33 struct duration_values
     34 {
     35 public:
     36     static constexpr Rep zero(); // noexcept in C++20
     37     static constexpr Rep max();  // noexcept in C++20
     38     static constexpr Rep min();  // noexcept in C++20
     39 };
     40 
     41 // duration
     42 
     43 template <class Rep, class Period = ratio<1>>
     44 class duration
     45 {
     46     static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
     47     static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
     48     static_assert(Period::num > 0, "duration period must be positive");
     49 public:
     50     typedef Rep rep;
     51     typedef typename _Period::type period;
     52 
     53     constexpr duration() = default;
     54     template <class Rep2>
     55         constexpr explicit duration(const Rep2& r,
     56             typename enable_if
     57             <
     58                is_convertible<Rep2, rep>::value &&
     59                (treat_as_floating_point<rep>::value ||
     60                !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
     61             >::type* = 0);
     62 
     63     // conversions
     64     template <class Rep2, class Period2>
     65         constexpr duration(const duration<Rep2, Period2>& d,
     66             typename enable_if
     67             <
     68                 treat_as_floating_point<rep>::value ||
     69                 ratio_divide<Period2, period>::type::den == 1
     70             >::type* = 0);
     71 
     72     // observer
     73 
     74     constexpr rep count() const;
     75 
     76     // arithmetic
     77 
     78     constexpr common_type<duration>::type  operator+() const;
     79     constexpr common_type<duration>::type  operator-() const;
     80     constexpr duration& operator++();    // constexpr in C++17
     81     constexpr duration  operator++(int); // constexpr in C++17
     82     constexpr duration& operator--();    // constexpr in C++17
     83     constexpr duration  operator--(int); // constexpr in C++17
     84 
     85     constexpr duration& operator+=(const duration& d);  // constexpr in C++17
     86     constexpr duration& operator-=(const duration& d);  // constexpr in C++17
     87 
     88     duration& operator*=(const rep& rhs);       // constexpr in C++17
     89     duration& operator/=(const rep& rhs);       // constexpr in C++17
     90     duration& operator%=(const rep& rhs);       // constexpr in C++17
     91     duration& operator%=(const duration& rhs);  // constexpr in C++17
     92 
     93     // special values
     94 
     95     static constexpr duration zero(); // noexcept in C++20
     96     static constexpr duration min();  // noexcept in C++20
     97     static constexpr duration max();  // noexcept in C++20
     98 };
     99 
    100 typedef duration<long long,         nano> nanoseconds;
    101 typedef duration<long long,        micro> microseconds;
    102 typedef duration<long long,        milli> milliseconds;
    103 typedef duration<long long              > seconds;
    104 typedef duration<     long, ratio<  60> > minutes;
    105 typedef duration<     long, ratio<3600> > hours;
    106 
    107 template <class Clock, class Duration = typename Clock::duration>
    108 class time_point
    109 {
    110 public:
    111     typedef Clock                     clock;
    112     typedef Duration                  duration;
    113     typedef typename duration::rep    rep;
    114     typedef typename duration::period period;
    115 private:
    116     duration d_;  // exposition only
    117 
    118 public:
    119     time_point();  // has value "epoch" // constexpr in C++14
    120     explicit time_point(const duration& d);  // same as time_point() + d // constexpr in C++14
    121 
    122     // conversions
    123     template <class Duration2>
    124        time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
    125 
    126     // observer
    127 
    128     duration time_since_epoch() const; // constexpr in C++14
    129 
    130     // arithmetic
    131 
    132     time_point& operator+=(const duration& d); // constexpr in C++17
    133     time_point& operator-=(const duration& d); // constexpr in C++17
    134 
    135     // special values
    136 
    137     static constexpr time_point min();  // noexcept in C++20
    138     static constexpr time_point max();  // noexcept in C++20
    139 };
    140 
    141 } // chrono
    142 
    143 // common_type traits
    144 template <class Rep1, class Period1, class Rep2, class Period2>
    145   struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
    146 
    147 template <class Clock, class Duration1, class Duration2>
    148   struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
    149 
    150 namespace chrono {
    151 
    152 
    153 template<class T> struct is_clock;  // C++20
    154 template<class T> inline constexpr bool is_clock_v = is_clock<T>::value;   // C++20
    155 
    156 
    157 // duration arithmetic
    158 template <class Rep1, class Period1, class Rep2, class Period2>
    159   constexpr
    160   typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
    161   operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
    162 template <class Rep1, class Period1, class Rep2, class Period2>
    163   constexpr
    164   typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
    165   operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
    166 template <class Rep1, class Period, class Rep2>
    167   constexpr
    168   duration<typename common_type<Rep1, Rep2>::type, Period>
    169   operator*(const duration<Rep1, Period>& d, const Rep2& s);
    170 template <class Rep1, class Period, class Rep2>
    171   constexpr
    172   duration<typename common_type<Rep1, Rep2>::type, Period>
    173   operator*(const Rep1& s, const duration<Rep2, Period>& d);
    174 template <class Rep1, class Period, class Rep2>
    175   constexpr
    176   duration<typename common_type<Rep1, Rep2>::type, Period>
    177   operator/(const duration<Rep1, Period>& d, const Rep2& s);
    178 template <class Rep1, class Period1, class Rep2, class Period2>
    179   constexpr
    180   typename common_type<Rep1, Rep2>::type
    181   operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
    182 
    183 // duration comparisons
    184 template <class Rep1, class Period1, class Rep2, class Period2>
    185    constexpr
    186    bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
    187 template <class Rep1, class Period1, class Rep2, class Period2>
    188    constexpr
    189    bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
    190 template <class Rep1, class Period1, class Rep2, class Period2>
    191    constexpr
    192    bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
    193 template <class Rep1, class Period1, class Rep2, class Period2>
    194    constexpr
    195    bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
    196 template <class Rep1, class Period1, class Rep2, class Period2>
    197    constexpr
    198    bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
    199 template <class Rep1, class Period1, class Rep2, class Period2>
    200    constexpr
    201    bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
    202 
    203 // duration_cast
    204 template <class ToDuration, class Rep, class Period>
    205   ToDuration duration_cast(const duration<Rep, Period>& d);
    206 
    207 template <class ToDuration, class Rep, class Period>
    208     constexpr ToDuration floor(const duration<Rep, Period>& d);    // C++17
    209 template <class ToDuration, class Rep, class Period>
    210     constexpr ToDuration ceil(const duration<Rep, Period>& d);     // C++17
    211 template <class ToDuration, class Rep, class Period>
    212     constexpr ToDuration round(const duration<Rep, Period>& d);    // C++17
    213 
    214 // duration I/O is elsewhere
    215 
    216 // time_point arithmetic (all constexpr in C++14)
    217 template <class Clock, class Duration1, class Rep2, class Period2>
    218   time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
    219   operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
    220 template <class Rep1, class Period1, class Clock, class Duration2>
    221   time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
    222   operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
    223 template <class Clock, class Duration1, class Rep2, class Period2>
    224   time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
    225   operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
    226 template <class Clock, class Duration1, class Duration2>
    227   typename common_type<Duration1, Duration2>::type
    228   operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
    229 
    230 // time_point comparisons (all constexpr in C++14)
    231 template <class Clock, class Duration1, class Duration2>
    232    bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
    233 template <class Clock, class Duration1, class Duration2>
    234    bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
    235 template <class Clock, class Duration1, class Duration2>
    236    bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
    237 template <class Clock, class Duration1, class Duration2>
    238    bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
    239 template <class Clock, class Duration1, class Duration2>
    240    bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
    241 template <class Clock, class Duration1, class Duration2>
    242    bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
    243 
    244 // time_point_cast (constexpr in C++14)
    245 
    246 template <class ToDuration, class Clock, class Duration>
    247   time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
    248 
    249 template <class ToDuration, class Clock, class Duration>
    250     constexpr time_point<Clock, ToDuration>
    251     floor(const time_point<Clock, Duration>& tp);                  // C++17
    252 
    253 template <class ToDuration, class Clock, class Duration>
    254     constexpr time_point<Clock, ToDuration>
    255     ceil(const time_point<Clock, Duration>& tp);                   // C++17
    256 
    257 template <class ToDuration, class Clock, class Duration>
    258     constexpr time_point<Clock, ToDuration>
    259     round(const time_point<Clock, Duration>& tp);                  // C++17
    260 
    261 template <class Rep, class Period>
    262     constexpr duration<Rep, Period> abs(duration<Rep, Period> d);  // C++17
    263 
    264 // Clocks
    265 
    266 class system_clock
    267 {
    268 public:
    269     typedef microseconds                     duration;
    270     typedef duration::rep                    rep;
    271     typedef duration::period                 period;
    272     typedef chrono::time_point<system_clock> time_point;
    273     static const bool is_steady =            false; // constexpr in C++14
    274 
    275     static time_point now() noexcept;
    276     static time_t     to_time_t  (const time_point& __t) noexcept;
    277     static time_point from_time_t(time_t __t) noexcept;
    278 };
    279 
    280 template <class Duration>
    281   using sys_time  = time_point<system_clock, Duration>; // C++20
    282 using sys_seconds = sys_time<seconds>;                  // C++20
    283 using sys_days    = sys_time<days>;                     // C++20
    284 
    285 class utc_clock;                                        // C++20
    286 
    287 template <class Duration>
    288   using utc_time  = time_point<utc_clock, Duration>;    // C++20
    289 using utc_seconds = utc_time<seconds>;                  // C++20
    290 
    291 class tai_clock;                                        // C++20
    292 
    293 template <class Duration>
    294   using tai_time  = time_point<tai_clock, Duration>;    // C++20
    295 using tai_seconds = tai_time<seconds>;                  // C++20
    296 
    297 class file_clock;                                       // C++20
    298 
    299 template<class Duration>
    300   using file_time = time_point<file_clock, Duration>;   // C++20
    301 
    302 class steady_clock
    303 {
    304 public:
    305     typedef nanoseconds                                   duration;
    306     typedef duration::rep                                 rep;
    307     typedef duration::period                              period;
    308     typedef chrono::time_point<steady_clock, duration>    time_point;
    309     static const bool is_steady =                         true; // constexpr in C++14
    310 
    311     static time_point now() noexcept;
    312 };
    313 
    314 typedef steady_clock high_resolution_clock;
    315 
    316 // 25.7.8, local time           // C++20
    317 struct local_t {};
    318 template<class Duration>
    319   using local_time  = time_point<local_t, Duration>;
    320 using local_seconds = local_time<seconds>;
    321 using local_days    = local_time<days>;
    322 
    323 // 25.7.9, time_point conversions template<class DestClock, class SourceClock>    // C++20
    324 struct clock_time_conversion;
    325 
    326 template<class DestClock, class SourceClock, class Duration>
    327   auto clock_cast(const time_point<SourceClock, Duration>& t);
    328 
    329 // 25.8.2, class last_spec    // C++20
    330 struct last_spec;
    331 
    332 // 25.8.3, class day          // C++20
    333 
    334 class day;
    335 constexpr bool operator==(const day& x, const day& y) noexcept;
    336 constexpr bool operator!=(const day& x, const day& y) noexcept;
    337 constexpr bool operator< (const day& x, const day& y) noexcept;
    338 constexpr bool operator> (const day& x, const day& y) noexcept;
    339 constexpr bool operator<=(const day& x, const day& y) noexcept;
    340 constexpr bool operator>=(const day& x, const day& y) noexcept;
    341 constexpr day  operator+(const day&  x, const days& y) noexcept;
    342 constexpr day  operator+(const days& x, const day&  y) noexcept;
    343 constexpr day  operator-(const day&  x, const days& y) noexcept;
    344 constexpr days operator-(const day&  x, const day&  y) noexcept;
    345 
    346 // 25.8.4, class month    // C++20
    347 class month;
    348 constexpr bool operator==(const month& x, const month& y) noexcept;
    349 constexpr bool operator!=(const month& x, const month& y) noexcept;
    350 constexpr bool operator< (const month& x, const month& y) noexcept;
    351 constexpr bool operator> (const month& x, const month& y) noexcept;
    352 constexpr bool operator<=(const month& x, const month& y) noexcept;
    353 constexpr bool operator>=(const month& x, const month& y) noexcept;
    354 constexpr month  operator+(const month&  x, const months& y) noexcept;
    355 constexpr month  operator+(const months& x,  const month& y) noexcept;
    356 constexpr month  operator-(const month&  x, const months& y) noexcept;
    357 constexpr months operator-(const month&  x,  const month& y) noexcept;
    358 
    359 // 25.8.5, class year    // C++20
    360 class year;
    361 constexpr bool operator==(const year& x, const year& y) noexcept;
    362 constexpr bool operator!=(const year& x, const year& y) noexcept;
    363 constexpr bool operator< (const year& x, const year& y) noexcept;
    364 constexpr bool operator> (const year& x, const year& y) noexcept;
    365 constexpr bool operator<=(const year& x, const year& y) noexcept;
    366 constexpr bool operator>=(const year& x, const year& y) noexcept;
    367 constexpr year  operator+(const year&  x, const years& y) noexcept;
    368 constexpr year  operator+(const years& x, const year&  y) noexcept;
    369 constexpr year  operator-(const year&  x, const years& y) noexcept;
    370 constexpr years operator-(const year&  x, const year&  y) noexcept;
    371 
    372 // 25.8.6, class weekday    // C++20
    373 class weekday;
    374 
    375 constexpr bool operator==(const weekday& x, const weekday& y) noexcept;
    376 constexpr bool operator!=(const weekday& x, const weekday& y) noexcept;
    377 constexpr weekday operator+(const weekday& x, const days&    y) noexcept;
    378 constexpr weekday operator+(const days&    x, const weekday& y) noexcept;
    379 constexpr weekday operator-(const weekday& x, const days&    y) noexcept;
    380 constexpr days    operator-(const weekday& x, const weekday& y) noexcept;
    381 
    382 // 25.8.7, class weekday_indexed    // C++20
    383 
    384 class weekday_indexed;
    385 constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept;
    386 constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept;
    387 
    388 // 25.8.8, class weekday_last    // C++20
    389 class weekday_last;
    390 
    391 constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept;
    392 constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept;
    393 
    394 // 25.8.9, class month_day    // C++20
    395 class month_day;
    396 
    397 constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
    398 constexpr bool operator!=(const month_day& x, const month_day& y) noexcept;
    399 constexpr bool operator< (const month_day& x, const month_day& y) noexcept;
    400 constexpr bool operator> (const month_day& x, const month_day& y) noexcept;
    401 constexpr bool operator<=(const month_day& x, const month_day& y) noexcept;
    402 constexpr bool operator>=(const month_day& x, const month_day& y) noexcept;
    403 
    404 
    405 // 25.8.10, class month_day_last    // C++20
    406 class month_day_last;
    407 
    408 constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept;
    409 constexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept;
    410 constexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept;
    411 constexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept;
    412 constexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept;
    413 constexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept;
    414 
    415 // 25.8.11, class month_weekday    // C++20
    416 class month_weekday;
    417 
    418 constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept;
    419 constexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept;
    420 
    421 // 25.8.12, class month_weekday_last    // C++20
    422 class month_weekday_last;
    423 
    424 constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept;
    425 constexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept;
    426 
    427 
    428 // 25.8.13, class year_month    // C++20
    429 class year_month;
    430 
    431 constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
    432 constexpr bool operator!=(const year_month& x, const year_month& y) noexcept;
    433 constexpr bool operator< (const year_month& x, const year_month& y) noexcept;
    434 constexpr bool operator> (const year_month& x, const year_month& y) noexcept;
    435 constexpr bool operator<=(const year_month& x, const year_month& y) noexcept;
    436 constexpr bool operator>=(const year_month& x, const year_month& y) noexcept;
    437 
    438 constexpr year_month operator+(const year_month& ym, const months& dm) noexcept;
    439 constexpr year_month operator+(const months& dm, const year_month& ym) noexcept;
    440 constexpr year_month operator-(const year_month& ym, const months& dm) noexcept;
    441 constexpr months operator-(const year_month& x, const year_month& y) noexcept;
    442 constexpr year_month operator+(const year_month& ym, const years& dy) noexcept;
    443 constexpr year_month operator+(const years& dy, const year_month& ym) noexcept;
    444 constexpr year_month operator-(const year_month& ym, const years& dy) noexcept;
    445 
    446 // 25.8.14, class year_month_day class    // C++20
    447 year_month_day;
    448 
    449 constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
    450 constexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept;
    451 constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept;
    452 constexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept;
    453 constexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept;
    454 constexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept;
    455 
    456 constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept;
    457 constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept;
    458 constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept;
    459 constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept;
    460 constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept;
    461 constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept;
    462 
    463 
    464 // 25.8.15, class year_month_day_last    // C++20
    465 class year_month_day_last;
    466 
    467 constexpr bool operator==(const year_month_day_last& x,
    468                           const year_month_day_last& y) noexcept;
    469 constexpr bool operator!=(const year_month_day_last& x,
    470                           const year_month_day_last& y) noexcept;
    471 constexpr bool operator< (const year_month_day_last& x,
    472                           const year_month_day_last& y) noexcept;
    473 constexpr bool operator> (const year_month_day_last& x,
    474                           const year_month_day_last& y) noexcept;
    475 constexpr bool operator<=(const year_month_day_last& x,
    476                           const year_month_day_last& y) noexcept;
    477 constexpr bool operator>=(const year_month_day_last& x,
    478                           const year_month_day_last& y) noexcept;
    479 
    480 constexpr year_month_day_last
    481   operator+(const year_month_day_last& ymdl, const months& dm) noexcept;
    482 constexpr year_month_day_last
    483   operator+(const months& dm, const year_month_day_last& ymdl) noexcept;
    484 constexpr year_month_day_last
    485   operator+(const year_month_day_last& ymdl, const years& dy) noexcept;
    486 constexpr year_month_day_last
    487   operator+(const years& dy, const year_month_day_last& ymdl) noexcept;
    488 constexpr year_month_day_last
    489   operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
    490 constexpr year_month_day_last
    491   operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
    492 
    493 // 25.8.16, class year_month_weekday    // C++20
    494 class year_month_weekday;
    495 
    496 constexpr bool operator==(const year_month_weekday& x,
    497                           const year_month_weekday& y) noexcept;
    498 constexpr bool operator!=(const year_month_weekday& x,
    499                           const year_month_weekday& y) noexcept;
    500 
    501 constexpr year_month_weekday
    502   operator+(const year_month_weekday& ymwd, const months& dm) noexcept;
    503 constexpr year_month_weekday
    504   operator+(const months& dm, const year_month_weekday& ymwd) noexcept;
    505 constexpr year_month_weekday
    506   operator+(const year_month_weekday& ymwd, const years& dy) noexcept;
    507 constexpr year_month_weekday
    508   operator+(const years& dy, const year_month_weekday& ymwd) noexcept;
    509 constexpr year_month_weekday
    510   operator-(const year_month_weekday& ymwd, const months& dm) noexcept;
    511 constexpr year_month_weekday
    512   operator-(const year_month_weekday& ymwd, const years& dy) noexcept;
    513 
    514 // 25.8.17, class year_month_weekday_last    // C++20
    515 class year_month_weekday_last;
    516 
    517 constexpr bool operator==(const year_month_weekday_last& x,
    518                           const year_month_weekday_last& y) noexcept;
    519 constexpr bool operator!=(const year_month_weekday_last& x,
    520                           const year_month_weekday_last& y) noexcept;
    521 constexpr year_month_weekday_last
    522   operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
    523 constexpr year_month_weekday_last
    524   operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept;
    525 constexpr year_month_weekday_last
    526   operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
    527 constexpr year_month_weekday_last
    528   operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept;
    529 constexpr year_month_weekday_last
    530   operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
    531 constexpr year_month_weekday_last
    532   operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
    533 
    534 // 25.8.18, civil calendar conventional syntax operators    // C++20
    535 constexpr year_month
    536   operator/(const year& y, const month& m) noexcept;
    537 constexpr year_month
    538   operator/(const year& y, int m) noexcept;
    539 constexpr month_day
    540   operator/(const month& m, const day& d) noexcept;
    541 constexpr month_day
    542   operator/(const month& m, int d) noexcept;
    543 constexpr month_day
    544   operator/(int m, const day& d) noexcept;
    545 constexpr month_day
    546   operator/(const day& d, const month& m) noexcept;
    547 constexpr month_day
    548   operator/(const day& d, int m) noexcept;
    549 constexpr month_day_last
    550   operator/(const month& m, last_spec) noexcept;
    551 constexpr month_day_last
    552   operator/(int m, last_spec) noexcept;
    553 constexpr month_day_last
    554   operator/(last_spec, const month& m) noexcept;
    555 constexpr month_day_last
    556   operator/(last_spec, int m) noexcept;
    557 constexpr month_weekday
    558   operator/(const month& m, const weekday_indexed& wdi) noexcept;
    559 constexpr month_weekday
    560   operator/(int m, const weekday_indexed& wdi) noexcept;
    561 constexpr month_weekday
    562   operator/(const weekday_indexed& wdi, const month& m) noexcept;
    563 constexpr month_weekday
    564   operator/(const weekday_indexed& wdi, int m) noexcept;
    565 constexpr month_weekday_last
    566   operator/(const month& m, const weekday_last& wdl) noexcept;
    567 constexpr month_weekday_last
    568   operator/(int m, const weekday_last& wdl) noexcept;
    569 constexpr month_weekday_last
    570   operator/(const weekday_last& wdl, const month& m) noexcept;
    571 constexpr month_weekday_last
    572   operator/(const weekday_last& wdl, int m) noexcept;
    573 constexpr year_month_day
    574   operator/(const year_month& ym, const day& d) noexcept;
    575 constexpr year_month_day
    576   operator/(const year_month& ym, int d) noexcept;
    577 constexpr year_month_day
    578   operator/(const year& y, const month_day& md) noexcept;
    579 constexpr year_month_day
    580   operator/(int y, const month_day& md) noexcept;
    581 constexpr year_month_day
    582   operator/(const month_day& md, const year& y) noexcept;
    583 constexpr year_month_day
    584   operator/(const month_day& md, int y) noexcept;
    585 constexpr year_month_day_last
    586   operator/(const year_month& ym, last_spec) noexcept;
    587 constexpr year_month_day_last
    588   operator/(const year& y, const month_day_last& mdl) noexcept;
    589 constexpr year_month_day_last
    590   operator/(int y, const month_day_last& mdl) noexcept;
    591 constexpr year_month_day_last
    592   operator/(const month_day_last& mdl, const year& y) noexcept;
    593 constexpr year_month_day_last
    594   operator/(const month_day_last& mdl, int y) noexcept;
    595 constexpr year_month_weekday
    596   operator/(const year_month& ym, const weekday_indexed& wdi) noexcept;
    597 constexpr year_month_weekday
    598   operator/(const year& y, const month_weekday& mwd) noexcept;
    599 constexpr year_month_weekday
    600   operator/(int y, const month_weekday& mwd) noexcept;
    601 constexpr year_month_weekday
    602   operator/(const month_weekday& mwd, const year& y) noexcept;
    603 constexpr year_month_weekday
    604   operator/(const month_weekday& mwd, int y) noexcept;
    605 constexpr year_month_weekday_last
    606   operator/(const year_month& ym, const weekday_last& wdl) noexcept;
    607 constexpr year_month_weekday_last
    608   operator/(const year& y, const month_weekday_last& mwdl) noexcept;
    609 constexpr year_month_weekday_last
    610   operator/(int y, const month_weekday_last& mwdl) noexcept;
    611 constexpr year_month_weekday_last
    612   operator/(const month_weekday_last& mwdl, const year& y) noexcept;
    613 constexpr year_month_weekday_last
    614   operator/(const month_weekday_last& mwdl, int y) noexcept;
    615 
    616 // 25.9, class template time_of_day    // C++20
    617 template<class Duration> class time_of_day;
    618 
    619 template<> class time_of_day<hours>;
    620 template<> class time_of_day<minutes>;
    621 template<> class time_of_day<seconds>;
    622 template<class Rep, class Period> class time_of_day<duration<Rep, Period>>;
    623 
    624 // 25.10.2, time zone database     // C++20
    625 struct tzdb;
    626 class tzdb_list;
    627 
    628 // 25.10.2.3, time zone database access    // C++20
    629 const tzdb& get_tzdb();
    630 tzdb_list& get_tzdb_list();
    631 const time_zone* locate_zone(string_view tz_name);
    632 const time_zone* current_zone();
    633 
    634 // 25.10.2.4, remote time zone database support    // C++20
    635 const tzdb& reload_tzdb();
    636 string remote_version();
    637 
    638 // 25.10.3, exception classes    // C++20
    639 class nonexistent_local_time;
    640 class ambiguous_local_time;
    641 
    642 // 25.10.4, information classes    // C++20
    643 struct sys_info;
    644 struct local_info;
    645 
    646 // 25.10.5, class time_zone    // C++20
    647 enum class choose {earliest, latest};
    648 class time_zone;
    649 bool operator==(const time_zone& x, const time_zone& y) noexcept;
    650 bool operator!=(const time_zone& x, const time_zone& y) noexcept;
    651 bool operator<(const time_zone& x, const time_zone& y) noexcept;
    652 bool operator>(const time_zone& x, const time_zone& y) noexcept;
    653 bool operator<=(const time_zone& x, const time_zone& y) noexcept;
    654 bool operator>=(const time_zone& x, const time_zone& y) noexcept;
    655 
    656 // 25.10.6, class template zoned_traits    // C++20
    657 template<class T> struct zoned_traits;
    658 
    659 // 25.10.7, class template zoned_time    // C++20
    660 template<class Duration, class TimeZonePtr = const time_zone*> class zoned_time;
    661 using zoned_seconds = zoned_time<seconds>;
    662 
    663 template<class Duration1, class Duration2, class TimeZonePtr>
    664   bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
    665                   const zoned_time<Duration2, TimeZonePtr>& y);
    666 template<class Duration1, class Duration2, class TimeZonePtr>
    667   bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x,
    668                   const zoned_time<Duration2, TimeZonePtr>& y);
    669 
    670 // 25.10.8, leap second support    // C++20
    671 class leap;
    672 
    673 bool operator==(const leap& x, const leap& y);
    674 bool operator!=(const leap& x, const leap& y);
    675 bool operator< (const leap& x, const leap& y);
    676 bool operator> (const leap& x, const leap& y);
    677 bool operator<=(const leap& x, const leap& y);
    678 bool operator>=(const leap& x, const leap& y);
    679 template<class Duration>
    680   bool operator==(const leap& x, const sys_time<Duration>& y);
    681 template<class Duration>
    682   bool operator==(const sys_time<Duration>& x, const leap& y);
    683 template<class Duration>
    684   bool operator!=(const leap& x, const sys_time<Duration>& y);
    685 template<class Duration>
    686   bool operator!=(const sys_time<Duration>& x, const leap& y);
    687 template<class Duration>
    688   bool operator< (const leap& x, const sys_time<Duration>& y);
    689 template<class Duration>
    690   bool operator< (const sys_time<Duration>& x, const leap& y);
    691 template<class Duration>
    692   bool operator> (const leap& x, const sys_time<Duration>& y);
    693 template<class Duration>
    694   bool operator> (const sys_time<Duration>& x, const leap& y);
    695 template<class Duration>
    696   bool operator<=(const leap& x, const sys_time<Duration>& y);
    697 template<class Duration>
    698   bool operator<=(const sys_time<Duration>& x, const leap& y);
    699 template<class Duration>
    700   bool operator>=(const leap& x, const sys_time<Duration>& y);
    701 template<class Duration>
    702   bool operator>=(const sys_time<Duration>& x, const leap& y);
    703 
    704 // 25.10.9, class link    // C++20
    705 class link;
    706 bool operator==(const link& x, const link& y);
    707 bool operator!=(const link& x, const link& y);
    708 bool operator< (const link& x, const link& y);
    709 bool operator> (const link& x, const link& y);
    710 bool operator<=(const link& x, const link& y);
    711 bool operator>=(const link& x, const link& y);
    712 
    713 // 25.11, formatting    // C++20
    714 template<class charT, class Streamable>
    715   basic_string<charT>
    716     format(const charT* fmt, const Streamable& s);
    717 
    718 template<class charT, class Streamable>
    719   basic_string<charT>
    720     format(const locale& loc, const charT* fmt, const Streamable& s);
    721 
    722 template<class charT, class traits, class Alloc, class Streamable>
    723   basic_string<charT, traits, Alloc>
    724     format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s);
    725 
    726 template<class charT, class traits, class Alloc, class Streamable>
    727   basic_string<charT, traits, Alloc>
    728     format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt,
    729            const Streamable& s);
    730 
    731 // 25.12, parsing    // C++20
    732 template<class charT, class traits, class Alloc, class Parsable>
    733 unspecified
    734     parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp);
    735 
    736 template<class charT, class traits, class Alloc, class Parsable>
    737 unspecified
    738     parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
    739           basic_string<charT, traits, Alloc>& abbrev);
    740 
    741 template<class charT, class traits, class Alloc, class Parsable>
    742 unspecified
    743     parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
    744           minutes& offset);
    745 
    746 template<class charT, class traits, class Alloc, class Parsable>
    747 unspecified
    748     parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
    749           basic_string<charT, traits, Alloc>& abbrev, minutes& offset);
    750 
    751 // calendrical constants
    752 inline constexpr last_spec                              last{};       // C++20
    753 inline constexpr chrono::weekday                        Sunday{0};    // C++20
    754 inline constexpr chrono::weekday                        Monday{1};    // C++20
    755 inline constexpr chrono::weekday                        Tuesday{2};   // C++20
    756 inline constexpr chrono::weekday                        Wednesday{3}; // C++20
    757 inline constexpr chrono::weekday                        Thursday{4};  // C++20
    758 inline constexpr chrono::weekday                        Friday{5};    // C++20
    759 inline constexpr chrono::weekday                        Saturday{6};  // C++20
    760 
    761 inline constexpr chrono::month                          January{1};   // C++20
    762 inline constexpr chrono::month                          February{2};  // C++20
    763 inline constexpr chrono::month                          March{3};     // C++20
    764 inline constexpr chrono::month                          April{4};     // C++20
    765 inline constexpr chrono::month                          May{5};       // C++20
    766 inline constexpr chrono::month                          June{6};      // C++20
    767 inline constexpr chrono::month                          July{7};      // C++20
    768 inline constexpr chrono::month                          August{8};    // C++20
    769 inline constexpr chrono::month                          September{9}; // C++20
    770 inline constexpr chrono::month                          October{10};  // C++20
    771 inline constexpr chrono::month                          November{11}; // C++20
    772 inline constexpr chrono::month                          December{12}; // C++20
    773 }  // chrono
    774 
    775 inline namespace literals {
    776   inline namespace chrono_literals {
    777 constexpr chrono::hours                                 operator ""h(unsigned long long); // C++14
    778 constexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14
    779 constexpr chrono::minutes                               operator ""min(unsigned long long); // C++14
    780 constexpr chrono::duration<unspecified , ratio<60,1>>   operator ""min(long double); // C++14
    781 constexpr chrono::seconds                               operator ""s(unsigned long long); // C++14
    782 constexpr chrono::duration<unspecified >                operator ""s(long double); // C++14
    783 constexpr chrono::milliseconds                          operator ""ms(unsigned long long); // C++14
    784 constexpr chrono::duration<unspecified , milli>         operator ""ms(long double); // C++14
    785 constexpr chrono::microseconds                          operator ""us(unsigned long long); // C++14
    786 constexpr chrono::duration<unspecified , micro>         operator ""us(long double); // C++14
    787 constexpr chrono::nanoseconds                           operator ""ns(unsigned long long); // C++14
    788 constexpr chrono::duration<unspecified , nano>          operator ""ns(long double); // C++14
    789 constexpr chrono::day                                   operator ""d(unsigned long long d) noexcept; // C++20
    790 constexpr chrono::year                                  operator ""y(unsigned long long y) noexcept; // C++20
    791 }  // chrono_literals
    792 }  // literals
    793 
    794 }  // std
    795 */
    796 
    797 #include <__config>
    798 #include <ctime>
    799 #include <type_traits>
    800 #include <ratio>
    801 #include <limits>
    802 #include <version>
    803 
    804 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
    805 #pragma GCC system_header
    806 #endif
    807 
    808 _LIBCPP_PUSH_MACROS
    809 #include <__undef_macros>
    810 
    811 #ifndef _LIBCPP_CXX03_LANG
    812 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
    813 struct _FilesystemClock;
    814 _LIBCPP_END_NAMESPACE_FILESYSTEM
    815 #endif // !_LIBCPP_CXX03_LANG
    816 
    817 _LIBCPP_BEGIN_NAMESPACE_STD
    818 
    819 namespace chrono
    820 {
    821 
    822 template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration;
    823 
    824 template <class _Tp>
    825 struct __is_duration : false_type {};
    826 
    827 template <class _Rep, class _Period>
    828 struct __is_duration<duration<_Rep, _Period> > : true_type  {};
    829 
    830 template <class _Rep, class _Period>
    831 struct __is_duration<const duration<_Rep, _Period> > : true_type  {};
    832 
    833 template <class _Rep, class _Period>
    834 struct __is_duration<volatile duration<_Rep, _Period> > : true_type  {};
    835 
    836 template <class _Rep, class _Period>
    837 struct __is_duration<const volatile duration<_Rep, _Period> > : true_type  {};
    838 
    839 } // chrono
    840 
    841 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
    842 struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>,
    843                                          chrono::duration<_Rep2, _Period2> >
    844 {
    845     typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
    846                              typename __ratio_gcd<_Period1, _Period2>::type> type;
    847 };
    848 
    849 namespace chrono {
    850 
    851 // duration_cast
    852 
    853 template <class _FromDuration, class _ToDuration,
    854           class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
    855           bool = _Period::num == 1,
    856           bool = _Period::den == 1>
    857 struct __duration_cast;
    858 
    859 template <class _FromDuration, class _ToDuration, class _Period>
    860 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
    861 {
    862     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
    863     _ToDuration operator()(const _FromDuration& __fd) const
    864     {
    865         return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
    866     }
    867 };
    868 
    869 template <class _FromDuration, class _ToDuration, class _Period>
    870 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
    871 {
    872     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
    873     _ToDuration operator()(const _FromDuration& __fd) const
    874     {
    875         typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
    876         return _ToDuration(static_cast<typename _ToDuration::rep>(
    877                            static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
    878     }
    879 };
    880 
    881 template <class _FromDuration, class _ToDuration, class _Period>
    882 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
    883 {
    884     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
    885     _ToDuration operator()(const _FromDuration& __fd) const
    886     {
    887         typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
    888         return _ToDuration(static_cast<typename _ToDuration::rep>(
    889                            static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
    890     }
    891 };
    892 
    893 template <class _FromDuration, class _ToDuration, class _Period>
    894 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
    895 {
    896     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
    897     _ToDuration operator()(const _FromDuration& __fd) const
    898     {
    899         typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
    900         return _ToDuration(static_cast<typename _ToDuration::rep>(
    901                            static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
    902                                                           / static_cast<_Ct>(_Period::den)));
    903     }
    904 };
    905 
    906 template <class _ToDuration, class _Rep, class _Period>
    907 inline _LIBCPP_INLINE_VISIBILITY
    908 _LIBCPP_CONSTEXPR
    909 typename enable_if
    910 <
    911     __is_duration<_ToDuration>::value,
    912     _ToDuration
    913 >::type
    914 duration_cast(const duration<_Rep, _Period>& __fd)
    915 {
    916     return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
    917 }
    918 
    919 template <class _Rep>
    920 struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
    921 
    922 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
    923 template <class _Rep>
    924 _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v
    925     = treat_as_floating_point<_Rep>::value;
    926 #endif
    927 
    928 template <class _Rep>
    929 struct _LIBCPP_TEMPLATE_VIS duration_values
    930 {
    931 public:
    932     _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);}
    933     _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max()  _NOEXCEPT {return numeric_limits<_Rep>::max();}
    934     _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min()  _NOEXCEPT {return numeric_limits<_Rep>::lowest();}
    935 };
    936 
    937 #if _LIBCPP_STD_VER > 14
    938 template <class _ToDuration, class _Rep, class _Period>
    939 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
    940 typename enable_if
    941 <
    942     __is_duration<_ToDuration>::value,
    943     _ToDuration
    944 >::type
    945 floor(const duration<_Rep, _Period>& __d)
    946 {
    947     _ToDuration __t = duration_cast<_ToDuration>(__d);
    948     if (__t > __d)
    949         __t = __t - _ToDuration{1};
    950     return __t;
    951 }
    952 
    953 template <class _ToDuration, class _Rep, class _Period>
    954 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
    955 typename enable_if
    956 <
    957     __is_duration<_ToDuration>::value,
    958     _ToDuration
    959 >::type
    960 ceil(const duration<_Rep, _Period>& __d)
    961 {
    962     _ToDuration __t = duration_cast<_ToDuration>(__d);
    963     if (__t < __d)
    964         __t = __t + _ToDuration{1};
    965     return __t;
    966 }
    967 
    968 template <class _ToDuration, class _Rep, class _Period>
    969 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
    970 typename enable_if
    971 <
    972     __is_duration<_ToDuration>::value,
    973     _ToDuration
    974 >::type
    975 round(const duration<_Rep, _Period>& __d)
    976 {
    977     _ToDuration __lower = floor<_ToDuration>(__d);
    978     _ToDuration __upper = __lower + _ToDuration{1};
    979     auto __lowerDiff = __d - __lower;
    980     auto __upperDiff = __upper - __d;
    981     if (__lowerDiff < __upperDiff)
    982         return __lower;
    983     if (__lowerDiff > __upperDiff)
    984         return __upper;
    985     return __lower.count() & 1 ? __upper : __lower;
    986 }
    987 #endif
    988 
    989 // duration
    990 
    991 template <class _Rep, class _Period>
    992 class _LIBCPP_TEMPLATE_VIS duration
    993 {
    994     static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
    995     static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
    996     static_assert(_Period::num > 0, "duration period must be positive");
    997 
    998     template <class _R1, class _R2>
    999     struct __no_overflow
   1000     {
   1001     private:
   1002         static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
   1003         static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
   1004         static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
   1005         static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
   1006         static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
   1007         static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
   1008         static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
   1009 
   1010         template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
   1011         struct __mul    // __overflow == false
   1012         {
   1013             static const intmax_t value = _Xp * _Yp;
   1014         };
   1015 
   1016         template <intmax_t _Xp, intmax_t _Yp>
   1017         struct __mul<_Xp, _Yp, true>
   1018         {
   1019             static const intmax_t value = 1;
   1020         };
   1021 
   1022     public:
   1023         static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
   1024         typedef ratio<__mul<__n1, __d2, !value>::value,
   1025                       __mul<__n2, __d1, !value>::value> type;
   1026     };
   1027 
   1028 public:
   1029     typedef _Rep rep;
   1030     typedef typename _Period::type period;
   1031 private:
   1032     rep __rep_;
   1033 public:
   1034 
   1035     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
   1036 #ifndef _LIBCPP_CXX03_LANG
   1037         duration() = default;
   1038 #else
   1039         duration() {}
   1040 #endif
   1041 
   1042     template <class _Rep2>
   1043         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
   1044         explicit duration(const _Rep2& __r,
   1045             typename enable_if
   1046             <
   1047                is_convertible<_Rep2, rep>::value &&
   1048                (treat_as_floating_point<rep>::value ||
   1049                !treat_as_floating_point<_Rep2>::value)
   1050             >::type* = 0)
   1051                 : __rep_(__r) {}
   1052 
   1053     // conversions
   1054     template <class _Rep2, class _Period2>
   1055         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
   1056         duration(const duration<_Rep2, _Period2>& __d,
   1057             typename enable_if
   1058             <
   1059                 __no_overflow<_Period2, period>::value && (
   1060                 treat_as_floating_point<rep>::value ||
   1061                 (__no_overflow<_Period2, period>::type::den == 1 &&
   1062                  !treat_as_floating_point<_Rep2>::value))
   1063             >::type* = 0)
   1064                 : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
   1065 
   1066     // observer
   1067 
   1068     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
   1069 
   1070     // arithmetic
   1071 
   1072     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
   1073     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
   1074     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++()      {++__rep_; return *this;}
   1075     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration  operator++(int)   {return duration(__rep_++);}
   1076     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--()      {--__rep_; return *this;}
   1077     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration  operator--(int)   {return duration(__rep_--);}
   1078 
   1079     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
   1080     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
   1081 
   1082     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
   1083     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
   1084     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
   1085     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
   1086 
   1087     // special values
   1088 
   1089     _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());}
   1090     _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min()  _NOEXCEPT {return duration(duration_values<rep>::min());}
   1091     _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max()  _NOEXCEPT {return duration(duration_values<rep>::max());}
   1092 };
   1093 
   1094 typedef duration<long long,         nano> nanoseconds;
   1095 typedef duration<long long,        micro> microseconds;
   1096 typedef duration<long long,        milli> milliseconds;
   1097 typedef duration<long long              > seconds;
   1098 typedef duration<     long, ratio<  60> > minutes;
   1099 typedef duration<     long, ratio<3600> > hours;
   1100 #if _LIBCPP_STD_VER > 17
   1101 typedef duration<     int, ratio_multiply<ratio<24>, hours::period>>         days;
   1102 typedef duration<     int, ratio_multiply<ratio<7>,   days::period>>         weeks;
   1103 typedef duration<     int, ratio_multiply<ratio<146097, 400>, days::period>> years;
   1104 typedef duration<     int, ratio_divide<years::period, ratio<12>>>           months;
   1105 #endif
   1106 // Duration ==
   1107 
   1108 template <class _LhsDuration, class _RhsDuration>
   1109 struct __duration_eq
   1110 {
   1111     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
   1112     bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
   1113         {
   1114             typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
   1115             return _Ct(__lhs).count() == _Ct(__rhs).count();
   1116         }
   1117 };
   1118 
   1119 template <class _LhsDuration>
   1120 struct __duration_eq<_LhsDuration, _LhsDuration>
   1121 {
   1122     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
   1123     bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
   1124         {return __lhs.count() == __rhs.count();}
   1125 };
   1126 
   1127 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
   1128 inline _LIBCPP_INLINE_VISIBILITY
   1129 _LIBCPP_CONSTEXPR
   1130 bool
   1131 operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1132 {
   1133     return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
   1134 }
   1135 
   1136 // Duration !=
   1137 
   1138 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
   1139 inline _LIBCPP_INLINE_VISIBILITY
   1140 _LIBCPP_CONSTEXPR
   1141 bool
   1142 operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1143 {
   1144     return !(__lhs == __rhs);
   1145 }
   1146 
   1147 // Duration <
   1148 
   1149 template <class _LhsDuration, class _RhsDuration>
   1150 struct __duration_lt
   1151 {
   1152     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
   1153     bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
   1154         {
   1155             typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
   1156             return _Ct(__lhs).count() < _Ct(__rhs).count();
   1157         }
   1158 };
   1159 
   1160 template <class _LhsDuration>
   1161 struct __duration_lt<_LhsDuration, _LhsDuration>
   1162 {
   1163     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
   1164     bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
   1165         {return __lhs.count() < __rhs.count();}
   1166 };
   1167 
   1168 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
   1169 inline _LIBCPP_INLINE_VISIBILITY
   1170 _LIBCPP_CONSTEXPR
   1171 bool
   1172 operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1173 {
   1174     return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
   1175 }
   1176 
   1177 // Duration >
   1178 
   1179 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
   1180 inline _LIBCPP_INLINE_VISIBILITY
   1181 _LIBCPP_CONSTEXPR
   1182 bool
   1183 operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1184 {
   1185     return __rhs < __lhs;
   1186 }
   1187 
   1188 // Duration <=
   1189 
   1190 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
   1191 inline _LIBCPP_INLINE_VISIBILITY
   1192 _LIBCPP_CONSTEXPR
   1193 bool
   1194 operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1195 {
   1196     return !(__rhs < __lhs);
   1197 }
   1198 
   1199 // Duration >=
   1200 
   1201 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
   1202 inline _LIBCPP_INLINE_VISIBILITY
   1203 _LIBCPP_CONSTEXPR
   1204 bool
   1205 operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1206 {
   1207     return !(__lhs < __rhs);
   1208 }
   1209 
   1210 // Duration +
   1211 
   1212 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
   1213 inline _LIBCPP_INLINE_VISIBILITY
   1214 _LIBCPP_CONSTEXPR
   1215 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
   1216 operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1217 {
   1218     typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
   1219     return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
   1220 }
   1221 
   1222 // Duration -
   1223 
   1224 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
   1225 inline _LIBCPP_INLINE_VISIBILITY
   1226 _LIBCPP_CONSTEXPR
   1227 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
   1228 operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1229 {
   1230     typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
   1231     return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
   1232 }
   1233 
   1234 // Duration *
   1235 
   1236 template <class _Rep1, class _Period, class _Rep2>
   1237 inline _LIBCPP_INLINE_VISIBILITY
   1238 _LIBCPP_CONSTEXPR
   1239 typename enable_if
   1240 <
   1241     is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
   1242     duration<typename common_type<_Rep1, _Rep2>::type, _Period>
   1243 >::type
   1244 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
   1245 {
   1246     typedef typename common_type<_Rep1, _Rep2>::type _Cr;
   1247     typedef duration<_Cr, _Period> _Cd;
   1248     return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
   1249 }
   1250 
   1251 template <class _Rep1, class _Period, class _Rep2>
   1252 inline _LIBCPP_INLINE_VISIBILITY
   1253 _LIBCPP_CONSTEXPR
   1254 typename enable_if
   1255 <
   1256     is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
   1257     duration<typename common_type<_Rep1, _Rep2>::type, _Period>
   1258 >::type
   1259 operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
   1260 {
   1261     return __d * __s;
   1262 }
   1263 
   1264 // Duration /
   1265 
   1266 template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
   1267 struct __duration_divide_result
   1268 {
   1269 };
   1270 
   1271 template <class _Duration, class _Rep2,
   1272     bool = is_convertible<_Rep2,
   1273                           typename common_type<typename _Duration::rep, _Rep2>::type>::value>
   1274 struct __duration_divide_imp
   1275 {
   1276 };
   1277 
   1278 template <class _Rep1, class _Period, class _Rep2>
   1279 struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
   1280 {
   1281     typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
   1282 };
   1283 
   1284 template <class _Rep1, class _Period, class _Rep2>
   1285 struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
   1286     : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
   1287 {
   1288 };
   1289 
   1290 template <class _Rep1, class _Period, class _Rep2>
   1291 inline _LIBCPP_INLINE_VISIBILITY
   1292 _LIBCPP_CONSTEXPR
   1293 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
   1294 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
   1295 {
   1296     typedef typename common_type<_Rep1, _Rep2>::type _Cr;
   1297     typedef duration<_Cr, _Period> _Cd;
   1298     return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
   1299 }
   1300 
   1301 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
   1302 inline _LIBCPP_INLINE_VISIBILITY
   1303 _LIBCPP_CONSTEXPR
   1304 typename common_type<_Rep1, _Rep2>::type
   1305 operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1306 {
   1307     typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
   1308     return _Ct(__lhs).count() / _Ct(__rhs).count();
   1309 }
   1310 
   1311 // Duration %
   1312 
   1313 template <class _Rep1, class _Period, class _Rep2>
   1314 inline _LIBCPP_INLINE_VISIBILITY
   1315 _LIBCPP_CONSTEXPR
   1316 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
   1317 operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
   1318 {
   1319     typedef typename common_type<_Rep1, _Rep2>::type _Cr;
   1320     typedef duration<_Cr, _Period> _Cd;
   1321     return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
   1322 }
   1323 
   1324 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
   1325 inline _LIBCPP_INLINE_VISIBILITY
   1326 _LIBCPP_CONSTEXPR
   1327 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
   1328 operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1329 {
   1330     typedef typename common_type<_Rep1, _Rep2>::type _Cr;
   1331     typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
   1332     return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
   1333 }
   1334 
   1335 //////////////////////////////////////////////////////////
   1336 ///////////////////// time_point /////////////////////////
   1337 //////////////////////////////////////////////////////////
   1338 
   1339 template <class _Clock, class _Duration = typename _Clock::duration>
   1340 class _LIBCPP_TEMPLATE_VIS time_point
   1341 {
   1342     static_assert(__is_duration<_Duration>::value,
   1343                   "Second template parameter of time_point must be a std::chrono::duration");
   1344 public:
   1345     typedef _Clock                    clock;
   1346     typedef _Duration                 duration;
   1347     typedef typename duration::rep    rep;
   1348     typedef typename duration::period period;
   1349 private:
   1350     duration __d_;
   1351 
   1352 public:
   1353     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
   1354     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
   1355 
   1356     // conversions
   1357     template <class _Duration2>
   1358     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1359     time_point(const time_point<clock, _Duration2>& t,
   1360         typename enable_if
   1361         <
   1362             is_convertible<_Duration2, duration>::value
   1363         >::type* = 0)
   1364             : __d_(t.time_since_epoch()) {}
   1365 
   1366     // observer
   1367 
   1368     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
   1369 
   1370     // arithmetic
   1371 
   1372     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
   1373     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
   1374 
   1375     // special values
   1376 
   1377     _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());}
   1378     _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());}
   1379 };
   1380 
   1381 } // chrono
   1382 
   1383 template <class _Clock, class _Duration1, class _Duration2>
   1384 struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
   1385                                          chrono::time_point<_Clock, _Duration2> >
   1386 {
   1387     typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
   1388 };
   1389 
   1390 namespace chrono {
   1391 
   1392 template <class _ToDuration, class _Clock, class _Duration>
   1393 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1394 time_point<_Clock, _ToDuration>
   1395 time_point_cast(const time_point<_Clock, _Duration>& __t)
   1396 {
   1397     return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
   1398 }
   1399 
   1400 #if _LIBCPP_STD_VER > 14
   1401 template <class _ToDuration, class _Clock, class _Duration>
   1402 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
   1403 typename enable_if
   1404 <
   1405     __is_duration<_ToDuration>::value,
   1406     time_point<_Clock, _ToDuration>
   1407 >::type
   1408 floor(const time_point<_Clock, _Duration>& __t)
   1409 {
   1410     return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
   1411 }
   1412 
   1413 template <class _ToDuration, class _Clock, class _Duration>
   1414 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
   1415 typename enable_if
   1416 <
   1417     __is_duration<_ToDuration>::value,
   1418     time_point<_Clock, _ToDuration>
   1419 >::type
   1420 ceil(const time_point<_Clock, _Duration>& __t)
   1421 {
   1422     return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
   1423 }
   1424 
   1425 template <class _ToDuration, class _Clock, class _Duration>
   1426 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
   1427 typename enable_if
   1428 <
   1429     __is_duration<_ToDuration>::value,
   1430     time_point<_Clock, _ToDuration>
   1431 >::type
   1432 round(const time_point<_Clock, _Duration>& __t)
   1433 {
   1434     return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
   1435 }
   1436 
   1437 template <class _Rep, class _Period>
   1438 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
   1439 typename enable_if
   1440 <
   1441     numeric_limits<_Rep>::is_signed,
   1442     duration<_Rep, _Period>
   1443 >::type
   1444 abs(duration<_Rep, _Period> __d)
   1445 {
   1446     return __d >= __d.zero() ? __d : -__d;
   1447 }
   1448 #endif
   1449 
   1450 // time_point ==
   1451 
   1452 template <class _Clock, class _Duration1, class _Duration2>
   1453 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1454 bool
   1455 operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
   1456 {
   1457     return __lhs.time_since_epoch() == __rhs.time_since_epoch();
   1458 }
   1459 
   1460 // time_point !=
   1461 
   1462 template <class _Clock, class _Duration1, class _Duration2>
   1463 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1464 bool
   1465 operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
   1466 {
   1467     return !(__lhs == __rhs);
   1468 }
   1469 
   1470 // time_point <
   1471 
   1472 template <class _Clock, class _Duration1, class _Duration2>
   1473 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1474 bool
   1475 operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
   1476 {
   1477     return __lhs.time_since_epoch() < __rhs.time_since_epoch();
   1478 }
   1479 
   1480 // time_point >
   1481 
   1482 template <class _Clock, class _Duration1, class _Duration2>
   1483 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1484 bool
   1485 operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
   1486 {
   1487     return __rhs < __lhs;
   1488 }
   1489 
   1490 // time_point <=
   1491 
   1492 template <class _Clock, class _Duration1, class _Duration2>
   1493 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1494 bool
   1495 operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
   1496 {
   1497     return !(__rhs < __lhs);
   1498 }
   1499 
   1500 // time_point >=
   1501 
   1502 template <class _Clock, class _Duration1, class _Duration2>
   1503 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1504 bool
   1505 operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
   1506 {
   1507     return !(__lhs < __rhs);
   1508 }
   1509 
   1510 // time_point operator+(time_point x, duration y);
   1511 
   1512 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
   1513 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1514 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
   1515 operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1516 {
   1517     typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
   1518     return _Tr (__lhs.time_since_epoch() + __rhs);
   1519 }
   1520 
   1521 // time_point operator+(duration x, time_point y);
   1522 
   1523 template <class _Rep1, class _Period1, class _Clock, class _Duration2>
   1524 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1525 time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
   1526 operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
   1527 {
   1528     return __rhs + __lhs;
   1529 }
   1530 
   1531 // time_point operator-(time_point x, duration y);
   1532 
   1533 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
   1534 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1535 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
   1536 operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
   1537 {
   1538     typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
   1539     return _Ret(__lhs.time_since_epoch() -__rhs);
   1540 }
   1541 
   1542 // duration operator-(time_point x, time_point y);
   1543 
   1544 template <class _Clock, class _Duration1, class _Duration2>
   1545 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1546 typename common_type<_Duration1, _Duration2>::type
   1547 operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
   1548 {
   1549     return __lhs.time_since_epoch() - __rhs.time_since_epoch();
   1550 }
   1551 
   1552 //////////////////////////////////////////////////////////
   1553 /////////////////////// clocks ///////////////////////////
   1554 //////////////////////////////////////////////////////////
   1555 
   1556 class _LIBCPP_TYPE_VIS system_clock
   1557 {
   1558 public:
   1559     typedef microseconds                     duration;
   1560     typedef duration::rep                    rep;
   1561     typedef duration::period                 period;
   1562     typedef chrono::time_point<system_clock> time_point;
   1563     static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
   1564 
   1565     static time_point now() _NOEXCEPT;
   1566     static time_t     to_time_t  (const time_point& __t) _NOEXCEPT;
   1567     static time_point from_time_t(time_t __t) _NOEXCEPT;
   1568 };
   1569 
   1570 #ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
   1571 class _LIBCPP_TYPE_VIS steady_clock
   1572 {
   1573 public:
   1574     typedef nanoseconds                                   duration;
   1575     typedef duration::rep                                 rep;
   1576     typedef duration::period                              period;
   1577     typedef chrono::time_point<steady_clock, duration>    time_point;
   1578     static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
   1579 
   1580     static time_point now() _NOEXCEPT;
   1581 };
   1582 
   1583 typedef steady_clock high_resolution_clock;
   1584 #else
   1585 typedef system_clock high_resolution_clock;
   1586 #endif
   1587 
   1588 #if _LIBCPP_STD_VER > 17
   1589 // [time.clock.file], type file_clock
   1590 using file_clock = _VSTD_FS::_FilesystemClock;
   1591 
   1592 template<class _Duration>
   1593 using file_time = time_point<file_clock, _Duration>;
   1594 
   1595 
   1596 template <class _Duration>
   1597 using sys_time    = time_point<system_clock, _Duration>;
   1598 using sys_seconds = sys_time<seconds>;
   1599 using sys_days    = sys_time<days>;
   1600 
   1601 struct local_t {};
   1602 template<class Duration>
   1603 using local_time  = time_point<local_t, Duration>;
   1604 using local_seconds = local_time<seconds>;
   1605 using local_days    = local_time<days>;
   1606 
   1607 
   1608 struct _LIBCPP_TYPE_VIS last_spec { explicit last_spec() = default; };
   1609 
   1610 class _LIBCPP_TYPE_VIS day {
   1611 private:
   1612     unsigned char __d;
   1613 public:
   1614     day() = default;
   1615     explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {}
   1616     inline constexpr day& operator++()    noexcept { ++__d; return *this; }
   1617     inline constexpr day  operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
   1618     inline constexpr day& operator--()    noexcept { --__d; return *this; }
   1619     inline constexpr day  operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
   1620            constexpr day& operator+=(const days& __dd) noexcept;
   1621            constexpr day& operator-=(const days& __dd) noexcept;
   1622     explicit inline constexpr operator unsigned() const noexcept { return __d; }
   1623     inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; }
   1624   };
   1625 
   1626 
   1627 inline constexpr
   1628 bool operator==(const day& __lhs, const day& __rhs) noexcept
   1629 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
   1630 
   1631 inline constexpr
   1632 bool operator!=(const day& __lhs, const day& __rhs) noexcept
   1633 { return !(__lhs == __rhs); }
   1634 
   1635 inline constexpr
   1636 bool operator< (const day& __lhs, const day& __rhs) noexcept
   1637 { return static_cast<unsigned>(__lhs) <  static_cast<unsigned>(__rhs); }
   1638 
   1639 inline constexpr
   1640 bool operator> (const day& __lhs, const day& __rhs) noexcept
   1641 { return __rhs < __lhs; }
   1642 
   1643 inline constexpr
   1644 bool operator<=(const day& __lhs, const day& __rhs) noexcept
   1645 { return !(__rhs < __lhs);}
   1646 
   1647 inline constexpr
   1648 bool operator>=(const day& __lhs, const day& __rhs) noexcept
   1649 { return !(__lhs < __rhs); }
   1650 
   1651 inline constexpr
   1652 day operator+ (const day& __lhs, const days& __rhs) noexcept
   1653 { return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
   1654 
   1655 inline constexpr
   1656 day operator+ (const days& __lhs, const day& __rhs) noexcept
   1657 { return __rhs + __lhs; }
   1658 
   1659 inline constexpr
   1660 day operator- (const day& __lhs, const days& __rhs) noexcept
   1661 { return __lhs + -__rhs; }
   1662 
   1663 inline constexpr
   1664 days operator-(const day& __lhs, const day& __rhs) noexcept
   1665 { return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
   1666               static_cast<int>(static_cast<unsigned>(__rhs))); }
   1667 
   1668 inline constexpr day& day::operator+=(const days& __dd) noexcept
   1669 { *this = *this + __dd; return *this; }
   1670 
   1671 inline constexpr day& day::operator-=(const days& __dd) noexcept
   1672 { *this = *this - __dd; return *this; }
   1673 
   1674 
   1675 class _LIBCPP_TYPE_VIS month {
   1676 private:
   1677     unsigned char __m;
   1678 public:
   1679     month() = default;
   1680     explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {}
   1681     inline constexpr month& operator++()    noexcept { ++__m; return *this; }
   1682     inline constexpr month  operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
   1683     inline constexpr month& operator--()    noexcept { --__m; return *this; }
   1684     inline constexpr month  operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }
   1685            constexpr month& operator+=(const months& __m1) noexcept;
   1686            constexpr month& operator-=(const months& __m1) noexcept;
   1687     explicit inline constexpr operator unsigned() const noexcept { return __m; }
   1688     inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; }
   1689 };
   1690 
   1691 
   1692 inline constexpr
   1693 bool operator==(const month& __lhs, const month& __rhs) noexcept
   1694 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
   1695 
   1696 inline constexpr
   1697 bool operator!=(const month& __lhs, const month& __rhs) noexcept
   1698 { return !(__lhs == __rhs); }
   1699 
   1700 inline constexpr
   1701 bool operator< (const month& __lhs, const month& __rhs) noexcept
   1702 { return static_cast<unsigned>(__lhs)  < static_cast<unsigned>(__rhs); }
   1703 
   1704 inline constexpr
   1705 bool operator> (const month& __lhs, const month& __rhs) noexcept
   1706 { return __rhs < __lhs; }
   1707 
   1708 inline constexpr
   1709 bool operator<=(const month& __lhs, const month& __rhs) noexcept
   1710 { return !(__rhs < __lhs); }
   1711 
   1712 inline constexpr
   1713 bool operator>=(const month& __lhs, const month& __rhs) noexcept
   1714 { return !(__lhs < __rhs); }
   1715 
   1716 inline constexpr
   1717 month operator+ (const month& __lhs, const months& __rhs) noexcept
   1718 {
   1719     auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
   1720     auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
   1721     return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
   1722 }
   1723 
   1724 inline constexpr
   1725 month operator+ (const months& __lhs, const month& __rhs) noexcept
   1726 { return __rhs + __lhs; }
   1727 
   1728 inline constexpr
   1729 month operator- (const month& __lhs, const months& __rhs) noexcept
   1730 { return __lhs + -__rhs; }
   1731 
   1732 inline constexpr
   1733 months operator-(const month& __lhs, const month& __rhs) noexcept
   1734 {
   1735     auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
   1736     return months(__dm <= 11 ? __dm : __dm + 12);
   1737 }
   1738 
   1739 inline constexpr month& month::operator+=(const months& __dm) noexcept
   1740 { *this = *this + __dm; return *this; }
   1741 
   1742 inline constexpr month& month::operator-=(const months& __dm) noexcept
   1743 { *this = *this - __dm; return *this; }
   1744 
   1745 
   1746 class _LIBCPP_TYPE_VIS year {
   1747 private:
   1748     short __y;
   1749 public:
   1750     year() = default;
   1751     explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {}
   1752 
   1753     inline constexpr year& operator++()    noexcept { ++__y; return *this; };
   1754     inline constexpr year  operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; };
   1755     inline constexpr year& operator--()    noexcept { --__y; return *this; };
   1756     inline constexpr year  operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; };
   1757            constexpr year& operator+=(const years& __dy) noexcept;
   1758            constexpr year& operator-=(const years& __dy) noexcept;
   1759     inline constexpr year operator+() const noexcept { return *this; }
   1760     inline constexpr year operator-() const noexcept { return year{-__y}; };
   1761 
   1762     inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); }
   1763     explicit inline constexpr operator int() const noexcept { return __y; }
   1764            constexpr bool ok() const noexcept;
   1765     static inline constexpr year min() noexcept { return year{-32767}; }
   1766     static inline constexpr year max() noexcept { return year{ 32767}; }
   1767 };
   1768 
   1769 
   1770 inline constexpr
   1771 bool operator==(const year& __lhs, const year& __rhs) noexcept
   1772 { return static_cast<int>(__lhs) == static_cast<int>(__rhs); }
   1773 
   1774 inline constexpr
   1775 bool operator!=(const year& __lhs, const year& __rhs) noexcept
   1776 { return !(__lhs == __rhs); }
   1777 
   1778 inline constexpr
   1779 bool operator< (const year& __lhs, const year& __rhs) noexcept
   1780 { return static_cast<int>(__lhs)  < static_cast<int>(__rhs); }
   1781 
   1782 inline constexpr
   1783 bool operator> (const year& __lhs, const year& __rhs) noexcept
   1784 { return __rhs < __lhs; }
   1785 
   1786 inline constexpr
   1787 bool operator<=(const year& __lhs, const year& __rhs) noexcept
   1788 { return !(__rhs < __lhs); }
   1789 
   1790 inline constexpr
   1791 bool operator>=(const year& __lhs, const year& __rhs) noexcept
   1792 { return !(__lhs < __rhs); }
   1793 
   1794 inline constexpr
   1795 year operator+ (const year& __lhs, const years& __rhs) noexcept
   1796 { return year(static_cast<int>(__lhs) + __rhs.count()); }
   1797 
   1798 inline constexpr
   1799 year operator+ (const years& __lhs, const year& __rhs) noexcept
   1800 { return __rhs + __lhs; }
   1801 
   1802 inline constexpr
   1803 year operator- (const year& __lhs, const years& __rhs) noexcept
   1804 { return __lhs + -__rhs; }
   1805 
   1806 inline constexpr
   1807 years operator-(const year& __lhs, const year& __rhs) noexcept
   1808 { return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }
   1809 
   1810 
   1811 inline constexpr year& year::operator+=(const years& __dy) noexcept
   1812 { *this = *this + __dy; return *this; }
   1813 
   1814 inline constexpr year& year::operator-=(const years& __dy) noexcept
   1815 { *this = *this - __dy; return *this; }
   1816 
   1817 inline constexpr bool year::ok() const noexcept
   1818 { return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); }
   1819 
   1820 class _LIBCPP_TYPE_VIS weekday_indexed;
   1821 class _LIBCPP_TYPE_VIS weekday_last;
   1822 
   1823 class _LIBCPP_TYPE_VIS weekday {
   1824 private:
   1825     unsigned char __wd;
   1826 public:
   1827   weekday() = default;
   1828   inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val)) {}
   1829   inline constexpr          weekday(const sys_days& __sysd) noexcept
   1830           : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {}
   1831   inline explicit constexpr weekday(const local_days& __locd) noexcept
   1832           : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {}
   1833 
   1834   inline constexpr weekday& operator++()    noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; }
   1835   inline constexpr weekday  operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; }
   1836   inline constexpr weekday& operator--()    noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; }
   1837   inline constexpr weekday  operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
   1838          constexpr weekday& operator+=(const days& __dd) noexcept;
   1839          constexpr weekday& operator-=(const days& __dd) noexcept;
   1840   inline explicit constexpr operator unsigned() const noexcept { return __wd; }
   1841   inline constexpr bool ok() const noexcept { return __wd <= 6; }
   1842          constexpr weekday_indexed operator[](unsigned __index) const noexcept;
   1843          constexpr weekday_last    operator[](last_spec) const noexcept;
   1844 
   1845   static constexpr unsigned char __weekday_from_days(int __days) noexcept;
   1846 };
   1847 
   1848 
   1849 // https://howardhinnant.github.io/date_algorithms.html#weekday_from_days
   1850 inline constexpr
   1851 unsigned char weekday::__weekday_from_days(int __days) noexcept
   1852 {
   1853     return static_cast<unsigned char>(
   1854               static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6)
   1855            );
   1856 }
   1857 
   1858 inline constexpr
   1859 bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
   1860 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
   1861 
   1862 inline constexpr
   1863 bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
   1864 { return !(__lhs == __rhs); }
   1865 
   1866 inline constexpr
   1867 bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
   1868 { return static_cast<unsigned>(__lhs) <  static_cast<unsigned>(__rhs); }
   1869 
   1870 inline constexpr
   1871 bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
   1872 { return __rhs < __lhs; }
   1873 
   1874 inline constexpr
   1875 bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept
   1876 { return !(__rhs < __lhs);}
   1877 
   1878 inline constexpr
   1879 bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
   1880 { return !(__lhs < __rhs); }
   1881 
   1882 constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
   1883 {
   1884     auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + __rhs.count();
   1885     auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
   1886     return weekday{static_cast<unsigned>(__mu - __yr * 7)};
   1887 }
   1888 
   1889 constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
   1890 { return __rhs + __lhs; }
   1891 
   1892 constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
   1893 { return __lhs + -__rhs; }
   1894 
   1895 constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
   1896 {
   1897     const int __wdu = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
   1898     const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
   1899     return days{__wdu - __wk * 7};
   1900 }
   1901 
   1902 inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept
   1903 { *this = *this + __dd; return *this; }
   1904 
   1905 inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept
   1906 { *this = *this - __dd; return *this; }
   1907 
   1908 
   1909 class _LIBCPP_TYPE_VIS weekday_indexed {
   1910 private:
   1911     _VSTD::chrono::weekday __wd;
   1912     unsigned char          __idx;
   1913 public:
   1914     weekday_indexed() = default;
   1915     inline constexpr weekday_indexed(const _VSTD::chrono::weekday& __wdval, unsigned __idxval) noexcept
   1916         : __wd{__wdval}, __idx(__idxval) {}
   1917     inline constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; }
   1918     inline constexpr unsigned                 index() const noexcept { return __idx; }
   1919     inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; }
   1920 };
   1921 
   1922 inline constexpr
   1923 bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
   1924 { return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); }
   1925 
   1926 inline constexpr
   1927 bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
   1928 { return !(__lhs == __rhs); }
   1929 
   1930 
   1931 class _LIBCPP_TYPE_VIS weekday_last {
   1932 private:
   1933     _VSTD::chrono::weekday __wd;
   1934 public:
   1935     explicit constexpr weekday_last(const _VSTD::chrono::weekday& __val) noexcept
   1936         : __wd{__val} {}
   1937     constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; }
   1938     constexpr bool ok() const noexcept { return __wd.ok(); }
   1939 };
   1940 
   1941 inline constexpr
   1942 bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
   1943 { return __lhs.weekday() == __rhs.weekday(); }
   1944 
   1945 inline constexpr
   1946 bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
   1947 { return !(__lhs == __rhs); }
   1948 
   1949 inline constexpr
   1950 weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; }
   1951 
   1952 inline constexpr 
   1953 weekday_last    weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; }
   1954 
   1955 
   1956 inline constexpr last_spec last{};
   1957 inline constexpr weekday   Sunday{0};
   1958 inline constexpr weekday   Monday{1};
   1959 inline constexpr weekday   Tuesday{2};
   1960 inline constexpr weekday   Wednesday{3};
   1961 inline constexpr weekday   Thursday{4};
   1962 inline constexpr weekday   Friday{5};
   1963 inline constexpr weekday   Saturday{6};
   1964 
   1965 inline constexpr month January{1};
   1966 inline constexpr month February{2};
   1967 inline constexpr month March{3};
   1968 inline constexpr month April{4};
   1969 inline constexpr month May{5};
   1970 inline constexpr month June{6};
   1971 inline constexpr month July{7};
   1972 inline constexpr month August{8};
   1973 inline constexpr month September{9};
   1974 inline constexpr month October{10};
   1975 inline constexpr month November{11};
   1976 inline constexpr month December{12};
   1977 
   1978 
   1979 class _LIBCPP_TYPE_VIS month_day {
   1980 private:
   1981    chrono::month __m;
   1982    chrono::day   __d;
   1983 public:
   1984     month_day() = default;
   1985     constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
   1986         : __m{__mval}, __d{__dval} {}
   1987     inline constexpr chrono::month month() const noexcept { return __m; }
   1988     inline constexpr chrono::day   day()   const noexcept { return __d; }
   1989     constexpr bool ok() const noexcept;
   1990 };
   1991 
   1992 inline constexpr
   1993 bool month_day::ok() const noexcept
   1994 {
   1995     if (!__m.ok()) return false;
   1996     const unsigned __dval = static_cast<unsigned>(__d);
   1997     if (__dval < 1 || __dval > 31) return false;
   1998     if (__dval <= 29) return true;
   1999 //  Now we've got either 30 or 31
   2000     const unsigned __mval = static_cast<unsigned>(__m);
   2001     if (__mval == 2) return false;
   2002     if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
   2003         return __dval == 30;
   2004     return true;
   2005 }
   2006 
   2007 inline constexpr
   2008 bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
   2009 { return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
   2010 
   2011 inline constexpr
   2012 bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept
   2013 { return !(__lhs == __rhs); }
   2014 
   2015 inline constexpr
   2016 month_day operator/(const month& __lhs, const day& __rhs) noexcept
   2017 { return month_day{__lhs, __rhs}; }
   2018 
   2019 constexpr
   2020 month_day operator/(const day& __lhs, const month& __rhs) noexcept
   2021 { return __rhs / __lhs; }
   2022 
   2023 inline constexpr
   2024 month_day operator/(const month& __lhs, int __rhs) noexcept
   2025 { return __lhs / day(__rhs); }
   2026 
   2027 constexpr
   2028 month_day operator/(int __lhs, const day& __rhs) noexcept
   2029 { return month(__lhs) / __rhs; }
   2030 
   2031 constexpr
   2032 month_day operator/(const day& __lhs, int __rhs) noexcept
   2033 { return month(__rhs) / __lhs; }
   2034 
   2035 
   2036 inline constexpr
   2037 bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept
   2038 { return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); }
   2039 
   2040 inline constexpr
   2041 bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept
   2042 { return __rhs < __lhs; }
   2043 
   2044 inline constexpr
   2045 bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept
   2046 { return !(__rhs < __lhs);}
   2047 
   2048 inline constexpr
   2049 bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept
   2050 { return !(__lhs < __rhs); }
   2051 
   2052 
   2053 
   2054 class _LIBCPP_TYPE_VIS month_day_last {
   2055 private:
   2056     chrono::month __m;
   2057 public:
   2058     explicit constexpr month_day_last(const chrono::month& __val) noexcept
   2059         : __m{__val} {}
   2060     inline constexpr chrono::month month() const noexcept { return __m; }
   2061     inline constexpr bool ok() const noexcept { return __m.ok(); }
   2062 };
   2063 
   2064 inline constexpr
   2065 bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
   2066 { return __lhs.month() == __rhs.month(); }
   2067 
   2068 inline constexpr
   2069 bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
   2070 { return !(__lhs == __rhs); }
   2071 
   2072 inline constexpr
   2073 bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
   2074 { return __lhs.month() < __rhs.month(); }
   2075 
   2076 inline constexpr
   2077 bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
   2078 { return __rhs < __lhs; }
   2079 
   2080 inline constexpr
   2081 bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
   2082 { return !(__rhs < __lhs);}
   2083 
   2084 inline constexpr
   2085 bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
   2086 { return !(__lhs < __rhs); }
   2087 
   2088 inline constexpr
   2089 month_day_last operator/(const month& __lhs, last_spec) noexcept
   2090 { return month_day_last{__lhs}; }
   2091 
   2092 inline constexpr
   2093 month_day_last operator/(last_spec, const month& __rhs) noexcept
   2094 { return month_day_last{__rhs}; }
   2095 
   2096 inline constexpr
   2097 month_day_last operator/(int __lhs, last_spec) noexcept
   2098 { return month_day_last{month(__lhs)}; }
   2099 
   2100 inline constexpr
   2101 month_day_last operator/(last_spec, int __rhs) noexcept
   2102 { return month_day_last{month(__rhs)}; }
   2103 
   2104 
   2105 class _LIBCPP_TYPE_VIS month_weekday {
   2106 private:
   2107     chrono::month __m;
   2108     chrono::weekday_indexed __wdi;
   2109 public:
   2110     month_weekday() = default;
   2111     constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
   2112         : __m{__mval}, __wdi{__wdival} {}
   2113     inline constexpr chrono::month                     month() const noexcept { return __m; }
   2114     inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
   2115     inline constexpr bool                                 ok() const noexcept { return __m.ok() && __wdi.ok(); }
   2116 };
   2117 
   2118 inline constexpr
   2119 bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
   2120 { return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
   2121 
   2122 inline constexpr
   2123 bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
   2124 { return !(__lhs == __rhs); }
   2125 
   2126 inline constexpr
   2127 month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
   2128 { return month_weekday{__lhs, __rhs}; }
   2129 
   2130 inline constexpr
   2131 month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
   2132 { return month_weekday{month(__lhs), __rhs}; }
   2133 
   2134 inline constexpr
   2135 month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
   2136 { return month_weekday{__rhs, __lhs}; }
   2137 
   2138 inline constexpr
   2139 month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
   2140 { return month_weekday{month(__rhs), __lhs}; }
   2141 
   2142 
   2143 class _LIBCPP_TYPE_VIS month_weekday_last {
   2144     chrono::month        __m;
   2145     chrono::weekday_last __wdl;
   2146   public:
   2147     constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
   2148         : __m{__mval}, __wdl{__wdlval} {}
   2149     inline constexpr chrono::month               month() const noexcept { return __m; }
   2150     inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
   2151     inline constexpr bool                           ok() const noexcept { return __m.ok() && __wdl.ok(); }
   2152 };
   2153 
   2154 inline constexpr
   2155 bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
   2156 { return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
   2157 
   2158 inline constexpr
   2159 bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
   2160 { return !(__lhs == __rhs); }
   2161 
   2162 
   2163 inline constexpr
   2164 month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
   2165 { return month_weekday_last{__lhs, __rhs}; }
   2166 
   2167 inline constexpr
   2168 month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
   2169 { return month_weekday_last{month(__lhs), __rhs}; }
   2170 
   2171 inline constexpr
   2172 month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
   2173 { return month_weekday_last{__rhs, __lhs}; }
   2174 
   2175 inline constexpr
   2176 month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
   2177 { return month_weekday_last{month(__rhs), __lhs}; }
   2178 
   2179 
   2180 class _LIBCPP_TYPE_VIS year_month {
   2181     chrono::year  __y;
   2182     chrono::month __m;
   2183 public:
   2184     year_month() = default;
   2185     constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
   2186         : __y{__yval}, __m{__mval} {}
   2187     inline constexpr chrono::year  year()  const noexcept { return __y; }
   2188     inline constexpr chrono::month month() const noexcept { return __m; }
   2189     inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; }
   2190     inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; }
   2191     inline constexpr year_month& operator+=(const years& __dy)  noexcept { this->__y += __dy; return *this; }
   2192     inline constexpr year_month& operator-=(const years& __dy)  noexcept { this->__y -= __dy; return *this; }
   2193     inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); }
   2194 };
   2195 
   2196 inline constexpr
   2197 year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; }
   2198 
   2199 inline constexpr
   2200 year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; }
   2201 
   2202 inline constexpr
   2203 bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
   2204 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
   2205 
   2206 inline constexpr
   2207 bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept
   2208 { return !(__lhs == __rhs); }
   2209 
   2210 inline constexpr
   2211 bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept
   2212 { return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); }
   2213 
   2214 inline constexpr
   2215 bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept
   2216 { return __rhs < __lhs; }
   2217 
   2218 inline constexpr
   2219 bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept
   2220 { return !(__rhs < __lhs);}
   2221 
   2222 inline constexpr
   2223 bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept
   2224 { return !(__lhs < __rhs); }
   2225 
   2226 constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
   2227 {
   2228     int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
   2229     const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
   2230     __dmi = __dmi - __dy * 12 + 1;
   2231     return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
   2232 }
   2233 
   2234 constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
   2235 { return __rhs + __lhs; }
   2236 
   2237 constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
   2238 { return (__lhs.year() + __rhs) / __lhs.month(); }
   2239 
   2240 constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
   2241 { return __rhs + __lhs; }
   2242 
   2243 constexpr months     operator-(const year_month& __lhs, const year_month& __rhs) noexcept
   2244 { return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
   2245 
   2246 constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
   2247 { return __lhs + -__rhs; }
   2248 
   2249 constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
   2250 { return __lhs + -__rhs; }
   2251 
   2252 class year_month_day_last;
   2253 
   2254 class _LIBCPP_TYPE_VIS year_month_day {
   2255 private:
   2256     chrono::year  __y;
   2257     chrono::month __m;
   2258     chrono::day   __d;
   2259 public:
   2260      year_month_day() = default;
   2261      inline constexpr year_month_day(
   2262             const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
   2263             : __y{__yval}, __m{__mval}, __d{__dval} {}  
   2264             constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
   2265      inline constexpr year_month_day(const sys_days& __sysd) noexcept
   2266             : year_month_day(__from_days(__sysd.time_since_epoch())) {}
   2267      inline explicit constexpr year_month_day(const local_days& __locd) noexcept
   2268             : year_month_day(__from_days(__locd.time_since_epoch())) {}
   2269 
   2270             constexpr year_month_day& operator+=(const months& __dm) noexcept;
   2271             constexpr year_month_day& operator-=(const months& __dm) noexcept;
   2272             constexpr year_month_day& operator+=(const years& __dy)  noexcept;
   2273             constexpr year_month_day& operator-=(const years& __dy)  noexcept;
   2274 
   2275      inline constexpr chrono::year   year() const noexcept { return __y; }
   2276      inline constexpr chrono::month month() const noexcept { return __m; }
   2277      inline constexpr chrono::day     day() const noexcept { return __d; }
   2278      inline constexpr operator   sys_days() const noexcept          { return   sys_days{__to_days()}; }
   2279      inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
   2280 
   2281             constexpr bool             ok() const noexcept;
   2282 
   2283      static constexpr year_month_day __from_days(days __d) noexcept;
   2284      constexpr days __to_days() const noexcept;
   2285 };
   2286 
   2287 
   2288 // https://howardhinnant.github.io/date_algorithms.html#civil_from_days
   2289 inline constexpr
   2290 year_month_day
   2291 year_month_day::__from_days(days __d) noexcept
   2292 {
   2293     static_assert(std::numeric_limits<unsigned>::digits >= 18, "");
   2294     static_assert(std::numeric_limits<int>::digits >= 20     , "");
   2295     const int      __z = __d.count() + 719468;
   2296     const int      __era = (__z >= 0 ? __z : __z - 146096) / 146097;
   2297     const unsigned __doe = static_cast<unsigned>(__z - __era * 146097);              // [0, 146096]
   2298     const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365;  // [0, 399]
   2299     const int      __yr = static_cast<int>(__yoe) + __era * 400;
   2300     const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100);              // [0, 365]
   2301     const unsigned __mp = (5 * __doy + 2)/153;                                       // [0, 11]
   2302     const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1;                            // [1, 31]
   2303     const unsigned __mth = __mp + (__mp < 10 ? 3 : -9);                              // [1, 12]
   2304     return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
   2305 }
   2306 
   2307 // https://howardhinnant.github.io/date_algorithms.html#days_from_civil
   2308 inline constexpr days year_month_day::__to_days() const noexcept
   2309 {
   2310     static_assert(std::numeric_limits<unsigned>::digits >= 18, "");
   2311     static_assert(std::numeric_limits<int>::digits >= 20     , "");
   2312 
   2313     const int      __yr  = static_cast<int>(__y) - (__m <= February);
   2314     const unsigned __mth = static_cast<unsigned>(__m);
   2315     const unsigned __dy  = static_cast<unsigned>(__d);
   2316 
   2317     const int      __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
   2318     const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400);                // [0, 399]
   2319     const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1;  // [0, 365]
   2320     const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy;                // [0, 146096]
   2321     return days{__era * 146097 + static_cast<int>(__doe) - 719468};
   2322 }
   2323 
   2324 inline constexpr
   2325 bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
   2326 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
   2327 
   2328 inline constexpr
   2329 bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
   2330 { return !(__lhs == __rhs); }
   2331 
   2332 inline constexpr
   2333 bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
   2334 {
   2335     if (__lhs.year() < __rhs.year()) return true;
   2336     if (__lhs.year() > __rhs.year()) return false;
   2337     if (__lhs.month() < __rhs.month()) return true;
   2338     if (__lhs.month() > __rhs.month()) return false;
   2339     return __lhs.day() < __rhs.day();
   2340 }
   2341 
   2342 inline constexpr
   2343 bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
   2344 { return __rhs < __lhs; }
   2345 
   2346 inline constexpr
   2347 bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
   2348 { return !(__rhs < __lhs);}
   2349 
   2350 inline constexpr
   2351 bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
   2352 { return !(__lhs < __rhs); }
   2353 
   2354 inline constexpr
   2355 year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
   2356 { return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
   2357 
   2358 inline constexpr
   2359 year_month_day operator/(const year_month& __lhs, int __rhs) noexcept
   2360 { return __lhs / day(__rhs); }
   2361 
   2362 inline constexpr
   2363 year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept
   2364 { return __lhs / __rhs.month() / __rhs.day(); }
   2365 
   2366 inline constexpr
   2367 year_month_day operator/(int __lhs, const month_day& __rhs) noexcept
   2368 { return year(__lhs) / __rhs; }
   2369 
   2370 inline constexpr
   2371 year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept
   2372 { return __rhs / __lhs; }
   2373 
   2374 inline constexpr
   2375 year_month_day operator/(const month_day& __lhs, int __rhs) noexcept
   2376 { return year(__rhs) / __lhs; }
   2377 
   2378 
   2379 inline constexpr
   2380 year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept
   2381 { return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); }
   2382 
   2383 inline constexpr
   2384 year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept
   2385 { return __rhs + __lhs; }
   2386 
   2387 inline constexpr
   2388 year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept
   2389 { return __lhs + -__rhs; }
   2390 
   2391 inline constexpr
   2392 year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept
   2393 { return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); }
   2394 
   2395 inline constexpr
   2396 year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept
   2397 { return __rhs + __lhs; }
   2398 
   2399 inline constexpr
   2400 year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept
   2401 { return __lhs + -__rhs; }
   2402 
   2403 inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
   2404 inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
   2405 inline constexpr year_month_day& year_month_day::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
   2406 inline constexpr year_month_day& year_month_day::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
   2407 
   2408 class _LIBCPP_TYPE_VIS year_month_day_last {
   2409 private:
   2410     chrono::year           __y;
   2411     chrono::month_day_last __mdl;
   2412 public:
   2413      constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
   2414         : __y{__yval}, __mdl{__mdlval} {}
   2415 
   2416      constexpr year_month_day_last& operator+=(const months& __m) noexcept;
   2417      constexpr year_month_day_last& operator-=(const months& __m) noexcept;
   2418      constexpr year_month_day_last& operator+=(const years& __y)  noexcept;
   2419      constexpr year_month_day_last& operator-=(const years& __y)  noexcept;
   2420 
   2421      inline constexpr chrono::year                     year() const noexcept { return __y; }
   2422      inline constexpr chrono::month                   month() const noexcept { return __mdl.month(); }
   2423      inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; }
   2424             constexpr chrono::day                       day() const noexcept;
   2425      inline constexpr operator                     sys_days() const noexcept { return   sys_days{year()/month()/day()}; }
   2426      inline explicit constexpr operator          local_days() const noexcept { return local_days{year()/month()/day()}; }
   2427      inline constexpr bool                               ok() const noexcept { return __y.ok() && __mdl.ok(); }
   2428 };
   2429 
   2430 inline constexpr
   2431 chrono::day year_month_day_last::day() const noexcept
   2432 {
   2433     constexpr chrono::day __d[] =
   2434     {
   2435         chrono::day(31), chrono::day(28), chrono::day(31),
   2436         chrono::day(30), chrono::day(31), chrono::day(30),
   2437         chrono::day(31), chrono::day(31), chrono::day(30),
   2438         chrono::day(31), chrono::day(30), chrono::day(31)
   2439     };
   2440     return month() != February || !__y.is_leap() ?
   2441         __d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
   2442 }
   2443 
   2444 inline constexpr
   2445 bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
   2446 { return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); }
   2447 
   2448 inline constexpr
   2449 bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
   2450 { return !(__lhs == __rhs); }
   2451 
   2452 inline constexpr
   2453 bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
   2454 {
   2455     if (__lhs.year() < __rhs.year()) return true;
   2456     if (__lhs.year() > __rhs.year()) return false;
   2457     return __lhs.month_day_last() < __rhs.month_day_last();
   2458 }
   2459 
   2460 inline constexpr
   2461 bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
   2462 { return __rhs < __lhs; }
   2463 
   2464 inline constexpr
   2465 bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
   2466 { return !(__rhs < __lhs);}
   2467 
   2468 inline constexpr
   2469 bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
   2470 { return !(__lhs < __rhs); }
   2471 
   2472 inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept
   2473 { return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; }
   2474 
   2475 inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept
   2476 { return year_month_day_last{__lhs, __rhs}; }
   2477 
   2478 inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept
   2479 { return year_month_day_last{year{__lhs}, __rhs}; }
   2480 
   2481 inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept
   2482 { return __rhs / __lhs; }
   2483 
   2484 inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept
   2485 { return year{__rhs} / __lhs; }
   2486 
   2487 
   2488 inline constexpr
   2489 year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept
   2490 { return (__lhs.year() / __lhs.month() + __rhs) / last; }
   2491 
   2492 inline constexpr
   2493 year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept
   2494 { return __rhs + __lhs; }
   2495 
   2496 inline constexpr
   2497 year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept
   2498 { return __lhs + (-__rhs); }
   2499 
   2500 inline constexpr
   2501 year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept
   2502 { return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; }
   2503 
   2504 inline constexpr
   2505 year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept
   2506 { return __rhs + __lhs; }
   2507 
   2508 inline constexpr
   2509 year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept
   2510 { return __lhs + (-__rhs); }
   2511 
   2512 inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
   2513 inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
   2514 inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
   2515 inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
   2516 
   2517 inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
   2518     : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {}  
   2519 
   2520 inline constexpr bool year_month_day::ok() const noexcept
   2521 {
   2522     if (!__y.ok() || !__m.ok()) return false;
   2523     return chrono::day{1} <= __d && __d <= (__y / __m / last).day();
   2524 }
   2525 
   2526 class _LIBCPP_TYPE_VIS year_month_weekday {
   2527     chrono::year            __y;
   2528     chrono::month           __m;
   2529     chrono::weekday_indexed __wdi;
   2530 public:
   2531     year_month_weekday() = default;
   2532     constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval,
   2533                                const chrono::weekday_indexed& __wdival) noexcept
   2534         : __y{__yval}, __m{__mval}, __wdi{__wdival} {}
   2535     constexpr year_month_weekday(const sys_days& __sysd) noexcept
   2536             : year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
   2537     inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
   2538             : year_month_weekday(__from_days(__locd.time_since_epoch())) {}
   2539     constexpr year_month_weekday& operator+=(const months& m) noexcept;
   2540     constexpr year_month_weekday& operator-=(const months& m) noexcept;
   2541     constexpr year_month_weekday& operator+=(const years& y)  noexcept;
   2542     constexpr year_month_weekday& operator-=(const years& y)  noexcept;
   2543 
   2544     inline constexpr chrono::year                       year() const noexcept { return __y; }
   2545     inline constexpr chrono::month                     month() const noexcept { return __m; }
   2546     inline constexpr chrono::weekday                 weekday() const noexcept { return __wdi.weekday(); }
   2547     inline constexpr unsigned                          index() const noexcept { return __wdi.index(); }
   2548     inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
   2549 
   2550     inline constexpr                       operator sys_days() const noexcept { return   sys_days{__to_days()}; }
   2551     inline explicit constexpr operator            local_days() const noexcept { return local_days{__to_days()}; }
   2552     inline constexpr bool ok() const noexcept
   2553     {
   2554         if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false;
   2555     //  TODO: make sure it's a valid date
   2556         return true;
   2557     }
   2558 
   2559     static constexpr year_month_weekday __from_days(days __d) noexcept;
   2560     constexpr days __to_days() const noexcept;
   2561 };
   2562 
   2563 inline constexpr
   2564 year_month_weekday year_month_weekday::__from_days(days __d) noexcept
   2565 {
   2566     const sys_days      __sysd{__d};
   2567     const chrono::weekday __wd = chrono::weekday(__sysd);
   2568     const year_month_day __ymd = year_month_day(__sysd);
   2569     return year_month_weekday{__ymd.year(), __ymd.month(), 
   2570                               __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]};
   2571 }
   2572 
   2573 inline constexpr
   2574 days year_month_weekday::__to_days() const noexcept
   2575 {
   2576     const sys_days __sysd = sys_days(__y/__m/1);
   2577     return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7}))
   2578                 .time_since_epoch();
   2579 }
   2580 
   2581 inline constexpr
   2582 bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
   2583 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
   2584 
   2585 inline constexpr
   2586 bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
   2587 { return !(__lhs == __rhs); }
   2588 
   2589 inline constexpr
   2590 year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept
   2591 { return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; }
   2592 
   2593 inline constexpr
   2594 year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept
   2595 { return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; }
   2596 
   2597 inline constexpr
   2598 year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept
   2599 { return year(__lhs) / __rhs; }
   2600 
   2601 inline constexpr
   2602 year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept
   2603 { return __rhs / __lhs; }
   2604 
   2605 inline constexpr
   2606 year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept
   2607 { return year(__rhs) / __lhs; }
   2608 
   2609 
   2610 inline constexpr
   2611 year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept
   2612 { return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); }
   2613 
   2614 inline constexpr
   2615 year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept
   2616 { return __rhs + __lhs; }
   2617 
   2618 inline constexpr
   2619 year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept
   2620 { return __lhs + (-__rhs); }
   2621 
   2622 inline constexpr
   2623 year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept
   2624 { return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; }
   2625 
   2626 inline constexpr
   2627 year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept
   2628 { return __rhs + __lhs; }
   2629 
   2630 inline constexpr
   2631 year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept
   2632 { return __lhs + (-__rhs); }
   2633 
   2634 
   2635 inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
   2636 inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
   2637 inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
   2638 inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
   2639 
   2640 class _LIBCPP_TYPE_VIS year_month_weekday_last {
   2641 private:
   2642     chrono::year         __y;
   2643     chrono::month        __m;
   2644     chrono::weekday_last __wdl;
   2645 public:
   2646     constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval,
   2647                                       const chrono::weekday_last& __wdlval) noexcept
   2648                 : __y{__yval}, __m{__mval}, __wdl{__wdlval} {}
   2649     constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
   2650     constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
   2651     constexpr year_month_weekday_last& operator+=(const years& __dy)  noexcept;
   2652     constexpr year_month_weekday_last& operator-=(const years& __dy)  noexcept;
   2653 
   2654     inline constexpr chrono::year                 year() const noexcept { return __y; }
   2655     inline constexpr chrono::month               month() const noexcept { return __m; }
   2656     inline constexpr chrono::weekday           weekday() const noexcept { return __wdl.weekday(); }
   2657     inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
   2658     inline constexpr operator                 sys_days() const noexcept { return   sys_days{__to_days()}; }
   2659     inline explicit constexpr operator      local_days() const noexcept { return local_days{__to_days()}; }
   2660     inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); }
   2661     
   2662     constexpr days __to_days() const noexcept;
   2663     
   2664 };
   2665 
   2666 inline constexpr
   2667 days year_month_weekday_last::__to_days() const noexcept
   2668 {
   2669     const sys_days __last = sys_days{__y/__m/last};
   2670     return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch();
   2671 
   2672 }
   2673 
   2674 inline constexpr
   2675 bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
   2676 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
   2677 
   2678 inline constexpr
   2679 bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
   2680 { return !(__lhs == __rhs); }
   2681 
   2682 
   2683 inline constexpr
   2684 year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept
   2685 { return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; }
   2686 
   2687 inline constexpr
   2688 year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept
   2689 { return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; }
   2690 
   2691 inline constexpr
   2692 year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept
   2693 { return year(__lhs) / __rhs; }
   2694 
   2695 inline constexpr
   2696 year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept
   2697 { return __rhs / __lhs; }
   2698 
   2699 inline constexpr
   2700 year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept
   2701 { return year(__rhs) / __lhs; }  
   2702 
   2703 
   2704 inline constexpr
   2705 year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
   2706 { return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); }
   2707 
   2708 inline constexpr
   2709 year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept
   2710 { return __rhs + __lhs; }
   2711 
   2712 inline constexpr
   2713 year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
   2714 { return __lhs + (-__rhs); }
   2715 
   2716 inline constexpr
   2717 year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
   2718 { return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; }
   2719 
   2720 inline constexpr
   2721 year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept
   2722 { return __rhs + __lhs; }
   2723 
   2724 inline constexpr
   2725 year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
   2726 { return __lhs + (-__rhs); }
   2727 
   2728 inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
   2729 inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
   2730 inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
   2731 inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
   2732 
   2733 #endif // _LIBCPP_STD_VER > 17
   2734 } // chrono
   2735 
   2736 #if _LIBCPP_STD_VER > 11
   2737 // Suffixes for duration literals [time.duration.literals]
   2738 inline namespace literals
   2739 {
   2740   inline namespace chrono_literals
   2741   {
   2742 
   2743     constexpr chrono::hours operator""h(unsigned long long __h)
   2744     {
   2745         return chrono::hours(static_cast<chrono::hours::rep>(__h));
   2746     }
   2747 
   2748     constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h)
   2749     {
   2750         return chrono::duration<long double, ratio<3600,1>>(__h);
   2751     }
   2752 
   2753 
   2754     constexpr chrono::minutes operator""min(unsigned long long __m)
   2755     {
   2756         return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
   2757     }
   2758 
   2759     constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m)
   2760     {
   2761         return chrono::duration<long double, ratio<60,1>> (__m);
   2762     }
   2763 
   2764 
   2765     constexpr chrono::seconds operator""s(unsigned long long __s)
   2766     {
   2767         return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
   2768     }
   2769 
   2770     constexpr chrono::duration<long double> operator""s(long double __s)
   2771     {
   2772         return chrono::duration<long double> (__s);
   2773     }
   2774 
   2775 
   2776     constexpr chrono::milliseconds operator""ms(unsigned long long __ms)
   2777     {
   2778         return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
   2779     }
   2780 
   2781     constexpr chrono::duration<long double, milli> operator""ms(long double __ms)
   2782     {
   2783         return chrono::duration<long double, milli>(__ms);
   2784     }
   2785 
   2786 
   2787     constexpr chrono::microseconds operator""us(unsigned long long __us)
   2788     {
   2789         return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
   2790     }
   2791 
   2792     constexpr chrono::duration<long double, micro> operator""us(long double __us)
   2793     {
   2794         return chrono::duration<long double, micro> (__us);
   2795     }
   2796 
   2797 
   2798     constexpr chrono::nanoseconds operator""ns(unsigned long long __ns)
   2799     {
   2800         return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
   2801     }
   2802 
   2803     constexpr chrono::duration<long double, nano> operator""ns(long double __ns)
   2804     {
   2805         return chrono::duration<long double, nano> (__ns);
   2806     }
   2807 
   2808 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS)
   2809     constexpr chrono::day operator ""d(unsigned long long __d) noexcept
   2810     {
   2811         return chrono::day(static_cast<unsigned>(__d));
   2812     }
   2813  
   2814     constexpr chrono::year operator ""y(unsigned long long __y) noexcept
   2815     {
   2816         return chrono::year(static_cast<int>(__y));
   2817     }
   2818 #endif
   2819 }}
   2820 
   2821 namespace chrono { // hoist the literals into namespace std::chrono
   2822    using namespace literals::chrono_literals;
   2823 }
   2824 
   2825 #endif
   2826 
   2827 _LIBCPP_END_NAMESPACE_STD
   2828 
   2829 #ifndef _LIBCPP_CXX03_LANG
   2830 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
   2831 struct _FilesystemClock {
   2832 #if !defined(_LIBCPP_HAS_NO_INT128)
   2833   typedef __int128_t rep;
   2834   typedef nano period;
   2835 #else
   2836   typedef long long rep;
   2837   typedef nano period;
   2838 #endif
   2839 
   2840   typedef chrono::duration<rep, period> duration;
   2841   typedef chrono::time_point<_FilesystemClock> time_point;
   2842 
   2843   static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
   2844 
   2845   _LIBCPP_FUNC_VIS static time_point now() noexcept;
   2846 
   2847   _LIBCPP_INLINE_VISIBILITY
   2848   static time_t to_time_t(const time_point& __t) noexcept {
   2849       typedef chrono::duration<rep> __secs;
   2850       return time_t(
   2851           chrono::duration_cast<__secs>(__t.time_since_epoch()).count());
   2852   }
   2853 
   2854   _LIBCPP_INLINE_VISIBILITY
   2855   static time_point from_time_t(time_t __t) noexcept {
   2856       typedef chrono::duration<rep> __secs;
   2857       return time_point(__secs(__t));
   2858   }
   2859 };
   2860 _LIBCPP_END_NAMESPACE_FILESYSTEM
   2861 #endif // !_LIBCPP_CXX03_LANG
   2862 
   2863 _LIBCPP_POP_MACROS
   2864 
   2865 #endif  // _LIBCPP_CHRONO
   2866