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