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