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