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