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