Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===---------------------------- chrono ----------------------------------===// |
| 3 | // |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | ee11c31 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_CHRONO |
| 12 | #define _LIBCPP_CHRONO |
| 13 | |
| 14 | /* |
| 15 | chrono synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | namespace chrono |
| 20 | { |
| 21 | |
| 22 | template <class ToDuration, class Rep, class Period> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 23 | constexpr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | ToDuration |
| 25 | duration_cast(const duration<Rep, Period>& fd); |
| 26 | |
| 27 | template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {}; |
| 28 | |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 29 | template <class Rep> inline constexpr bool treat_as_floating_point_v |
Marshall Clow | 59581f0 | 2015-11-30 05:39:30 +0000 | [diff] [blame] | 30 | = treat_as_floating_point<Rep>::value; // C++17 |
| 31 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 32 | template <class Rep> |
| 33 | struct duration_values |
| 34 | { |
| 35 | public: |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 36 | static constexpr Rep zero(); |
| 37 | static constexpr Rep max(); |
| 38 | static constexpr Rep min(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | // duration |
| 42 | |
| 43 | template <class Rep, class Period = ratio<1>> |
| 44 | class duration |
| 45 | { |
| 46 | static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration"); |
| 47 | static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio"); |
| 48 | static_assert(Period::num > 0, "duration period must be positive"); |
| 49 | public: |
| 50 | typedef Rep rep; |
Marshall Clow | 76200b2 | 2017-03-21 18:38:57 +0000 | [diff] [blame] | 51 | typedef typename _Period::type period; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 52 | |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 53 | constexpr duration() = default; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 54 | template <class Rep2> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 55 | constexpr explicit duration(const Rep2& r, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | typename enable_if |
| 57 | < |
| 58 | is_convertible<Rep2, rep>::value && |
| 59 | (treat_as_floating_point<rep>::value || |
| 60 | !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value) |
| 61 | >::type* = 0); |
| 62 | |
| 63 | // conversions |
| 64 | template <class Rep2, class Period2> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 65 | constexpr duration(const duration<Rep2, Period2>& d, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | typename enable_if |
| 67 | < |
| 68 | treat_as_floating_point<rep>::value || |
| 69 | ratio_divide<Period2, period>::type::den == 1 |
| 70 | >::type* = 0); |
| 71 | |
| 72 | // observer |
| 73 | |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 74 | constexpr rep count() const; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 75 | |
| 76 | // arithmetic |
| 77 | |
Marshall Clow | 76200b2 | 2017-03-21 18:38:57 +0000 | [diff] [blame] | 78 | constexpr common_type<duration>::type operator+() const; |
| 79 | constexpr common_type<duration>::type operator-() const; |
Marshall Clow | df247eb | 2018-08-29 23:02:15 +0000 | [diff] [blame^] | 80 | constexpr duration& operator++(); // constexpr in C++17 |
| 81 | constexpr duration operator++(int); // constexpr in C++17 |
| 82 | constexpr duration& operator--(); // constexpr in C++17 |
| 83 | constexpr duration operator--(int); // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | |
Marshall Clow | df247eb | 2018-08-29 23:02:15 +0000 | [diff] [blame^] | 85 | constexpr duration& operator+=(const duration& d); // constexpr in C++17 |
| 86 | constexpr duration& operator-=(const duration& d); // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 87 | |
Marshall Clow | df247eb | 2018-08-29 23:02:15 +0000 | [diff] [blame^] | 88 | duration& operator*=(const rep& rhs); // constexpr in C++17 |
| 89 | duration& operator/=(const rep& rhs); // constexpr in C++17 |
| 90 | duration& operator%=(const rep& rhs); // constexpr in C++17 |
| 91 | duration& operator%=(const duration& rhs); // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 92 | |
| 93 | // special values |
| 94 | |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 95 | static constexpr duration zero(); |
| 96 | static constexpr duration min(); |
| 97 | static constexpr duration max(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | typedef duration<long long, nano> nanoseconds; |
| 101 | typedef duration<long long, micro> microseconds; |
| 102 | typedef duration<long long, milli> milliseconds; |
| 103 | typedef duration<long long > seconds; |
| 104 | typedef duration< long, ratio< 60> > minutes; |
| 105 | typedef duration< long, ratio<3600> > hours; |
| 106 | |
| 107 | template <class Clock, class Duration = typename Clock::duration> |
| 108 | class time_point |
| 109 | { |
| 110 | public: |
| 111 | typedef Clock clock; |
| 112 | typedef Duration duration; |
| 113 | typedef typename duration::rep rep; |
| 114 | typedef typename duration::period period; |
| 115 | private: |
| 116 | duration d_; // exposition only |
| 117 | |
| 118 | public: |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 119 | time_point(); // has value "epoch" // constexpr in C++14 |
| 120 | explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 121 | |
| 122 | // conversions |
| 123 | template <class Duration2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 124 | time_point(const time_point<clock, Duration2>& t); // constexpr in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 125 | |
| 126 | // observer |
| 127 | |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 128 | duration time_since_epoch() const; // constexpr in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 129 | |
| 130 | // arithmetic |
| 131 | |
Marshall Clow | df247eb | 2018-08-29 23:02:15 +0000 | [diff] [blame^] | 132 | time_point& operator+=(const duration& d); // constexpr in C++17 |
| 133 | time_point& operator-=(const duration& d); // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 134 | |
| 135 | // special values |
| 136 | |
| 137 | static constexpr time_point min(); |
| 138 | static constexpr time_point max(); |
| 139 | }; |
| 140 | |
| 141 | } // chrono |
| 142 | |
| 143 | // common_type traits |
| 144 | template <class Rep1, class Period1, class Rep2, class Period2> |
| 145 | struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>; |
| 146 | |
| 147 | template <class Clock, class Duration1, class Duration2> |
| 148 | struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>; |
| 149 | |
| 150 | namespace chrono { |
| 151 | |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 152 | |
| 153 | template<class T> struct is_clock; // C++20 |
| 154 | template<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // C++20 |
| 155 | |
| 156 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 157 | // duration arithmetic |
| 158 | template <class Rep1, class Period1, class Rep2, class Period2> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 159 | constexpr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 160 | typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type |
| 161 | operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 162 | template <class Rep1, class Period1, class Rep2, class Period2> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 163 | constexpr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 164 | typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type |
| 165 | operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 166 | template <class Rep1, class Period, class Rep2> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 167 | constexpr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 168 | duration<typename common_type<Rep1, Rep2>::type, Period> |
| 169 | operator*(const duration<Rep1, Period>& d, const Rep2& s); |
| 170 | template <class Rep1, class Period, class Rep2> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 171 | constexpr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 172 | duration<typename common_type<Rep1, Rep2>::type, Period> |
| 173 | operator*(const Rep1& s, const duration<Rep2, Period>& d); |
| 174 | template <class Rep1, class Period, class Rep2> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 175 | constexpr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 176 | duration<typename common_type<Rep1, Rep2>::type, Period> |
| 177 | operator/(const duration<Rep1, Period>& d, const Rep2& s); |
| 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 | typename common_type<Rep1, Rep2>::type |
| 181 | operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 182 | |
| 183 | // duration comparisons |
| 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 | template <class Rep1, class Period1, class Rep2, class Period2> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 197 | constexpr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 198 | bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 199 | template <class Rep1, class Period1, class Rep2, class Period2> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 200 | constexpr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 201 | bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 202 | |
| 203 | // duration_cast |
| 204 | template <class ToDuration, class Rep, class Period> |
| 205 | ToDuration duration_cast(const duration<Rep, Period>& d); |
| 206 | |
Marshall Clow | f2eabaf | 2015-11-05 19:33:59 +0000 | [diff] [blame] | 207 | template <class ToDuration, class Rep, class Period> |
| 208 | constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17 |
| 209 | template <class ToDuration, class Rep, class Period> |
| 210 | constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17 |
| 211 | template <class ToDuration, class Rep, class Period> |
| 212 | constexpr ToDuration round(const duration<Rep, Period>& d); // C++17 |
| 213 | |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 214 | // duration I/O is elsewhere |
| 215 | |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 216 | // time_point arithmetic (all constexpr in C++14) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 Rep1, class Period1, class Clock, class Duration2> |
| 221 | time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> |
| 222 | operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 223 | template <class Clock, class Duration1, class Rep2, class Period2> |
| 224 | time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> |
| 225 | operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); |
| 226 | template <class Clock, class Duration1, class Duration2> |
| 227 | typename common_type<Duration1, Duration2>::type |
| 228 | operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 229 | |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 230 | // time_point comparisons (all constexpr in C++14) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | template <class Clock, class Duration1, class Duration2> |
| 238 | bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 239 | template <class Clock, class Duration1, class Duration2> |
| 240 | bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 241 | template <class Clock, class Duration1, class Duration2> |
| 242 | bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 243 | |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 244 | // time_point_cast (constexpr in C++14) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 245 | |
| 246 | template <class ToDuration, class Clock, class Duration> |
| 247 | time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t); |
| 248 | |
Marshall Clow | f2eabaf | 2015-11-05 19:33:59 +0000 | [diff] [blame] | 249 | template <class ToDuration, class Clock, class Duration> |
| 250 | constexpr time_point<Clock, ToDuration> |
| 251 | floor(const time_point<Clock, Duration>& tp); // C++17 |
| 252 | |
| 253 | template <class ToDuration, class Clock, class Duration> |
| 254 | constexpr time_point<Clock, ToDuration> |
| 255 | ceil(const time_point<Clock, Duration>& tp); // C++17 |
| 256 | |
| 257 | template <class ToDuration, class Clock, class Duration> |
| 258 | constexpr time_point<Clock, ToDuration> |
| 259 | round(const time_point<Clock, Duration>& tp); // C++17 |
| 260 | |
| 261 | template <class Rep, class Period> |
| 262 | constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17 |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 263 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 264 | // Clocks |
| 265 | |
| 266 | class system_clock |
| 267 | { |
| 268 | public: |
| 269 | typedef microseconds duration; |
| 270 | typedef duration::rep rep; |
| 271 | typedef duration::period period; |
| 272 | typedef chrono::time_point<system_clock> time_point; |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 273 | static const bool is_steady = false; // constexpr in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 274 | |
Howard Hinnant | aa54ac4 | 2011-05-28 18:34:36 +0000 | [diff] [blame] | 275 | static time_point now() noexcept; |
| 276 | static time_t to_time_t (const time_point& __t) noexcept; |
| 277 | static time_point from_time_t(time_t __t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 278 | }; |
| 279 | |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 280 | template <class Duration> |
| 281 | using sys_time = time_point<system_clock, Duration>; // C++20 |
| 282 | using sys_seconds = sys_time<seconds>; // C++20 |
| 283 | using sys_days = sys_time<days>; // C++20 |
| 284 | |
| 285 | class utc_clock; // C++20 |
| 286 | |
| 287 | template <class Duration> |
| 288 | using utc_time = time_point<utc_clock, Duration>; // C++20 |
| 289 | using utc_seconds = utc_time<seconds>; // C++20 |
| 290 | |
| 291 | class tai_clock; // C++20 |
| 292 | |
| 293 | template <class Duration> |
| 294 | using tai_time = time_point<tai_clock, Duration>; // C++20 |
| 295 | using tai_seconds = tai_time<seconds>; // C++20 |
| 296 | |
| 297 | class file_clock; // C++20 |
| 298 | |
| 299 | template<class Duration> |
| 300 | using file_time = time_point<file_clock, Duration>; // C++20 |
| 301 | |
Howard Hinnant | c8dbd22 | 2010-11-20 19:16:30 +0000 | [diff] [blame] | 302 | class steady_clock |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | { |
| 304 | public: |
| 305 | typedef nanoseconds duration; |
| 306 | typedef duration::rep rep; |
| 307 | typedef duration::period period; |
Howard Hinnant | c8dbd22 | 2010-11-20 19:16:30 +0000 | [diff] [blame] | 308 | typedef chrono::time_point<steady_clock, duration> time_point; |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 309 | static const bool is_steady = true; // constexpr in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 310 | |
Howard Hinnant | aa54ac4 | 2011-05-28 18:34:36 +0000 | [diff] [blame] | 311 | static time_point now() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 312 | }; |
| 313 | |
Howard Hinnant | c8dbd22 | 2010-11-20 19:16:30 +0000 | [diff] [blame] | 314 | typedef steady_clock high_resolution_clock; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 315 | |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 316 | // 25.7.8, local time // C++20 |
| 317 | struct local_t {}; |
| 318 | template<class Duration> |
| 319 | using local_time = time_point<local_t, Duration>; |
| 320 | using local_seconds = local_time<seconds>; |
| 321 | using local_days = local_time<days>; |
| 322 | |
| 323 | // 25.7.9, time_point conversions template<class DestClock, class SourceClock> // C++20 |
| 324 | struct clock_time_conversion; |
| 325 | |
| 326 | template<class DestClock, class SourceClock, class Duration> |
| 327 | auto clock_cast(const time_point<SourceClock, Duration>& t); |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 328 | |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 329 | // 25.8.2, class last_spec // C++20 |
| 330 | struct last_spec; |
| 331 | |
| 332 | // 25.8.3, class day // C++20 |
| 333 | |
| 334 | class day; |
| 335 | constexpr bool operator==(const day& x, const day& y) noexcept; |
| 336 | constexpr bool operator!=(const day& x, const day& y) noexcept; |
| 337 | constexpr bool operator< (const day& x, const day& y) noexcept; |
| 338 | constexpr bool operator> (const day& x, const day& y) noexcept; |
| 339 | constexpr bool operator<=(const day& x, const day& y) noexcept; |
| 340 | constexpr bool operator>=(const day& x, const day& y) noexcept; |
| 341 | constexpr day operator+(const day& x, const days& y) noexcept; |
| 342 | constexpr day operator+(const days& x, const day& y) noexcept; |
| 343 | constexpr day operator-(const day& x, const days& y) noexcept; |
| 344 | constexpr days operator-(const day& x, const day& y) noexcept; |
| 345 | |
| 346 | // 25.8.4, class month // C++20 |
| 347 | class month; |
| 348 | constexpr bool operator==(const month& x, const month& y) noexcept; |
| 349 | constexpr bool operator!=(const month& x, const month& y) noexcept; |
| 350 | constexpr bool operator< (const month& x, const month& y) noexcept; |
| 351 | constexpr bool operator> (const month& x, const month& y) noexcept; |
| 352 | constexpr bool operator<=(const month& x, const month& y) noexcept; |
| 353 | constexpr bool operator>=(const month& x, const month& y) noexcept; |
| 354 | constexpr month operator+(const month& x, const months& y) noexcept; |
| 355 | constexpr month operator+(const months& x, const month& y) noexcept; |
| 356 | constexpr month operator-(const month& x, const months& y) noexcept; |
| 357 | constexpr months operator-(const month& x, const month& y) noexcept; |
| 358 | |
| 359 | // 25.8.5, class year // C++20 |
| 360 | class year; |
| 361 | constexpr bool operator==(const year& x, const year& y) noexcept; |
| 362 | constexpr bool operator!=(const year& x, const year& y) noexcept; |
| 363 | constexpr bool operator< (const year& x, const year& y) noexcept; |
| 364 | constexpr bool operator> (const year& x, const year& y) noexcept; |
| 365 | constexpr bool operator<=(const year& x, const year& y) noexcept; |
| 366 | constexpr bool operator>=(const year& x, const year& y) noexcept; |
| 367 | constexpr year operator+(const year& x, const years& y) noexcept; |
| 368 | constexpr year operator+(const years& x, const year& y) noexcept; |
| 369 | constexpr year operator-(const year& x, const years& y) noexcept; |
| 370 | constexpr years operator-(const year& x, const year& y) noexcept; |
| 371 | |
| 372 | // 25.8.6, class weekday // C++20 |
| 373 | class weekday; |
| 374 | |
| 375 | constexpr bool operator==(const weekday& x, const weekday& y) noexcept; |
| 376 | constexpr bool operator!=(const weekday& x, const weekday& y) noexcept; |
| 377 | constexpr weekday operator+(const weekday& x, const days& y) noexcept; |
| 378 | constexpr weekday operator+(const days& x, const weekday& y) noexcept; |
| 379 | constexpr weekday operator-(const weekday& x, const days& y) noexcept; |
| 380 | constexpr days operator-(const weekday& x, const weekday& y) noexcept; |
| 381 | |
| 382 | // 25.8.7, class weekday_indexed // C++20 |
| 383 | |
| 384 | class weekday_indexed; |
| 385 | constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept; |
| 386 | constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept; |
| 387 | |
| 388 | // 25.8.8, class weekday_last // C++20 |
| 389 | class weekday_last; |
| 390 | |
| 391 | constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept; |
| 392 | constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept; |
| 393 | |
| 394 | // 25.8.9, class month_day // C++20 |
| 395 | class month_day; |
| 396 | |
| 397 | constexpr bool operator==(const month_day& x, const month_day& y) noexcept; |
| 398 | constexpr bool operator!=(const month_day& x, const month_day& y) noexcept; |
| 399 | constexpr bool operator< (const month_day& x, const month_day& y) noexcept; |
| 400 | constexpr bool operator> (const month_day& x, const month_day& y) noexcept; |
| 401 | constexpr bool operator<=(const month_day& x, const month_day& y) noexcept; |
| 402 | constexpr bool operator>=(const month_day& x, const month_day& y) noexcept; |
| 403 | |
| 404 | |
| 405 | // 25.8.10, class month_day_last // C++20 |
| 406 | class month_day_last; |
| 407 | |
| 408 | constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept; |
| 409 | constexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept; |
| 410 | constexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept; |
| 411 | constexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept; |
| 412 | constexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept; |
| 413 | constexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept; |
| 414 | |
| 415 | // 25.8.11, class month_weekday // C++20 |
| 416 | class month_weekday; |
| 417 | |
| 418 | constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept; |
| 419 | constexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept; |
| 420 | |
| 421 | // 25.8.12, class month_weekday_last // C++20 |
| 422 | class month_weekday_last; |
| 423 | |
| 424 | constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept; |
| 425 | constexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept; |
| 426 | |
| 427 | |
| 428 | // 25.8.13, class year_month // C++20 |
| 429 | class year_month; |
| 430 | |
| 431 | constexpr bool operator==(const year_month& x, const year_month& y) noexcept; |
| 432 | constexpr bool operator!=(const year_month& x, const year_month& y) noexcept; |
| 433 | constexpr bool operator< (const year_month& x, const year_month& y) noexcept; |
| 434 | constexpr bool operator> (const year_month& x, const year_month& y) noexcept; |
| 435 | constexpr bool operator<=(const year_month& x, const year_month& y) noexcept; |
| 436 | constexpr bool operator>=(const year_month& x, const year_month& y) noexcept; |
| 437 | |
| 438 | constexpr year_month operator+(const year_month& ym, const months& dm) noexcept; |
| 439 | constexpr year_month operator+(const months& dm, const year_month& ym) noexcept; |
| 440 | constexpr year_month operator-(const year_month& ym, const months& dm) noexcept; |
| 441 | constexpr months operator-(const year_month& x, const year_month& y) noexcept; |
| 442 | constexpr year_month operator+(const year_month& ym, const years& dy) noexcept; |
| 443 | constexpr year_month operator+(const years& dy, const year_month& ym) noexcept; |
| 444 | constexpr year_month operator-(const year_month& ym, const years& dy) noexcept; |
| 445 | |
| 446 | // 25.8.14, class year_month_day class // C++20 |
| 447 | year_month_day; |
| 448 | |
| 449 | constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept; |
| 450 | constexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept; |
| 451 | constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept; |
| 452 | constexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept; |
| 453 | constexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept; |
| 454 | constexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept; |
| 455 | |
| 456 | constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept; |
| 457 | constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept; |
| 458 | constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept; |
| 459 | constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept; |
| 460 | constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept; |
| 461 | constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; |
| 462 | |
| 463 | |
| 464 | // 25.8.15, class year_month_day_last // C++20 |
| 465 | class year_month_day_last; |
| 466 | |
| 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 | constexpr bool operator< (const year_month_day_last& x, |
| 472 | const year_month_day_last& y) noexcept; |
| 473 | constexpr bool operator> (const year_month_day_last& x, |
| 474 | const year_month_day_last& y) noexcept; |
| 475 | constexpr bool operator<=(const year_month_day_last& x, |
| 476 | const year_month_day_last& y) noexcept; |
| 477 | constexpr bool operator>=(const year_month_day_last& x, |
| 478 | const year_month_day_last& y) noexcept; |
| 479 | |
| 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 months& dm, const year_month_day_last& ymdl) noexcept; |
| 484 | constexpr year_month_day_last |
| 485 | operator+(const year_month_day_last& ymdl, const years& dy) noexcept; |
| 486 | constexpr year_month_day_last |
| 487 | operator+(const years& dy, const year_month_day_last& ymdl) noexcept; |
| 488 | constexpr year_month_day_last |
| 489 | operator-(const year_month_day_last& ymdl, const months& dm) noexcept; |
| 490 | constexpr year_month_day_last |
| 491 | operator-(const year_month_day_last& ymdl, const years& dy) noexcept; |
| 492 | |
| 493 | // 25.8.16, class year_month_weekday // C++20 |
| 494 | class year_month_weekday; |
| 495 | |
| 496 | constexpr bool operator==(const year_month_weekday& x, |
| 497 | const year_month_weekday& y) noexcept; |
| 498 | constexpr bool operator!=(const year_month_weekday& x, |
| 499 | const year_month_weekday& y) noexcept; |
| 500 | |
| 501 | constexpr year_month_weekday |
| 502 | operator+(const year_month_weekday& ymwd, const months& dm) noexcept; |
| 503 | constexpr year_month_weekday |
| 504 | operator+(const months& dm, const year_month_weekday& ymwd) noexcept; |
| 505 | constexpr year_month_weekday |
| 506 | operator+(const year_month_weekday& ymwd, const years& dy) noexcept; |
| 507 | constexpr year_month_weekday |
| 508 | operator+(const years& dy, const year_month_weekday& ymwd) noexcept; |
| 509 | constexpr year_month_weekday |
| 510 | operator-(const year_month_weekday& ymwd, const months& dm) noexcept; |
| 511 | constexpr year_month_weekday |
| 512 | operator-(const year_month_weekday& ymwd, const years& dy) noexcept; |
| 513 | |
| 514 | // 25.8.17, class year_month_weekday_last // C++20 |
| 515 | class year_month_weekday_last; |
| 516 | |
| 517 | constexpr bool operator==(const year_month_weekday_last& x, |
| 518 | const year_month_weekday_last& y) noexcept; |
| 519 | constexpr bool operator!=(const year_month_weekday_last& x, |
| 520 | const year_month_weekday_last& y) 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 months& dm, const year_month_weekday_last& ymwdl) noexcept; |
| 525 | constexpr year_month_weekday_last |
| 526 | operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept; |
| 527 | constexpr year_month_weekday_last |
| 528 | operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept; |
| 529 | constexpr year_month_weekday_last |
| 530 | operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept; |
| 531 | constexpr year_month_weekday_last |
| 532 | operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept; |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 533 | |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 534 | // 25.8.18, civil calendar conventional syntax operators // C++20 |
| 535 | constexpr year_month |
| 536 | operator/(const year& y, const month& m) noexcept; |
| 537 | constexpr year_month |
| 538 | operator/(const year& y, int m) noexcept; |
| 539 | constexpr month_day |
| 540 | operator/(const month& m, const day& d) noexcept; |
| 541 | constexpr month_day |
| 542 | operator/(const month& m, int d) noexcept; |
| 543 | constexpr month_day |
| 544 | operator/(int m, const day& d) noexcept; |
| 545 | constexpr month_day |
| 546 | operator/(const day& d, const month& m) noexcept; |
| 547 | constexpr month_day |
| 548 | operator/(const day& d, int m) noexcept; |
| 549 | constexpr month_day_last |
| 550 | operator/(const month& m, last_spec) noexcept; |
| 551 | constexpr month_day_last |
| 552 | operator/(int m, last_spec) noexcept; |
| 553 | constexpr month_day_last |
| 554 | operator/(last_spec, const month& m) noexcept; |
| 555 | constexpr month_day_last |
| 556 | operator/(last_spec, int m) noexcept; |
| 557 | constexpr month_weekday |
| 558 | operator/(const month& m, const weekday_indexed& wdi) noexcept; |
| 559 | constexpr month_weekday |
| 560 | operator/(int m, const weekday_indexed& wdi) noexcept; |
| 561 | constexpr month_weekday |
| 562 | operator/(const weekday_indexed& wdi, const month& m) noexcept; |
| 563 | constexpr month_weekday |
| 564 | operator/(const weekday_indexed& wdi, int m) noexcept; |
| 565 | constexpr month_weekday_last |
| 566 | operator/(const month& m, const weekday_last& wdl) noexcept; |
| 567 | constexpr month_weekday_last |
| 568 | operator/(int m, const weekday_last& wdl) noexcept; |
| 569 | constexpr month_weekday_last |
| 570 | operator/(const weekday_last& wdl, const month& m) noexcept; |
| 571 | constexpr month_weekday_last |
| 572 | operator/(const weekday_last& wdl, int m) noexcept; |
| 573 | constexpr year_month_day |
| 574 | operator/(const year_month& ym, const day& d) noexcept; |
| 575 | constexpr year_month_day |
| 576 | operator/(const year_month& ym, int d) noexcept; |
| 577 | constexpr year_month_day |
| 578 | operator/(const year& y, const month_day& md) noexcept; |
| 579 | constexpr year_month_day |
| 580 | operator/(int y, const month_day& md) noexcept; |
| 581 | constexpr year_month_day |
| 582 | operator/(const month_day& md, const year& y) noexcept; |
| 583 | constexpr year_month_day |
| 584 | operator/(const month_day& md, int y) noexcept; |
| 585 | constexpr year_month_day_last |
| 586 | operator/(const year_month& ym, last_spec) noexcept; |
| 587 | constexpr year_month_day_last |
| 588 | operator/(const year& y, const month_day_last& mdl) noexcept; |
| 589 | constexpr year_month_day_last |
| 590 | operator/(int y, const month_day_last& mdl) noexcept; |
| 591 | constexpr year_month_day_last |
| 592 | operator/(const month_day_last& mdl, const year& y) noexcept; |
| 593 | constexpr year_month_day_last |
| 594 | operator/(const month_day_last& mdl, int y) noexcept; |
| 595 | constexpr year_month_weekday |
| 596 | operator/(const year_month& ym, const weekday_indexed& wdi) noexcept; |
| 597 | constexpr year_month_weekday |
| 598 | operator/(const year& y, const month_weekday& mwd) noexcept; |
| 599 | constexpr year_month_weekday |
| 600 | operator/(int y, const month_weekday& mwd) noexcept; |
| 601 | constexpr year_month_weekday |
| 602 | operator/(const month_weekday& mwd, const year& y) noexcept; |
| 603 | constexpr year_month_weekday |
| 604 | operator/(const month_weekday& mwd, int y) noexcept; |
| 605 | constexpr year_month_weekday_last |
| 606 | operator/(const year_month& ym, const weekday_last& wdl) noexcept; |
| 607 | constexpr year_month_weekday_last |
| 608 | operator/(const year& y, const month_weekday_last& mwdl) noexcept; |
| 609 | constexpr year_month_weekday_last |
| 610 | operator/(int y, const month_weekday_last& mwdl) noexcept; |
| 611 | constexpr year_month_weekday_last |
| 612 | operator/(const month_weekday_last& mwdl, const year& y) noexcept; |
| 613 | constexpr year_month_weekday_last |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 614 | operator/(const month_weekday_last& mwdl, int y) noexcept; |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 615 | |
| 616 | // 25.9, class template time_of_day // C++20 |
| 617 | template<class Duration> class time_of_day; |
| 618 | |
| 619 | template<> class time_of_day<hours>; |
| 620 | template<> class time_of_day<minutes>; |
| 621 | template<> class time_of_day<seconds>; |
| 622 | template<class Rep, class Period> class time_of_day<duration<Rep, Period>>; |
| 623 | |
| 624 | // 25.10.2, time zone database // C++20 |
| 625 | struct tzdb; |
| 626 | class tzdb_list; |
| 627 | |
| 628 | // 25.10.2.3, time zone database access // C++20 |
| 629 | const tzdb& get_tzdb(); |
| 630 | tzdb_list& get_tzdb_list(); |
| 631 | const time_zone* locate_zone(string_view tz_name); |
| 632 | const time_zone* current_zone(); |
| 633 | |
| 634 | // 25.10.2.4, remote time zone database support // C++20 |
| 635 | const tzdb& reload_tzdb(); |
| 636 | string remote_version(); |
| 637 | |
| 638 | // 25.10.3, exception classes // C++20 |
| 639 | class nonexistent_local_time; |
| 640 | class ambiguous_local_time; |
| 641 | |
| 642 | // 25.10.4, information classes // C++20 |
| 643 | struct sys_info; |
| 644 | struct local_info; |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 645 | |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 646 | // 25.10.5, class time_zone // C++20 |
| 647 | enum class choose {earliest, latest}; |
| 648 | class time_zone; |
| 649 | bool operator==(const time_zone& x, const time_zone& y) noexcept; |
| 650 | bool operator!=(const time_zone& x, const time_zone& y) noexcept; |
| 651 | bool operator<(const time_zone& x, const time_zone& y) noexcept; |
| 652 | bool operator>(const time_zone& x, const time_zone& y) noexcept; |
| 653 | bool operator<=(const time_zone& x, const time_zone& y) noexcept; |
| 654 | bool operator>=(const time_zone& x, const time_zone& y) noexcept; |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 655 | |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 656 | // 25.10.6, class template zoned_traits // C++20 |
| 657 | template<class T> struct zoned_traits; |
| 658 | |
| 659 | // 25.10.7, class template zoned_time // C++20 |
| 660 | template<class Duration, class TimeZonePtr = const time_zone*> class zoned_time; |
| 661 | using zoned_seconds = zoned_time<seconds>; |
| 662 | |
| 663 | template<class Duration1, class Duration2, class TimeZonePtr> |
| 664 | bool operator==(const zoned_time<Duration1, TimeZonePtr>& x, |
| 665 | const zoned_time<Duration2, TimeZonePtr>& y); |
| 666 | template<class Duration1, class Duration2, class TimeZonePtr> |
| 667 | bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x, |
| 668 | const zoned_time<Duration2, TimeZonePtr>& y); |
| 669 | |
| 670 | // 25.10.8, leap second support // C++20 |
| 671 | class leap; |
| 672 | |
| 673 | bool operator==(const leap& x, const leap& y); |
| 674 | bool operator!=(const leap& x, const leap& y); |
| 675 | bool operator< (const leap& x, const leap& y); |
| 676 | bool operator> (const leap& x, const leap& y); |
| 677 | bool operator<=(const leap& x, const leap& y); |
| 678 | bool operator>=(const leap& x, const leap& y); |
| 679 | template<class Duration> |
| 680 | bool operator==(const leap& x, const sys_time<Duration>& y); |
| 681 | template<class Duration> |
| 682 | bool operator==(const sys_time<Duration>& x, const leap& y); |
| 683 | template<class Duration> |
| 684 | bool operator!=(const leap& x, const sys_time<Duration>& y); |
| 685 | template<class Duration> |
| 686 | bool operator!=(const sys_time<Duration>& x, const leap& y); |
| 687 | template<class Duration> |
| 688 | bool operator< (const leap& x, const sys_time<Duration>& y); |
| 689 | template<class Duration> |
| 690 | bool operator< (const sys_time<Duration>& x, const leap& y); |
| 691 | template<class Duration> |
| 692 | bool operator> (const leap& x, const sys_time<Duration>& y); |
| 693 | template<class Duration> |
| 694 | bool operator> (const sys_time<Duration>& x, const leap& y); |
| 695 | template<class Duration> |
| 696 | bool operator<=(const leap& x, const sys_time<Duration>& y); |
| 697 | template<class Duration> |
| 698 | bool operator<=(const sys_time<Duration>& x, const leap& y); |
| 699 | template<class Duration> |
| 700 | bool operator>=(const leap& x, const sys_time<Duration>& y); |
| 701 | template<class Duration> |
| 702 | bool operator>=(const sys_time<Duration>& x, const leap& y); |
| 703 | |
| 704 | // 25.10.9, class link // C++20 |
| 705 | class link; |
| 706 | bool operator==(const link& x, const link& y); |
| 707 | bool operator!=(const link& x, const link& y); |
| 708 | bool operator< (const link& x, const link& y); |
| 709 | bool operator> (const link& x, const link& y); |
| 710 | bool operator<=(const link& x, const link& y); |
| 711 | bool operator>=(const link& x, const link& y); |
| 712 | |
| 713 | // 25.11, formatting // C++20 |
| 714 | template<class charT, class Streamable> |
| 715 | basic_string<charT> |
| 716 | format(const charT* fmt, const Streamable& s); |
| 717 | |
| 718 | template<class charT, class Streamable> |
| 719 | basic_string<charT> |
| 720 | format(const locale& loc, const charT* fmt, const Streamable& s); |
| 721 | |
| 722 | template<class charT, class traits, class Alloc, class Streamable> |
| 723 | basic_string<charT, traits, Alloc> |
| 724 | format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s); |
| 725 | |
| 726 | template<class charT, class traits, class Alloc, class Streamable> |
| 727 | basic_string<charT, traits, Alloc> |
| 728 | format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt, |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 729 | const Streamable& s); |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 730 | |
| 731 | // 25.12, parsing // C++20 |
| 732 | template<class charT, class traits, class Alloc, class Parsable> |
| 733 | unspecified |
| 734 | parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp); |
| 735 | |
| 736 | template<class charT, class traits, class Alloc, class Parsable> |
| 737 | unspecified |
| 738 | parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, |
| 739 | basic_string<charT, traits, Alloc>& abbrev); |
| 740 | |
| 741 | template<class charT, class traits, class Alloc, class Parsable> |
| 742 | unspecified |
| 743 | parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, |
| 744 | minutes& offset); |
| 745 | |
| 746 | template<class charT, class traits, class Alloc, class Parsable> |
| 747 | unspecified |
| 748 | parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, |
| 749 | basic_string<charT, traits, Alloc>& abbrev, minutes& offset); |
| 750 | |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 751 | inline constexpr last_spec last{}; // C++20 |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 752 | inline constexpr chrono::weekday Sunday{0}; // C++20 |
| 753 | inline constexpr chrono::weekday Monday{1}; // C++20 |
| 754 | inline constexpr chrono::weekday Tuesday{2}; // C++20 |
| 755 | inline constexpr chrono::weekday Wednesday{3}; // C++20 |
| 756 | inline constexpr chrono::weekday Thursday{4}; // C++20 |
| 757 | inline constexpr chrono::weekday Friday{5}; // C++20 |
| 758 | inline constexpr chrono::weekday Saturday{6}; // C++20 |
| 759 | |
| 760 | inline constexpr chrono::month January{1}; // C++20 |
| 761 | inline constexpr chrono::month February{2}; // C++20 |
| 762 | inline constexpr chrono::month March{3}; // C++20 |
| 763 | inline constexpr chrono::month April{4}; // C++20 |
| 764 | inline constexpr chrono::month May{5}; // C++20 |
| 765 | inline constexpr chrono::month June{6}; // C++20 |
| 766 | inline constexpr chrono::month July{7}; // C++20 |
| 767 | inline constexpr chrono::month August{8}; // C++20 |
| 768 | inline constexpr chrono::month September{9}; // C++20 |
| 769 | inline constexpr chrono::month October{10}; // C++20 |
| 770 | inline constexpr chrono::month November{11}; // C++20 |
| 771 | inline constexpr chrono::month December{12}; // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 772 | } // chrono |
| 773 | |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 774 | inline namespace literals { |
| 775 | inline namespace chrono_literals { |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 776 | constexpr chrono::hours operator ""h(unsigned long long); // C++14 |
| 777 | constexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14 |
| 778 | constexpr chrono::minutes operator ""min(unsigned long long); // C++14 |
| 779 | constexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14 |
| 780 | constexpr chrono::seconds operator ""s(unsigned long long); // C++14 |
| 781 | constexpr chrono::duration<unspecified > operator ""s(long double); // C++14 |
| 782 | constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14 |
| 783 | constexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14 |
| 784 | constexpr chrono::microseconds operator ""us(unsigned long long); // C++14 |
| 785 | constexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14 |
| 786 | constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14 |
| 787 | constexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14 |
Marshall Clow | 40ca0c1 | 2018-07-18 17:37:51 +0000 | [diff] [blame] | 788 | constexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20 |
| 789 | constexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20 |
| 790 | } // chrono_literals |
| 791 | } // literals |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 792 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 793 | } // std |
| 794 | */ |
| 795 | |
| 796 | #include <__config> |
| 797 | #include <ctime> |
| 798 | #include <type_traits> |
| 799 | #include <ratio> |
| 800 | #include <limits> |
| 801 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 802 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 803 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 804 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 805 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 806 | _LIBCPP_PUSH_MACROS |
| 807 | #include <__undef_macros> |
| 808 | |
| 809 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 810 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 811 | |
| 812 | namespace chrono |
| 813 | { |
| 814 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 815 | template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 816 | |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 817 | template <class _Tp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 818 | struct __is_duration : false_type {}; |
| 819 | |
| 820 | template <class _Rep, class _Period> |
| 821 | struct __is_duration<duration<_Rep, _Period> > : true_type {}; |
| 822 | |
| 823 | template <class _Rep, class _Period> |
| 824 | struct __is_duration<const duration<_Rep, _Period> > : true_type {}; |
| 825 | |
| 826 | template <class _Rep, class _Period> |
| 827 | struct __is_duration<volatile duration<_Rep, _Period> > : true_type {}; |
| 828 | |
| 829 | template <class _Rep, class _Period> |
| 830 | struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {}; |
| 831 | |
| 832 | } // chrono |
| 833 | |
| 834 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 835 | struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>, |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 836 | chrono::duration<_Rep2, _Period2> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 837 | { |
| 838 | typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, |
| 839 | typename __ratio_gcd<_Period1, _Period2>::type> type; |
| 840 | }; |
| 841 | |
| 842 | namespace chrono { |
| 843 | |
| 844 | // duration_cast |
| 845 | |
| 846 | template <class _FromDuration, class _ToDuration, |
| 847 | class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type, |
| 848 | bool = _Period::num == 1, |
| 849 | bool = _Period::den == 1> |
| 850 | struct __duration_cast; |
| 851 | |
| 852 | template <class _FromDuration, class _ToDuration, class _Period> |
| 853 | struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> |
| 854 | { |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 855 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 856 | _ToDuration operator()(const _FromDuration& __fd) const |
| 857 | { |
| 858 | return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count())); |
| 859 | } |
| 860 | }; |
| 861 | |
| 862 | template <class _FromDuration, class _ToDuration, class _Period> |
| 863 | struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> |
| 864 | { |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 865 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 866 | _ToDuration operator()(const _FromDuration& __fd) const |
| 867 | { |
| 868 | typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; |
| 869 | return _ToDuration(static_cast<typename _ToDuration::rep>( |
| 870 | static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); |
| 871 | } |
| 872 | }; |
| 873 | |
| 874 | template <class _FromDuration, class _ToDuration, class _Period> |
| 875 | struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> |
| 876 | { |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 877 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 878 | _ToDuration operator()(const _FromDuration& __fd) const |
| 879 | { |
| 880 | typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; |
| 881 | return _ToDuration(static_cast<typename _ToDuration::rep>( |
| 882 | static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); |
| 883 | } |
| 884 | }; |
| 885 | |
| 886 | template <class _FromDuration, class _ToDuration, class _Period> |
| 887 | struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> |
| 888 | { |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 889 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 890 | _ToDuration operator()(const _FromDuration& __fd) const |
| 891 | { |
| 892 | typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; |
| 893 | return _ToDuration(static_cast<typename _ToDuration::rep>( |
| 894 | static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) |
| 895 | / static_cast<_Ct>(_Period::den))); |
| 896 | } |
| 897 | }; |
| 898 | |
| 899 | template <class _ToDuration, class _Rep, class _Period> |
| 900 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 901 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 902 | typename enable_if |
| 903 | < |
| 904 | __is_duration<_ToDuration>::value, |
| 905 | _ToDuration |
| 906 | >::type |
| 907 | duration_cast(const duration<_Rep, _Period>& __fd) |
| 908 | { |
| 909 | return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd); |
| 910 | } |
| 911 | |
Howard Hinnant | 874ad9a | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 912 | template <class _Rep> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 913 | struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 914 | |
Marshall Clow | 59581f0 | 2015-11-30 05:39:30 +0000 | [diff] [blame] | 915 | #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 916 | template <class _Rep> |
| 917 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v |
Marshall Clow | 59581f0 | 2015-11-30 05:39:30 +0000 | [diff] [blame] | 918 | = treat_as_floating_point<_Rep>::value; |
| 919 | #endif |
| 920 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 921 | template <class _Rep> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 922 | struct _LIBCPP_TEMPLATE_VIS duration_values |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 923 | { |
| 924 | public: |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 925 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);} |
| 926 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() {return numeric_limits<_Rep>::max();} |
| 927 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 928 | }; |
| 929 | |
Marshall Clow | f2eabaf | 2015-11-05 19:33:59 +0000 | [diff] [blame] | 930 | #if _LIBCPP_STD_VER > 14 |
| 931 | template <class _ToDuration, class _Rep, class _Period> |
| 932 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 933 | typename enable_if |
| 934 | < |
| 935 | __is_duration<_ToDuration>::value, |
| 936 | _ToDuration |
| 937 | >::type |
| 938 | floor(const duration<_Rep, _Period>& __d) |
| 939 | { |
| 940 | _ToDuration __t = duration_cast<_ToDuration>(__d); |
| 941 | if (__t > __d) |
| 942 | __t = __t - _ToDuration{1}; |
| 943 | return __t; |
| 944 | } |
| 945 | |
| 946 | template <class _ToDuration, class _Rep, class _Period> |
| 947 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 948 | typename enable_if |
| 949 | < |
| 950 | __is_duration<_ToDuration>::value, |
| 951 | _ToDuration |
| 952 | >::type |
| 953 | ceil(const duration<_Rep, _Period>& __d) |
| 954 | { |
| 955 | _ToDuration __t = duration_cast<_ToDuration>(__d); |
| 956 | if (__t < __d) |
| 957 | __t = __t + _ToDuration{1}; |
| 958 | return __t; |
| 959 | } |
| 960 | |
| 961 | template <class _ToDuration, class _Rep, class _Period> |
| 962 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 963 | typename enable_if |
| 964 | < |
| 965 | __is_duration<_ToDuration>::value, |
| 966 | _ToDuration |
| 967 | >::type |
| 968 | round(const duration<_Rep, _Period>& __d) |
| 969 | { |
| 970 | _ToDuration __lower = floor<_ToDuration>(__d); |
| 971 | _ToDuration __upper = __lower + _ToDuration{1}; |
| 972 | auto __lowerDiff = __d - __lower; |
| 973 | auto __upperDiff = __upper - __d; |
| 974 | if (__lowerDiff < __upperDiff) |
| 975 | return __lower; |
| 976 | if (__lowerDiff > __upperDiff) |
| 977 | return __upper; |
| 978 | return __lower.count() & 1 ? __upper : __lower; |
| 979 | } |
| 980 | #endif |
| 981 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 982 | // duration |
| 983 | |
| 984 | template <class _Rep, class _Period> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 985 | class _LIBCPP_TEMPLATE_VIS duration |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 986 | { |
| 987 | static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); |
| 988 | static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); |
| 989 | static_assert(_Period::num > 0, "duration period must be positive"); |
Howard Hinnant | 0a51e15 | 2013-08-31 16:51:56 +0000 | [diff] [blame] | 990 | |
| 991 | template <class _R1, class _R2> |
| 992 | struct __no_overflow |
| 993 | { |
| 994 | private: |
| 995 | static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; |
| 996 | static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; |
| 997 | static const intmax_t __n1 = _R1::num / __gcd_n1_n2; |
| 998 | static const intmax_t __d1 = _R1::den / __gcd_d1_d2; |
| 999 | static const intmax_t __n2 = _R2::num / __gcd_n1_n2; |
| 1000 | static const intmax_t __d2 = _R2::den / __gcd_d1_d2; |
| 1001 | static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1); |
| 1002 | |
| 1003 | template <intmax_t _Xp, intmax_t _Yp, bool __overflow> |
| 1004 | struct __mul // __overflow == false |
| 1005 | { |
| 1006 | static const intmax_t value = _Xp * _Yp; |
| 1007 | }; |
| 1008 | |
| 1009 | template <intmax_t _Xp, intmax_t _Yp> |
| 1010 | struct __mul<_Xp, _Yp, true> |
| 1011 | { |
| 1012 | static const intmax_t value = 1; |
| 1013 | }; |
| 1014 | |
| 1015 | public: |
| 1016 | static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1); |
| 1017 | typedef ratio<__mul<__n1, __d2, !value>::value, |
| 1018 | __mul<__n2, __d1, !value>::value> type; |
| 1019 | }; |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 1020 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1021 | public: |
| 1022 | typedef _Rep rep; |
Marshall Clow | 76200b2 | 2017-03-21 18:38:57 +0000 | [diff] [blame] | 1023 | typedef typename _Period::type period; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1024 | private: |
| 1025 | rep __rep_; |
| 1026 | public: |
| 1027 | |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1028 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Eric Fiselier | 07b2b55 | 2016-11-18 06:42:17 +0000 | [diff] [blame] | 1029 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1030 | duration() = default; |
Marshall Clow | 3dbcf13 | 2013-07-31 19:39:37 +0000 | [diff] [blame] | 1031 | #else |
| 1032 | duration() {} |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1033 | #endif |
| 1034 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1035 | template <class _Rep2> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1036 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1037 | explicit duration(const _Rep2& __r, |
| 1038 | typename enable_if |
| 1039 | < |
| 1040 | is_convertible<_Rep2, rep>::value && |
| 1041 | (treat_as_floating_point<rep>::value || |
| 1042 | !treat_as_floating_point<_Rep2>::value) |
| 1043 | >::type* = 0) |
| 1044 | : __rep_(__r) {} |
| 1045 | |
| 1046 | // conversions |
| 1047 | template <class _Rep2, class _Period2> |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1048 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1049 | duration(const duration<_Rep2, _Period2>& __d, |
| 1050 | typename enable_if |
| 1051 | < |
Howard Hinnant | 0a51e15 | 2013-08-31 16:51:56 +0000 | [diff] [blame] | 1052 | __no_overflow<_Period2, period>::value && ( |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1053 | treat_as_floating_point<rep>::value || |
Howard Hinnant | 0a51e15 | 2013-08-31 16:51:56 +0000 | [diff] [blame] | 1054 | (__no_overflow<_Period2, period>::type::den == 1 && |
| 1055 | !treat_as_floating_point<_Rep2>::value)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1056 | >::type* = 0) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1057 | : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1058 | |
| 1059 | // observer |
| 1060 | |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1061 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1062 | |
| 1063 | // arithmetic |
| 1064 | |
Marshall Clow | 76200b2 | 2017-03-21 18:38:57 +0000 | [diff] [blame] | 1065 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);} |
| 1066 | _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] | 1067 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;} |
| 1068 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);} |
| 1069 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;} |
| 1070 | _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] | 1071 | |
Marshall Clow | 5c87ad0 | 2017-01-04 23:03:24 +0000 | [diff] [blame] | 1072 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} |
| 1073 | _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] | 1074 | |
Marshall Clow | 5c87ad0 | 2017-01-04 23:03:24 +0000 | [diff] [blame] | 1075 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} |
| 1076 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} |
| 1077 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} |
| 1078 | _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] | 1079 | |
| 1080 | // special values |
| 1081 | |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1082 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());} |
| 1083 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values<rep>::min());} |
| 1084 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values<rep>::max());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1085 | }; |
| 1086 | |
| 1087 | typedef duration<long long, nano> nanoseconds; |
| 1088 | typedef duration<long long, micro> microseconds; |
| 1089 | typedef duration<long long, milli> milliseconds; |
| 1090 | typedef duration<long long > seconds; |
| 1091 | typedef duration< long, ratio< 60> > minutes; |
| 1092 | typedef duration< long, ratio<3600> > hours; |
| 1093 | |
| 1094 | // Duration == |
| 1095 | |
| 1096 | template <class _LhsDuration, class _RhsDuration> |
| 1097 | struct __duration_eq |
| 1098 | { |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1099 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | 12967fb | 2013-06-28 18:09:35 +0000 | [diff] [blame] | 1100 | bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1101 | { |
| 1102 | typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; |
| 1103 | return _Ct(__lhs).count() == _Ct(__rhs).count(); |
| 1104 | } |
| 1105 | }; |
| 1106 | |
| 1107 | template <class _LhsDuration> |
| 1108 | struct __duration_eq<_LhsDuration, _LhsDuration> |
| 1109 | { |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1110 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | 12967fb | 2013-06-28 18:09:35 +0000 | [diff] [blame] | 1111 | bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1112 | {return __lhs.count() == __rhs.count();} |
| 1113 | }; |
| 1114 | |
| 1115 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1116 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1117 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1118 | bool |
| 1119 | operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1120 | { |
| 1121 | return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); |
| 1122 | } |
| 1123 | |
| 1124 | // Duration != |
| 1125 | |
| 1126 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1127 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1128 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1129 | bool |
| 1130 | operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1131 | { |
| 1132 | return !(__lhs == __rhs); |
| 1133 | } |
| 1134 | |
| 1135 | // Duration < |
| 1136 | |
| 1137 | template <class _LhsDuration, class _RhsDuration> |
| 1138 | struct __duration_lt |
| 1139 | { |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1140 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | 12967fb | 2013-06-28 18:09:35 +0000 | [diff] [blame] | 1141 | bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1142 | { |
| 1143 | typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; |
| 1144 | return _Ct(__lhs).count() < _Ct(__rhs).count(); |
| 1145 | } |
| 1146 | }; |
| 1147 | |
| 1148 | template <class _LhsDuration> |
| 1149 | struct __duration_lt<_LhsDuration, _LhsDuration> |
| 1150 | { |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1151 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | 12967fb | 2013-06-28 18:09:35 +0000 | [diff] [blame] | 1152 | bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1153 | {return __lhs.count() < __rhs.count();} |
| 1154 | }; |
| 1155 | |
| 1156 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1157 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1158 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1159 | bool |
| 1160 | operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1161 | { |
| 1162 | return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); |
| 1163 | } |
| 1164 | |
| 1165 | // Duration > |
| 1166 | |
| 1167 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1168 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1169 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1170 | bool |
| 1171 | operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1172 | { |
| 1173 | return __rhs < __lhs; |
| 1174 | } |
| 1175 | |
| 1176 | // Duration <= |
| 1177 | |
| 1178 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1179 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1180 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1181 | bool |
| 1182 | operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1183 | { |
| 1184 | return !(__rhs < __lhs); |
| 1185 | } |
| 1186 | |
| 1187 | // Duration >= |
| 1188 | |
| 1189 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1190 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1191 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1192 | bool |
| 1193 | operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1194 | { |
| 1195 | return !(__lhs < __rhs); |
| 1196 | } |
| 1197 | |
| 1198 | // Duration + |
| 1199 | |
| 1200 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1201 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1202 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1203 | typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type |
| 1204 | operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1205 | { |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1206 | typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; |
| 1207 | return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | // Duration - |
| 1211 | |
| 1212 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1213 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1214 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1215 | typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type |
| 1216 | operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1217 | { |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1218 | typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; |
| 1219 | return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | // Duration * |
| 1223 | |
| 1224 | template <class _Rep1, class _Period, class _Rep2> |
| 1225 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1226 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1227 | typename enable_if |
| 1228 | < |
| 1229 | is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, |
| 1230 | duration<typename common_type<_Rep1, _Rep2>::type, _Period> |
| 1231 | >::type |
| 1232 | operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) |
| 1233 | { |
| 1234 | typedef typename common_type<_Rep1, _Rep2>::type _Cr; |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1235 | typedef duration<_Cr, _Period> _Cd; |
| 1236 | return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | template <class _Rep1, class _Period, class _Rep2> |
| 1240 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1241 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1242 | typename enable_if |
| 1243 | < |
| 1244 | is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, |
| 1245 | duration<typename common_type<_Rep1, _Rep2>::type, _Period> |
| 1246 | >::type |
| 1247 | operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) |
| 1248 | { |
| 1249 | return __d * __s; |
| 1250 | } |
| 1251 | |
| 1252 | // Duration / |
| 1253 | |
| 1254 | template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value> |
| 1255 | struct __duration_divide_result |
| 1256 | { |
| 1257 | }; |
| 1258 | |
| 1259 | template <class _Duration, class _Rep2, |
| 1260 | bool = is_convertible<_Rep2, |
| 1261 | typename common_type<typename _Duration::rep, _Rep2>::type>::value> |
| 1262 | struct __duration_divide_imp |
| 1263 | { |
| 1264 | }; |
| 1265 | |
| 1266 | template <class _Rep1, class _Period, class _Rep2> |
| 1267 | struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true> |
| 1268 | { |
| 1269 | typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type; |
| 1270 | }; |
| 1271 | |
| 1272 | template <class _Rep1, class _Period, class _Rep2> |
| 1273 | struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false> |
| 1274 | : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2> |
| 1275 | { |
| 1276 | }; |
| 1277 | |
| 1278 | template <class _Rep1, class _Period, class _Rep2> |
| 1279 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1280 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1281 | typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type |
| 1282 | operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) |
| 1283 | { |
| 1284 | typedef typename common_type<_Rep1, _Rep2>::type _Cr; |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1285 | typedef duration<_Cr, _Period> _Cd; |
| 1286 | return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1290 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1291 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1292 | typename common_type<_Rep1, _Rep2>::type |
| 1293 | operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1294 | { |
| 1295 | typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct; |
| 1296 | return _Ct(__lhs).count() / _Ct(__rhs).count(); |
| 1297 | } |
| 1298 | |
| 1299 | // Duration % |
| 1300 | |
| 1301 | template <class _Rep1, class _Period, class _Rep2> |
| 1302 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1303 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1304 | typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type |
| 1305 | operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) |
| 1306 | { |
| 1307 | typedef typename common_type<_Rep1, _Rep2>::type _Cr; |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1308 | typedef duration<_Cr, _Period> _Cd; |
| 1309 | return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1313 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1314 | _LIBCPP_CONSTEXPR |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1315 | typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type |
| 1316 | operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1317 | { |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1318 | typedef typename common_type<_Rep1, _Rep2>::type _Cr; |
| 1319 | typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; |
| 1320 | 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] | 1321 | } |
| 1322 | |
| 1323 | ////////////////////////////////////////////////////////// |
| 1324 | ///////////////////// time_point ///////////////////////// |
| 1325 | ////////////////////////////////////////////////////////// |
| 1326 | |
| 1327 | template <class _Clock, class _Duration = typename _Clock::duration> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1328 | class _LIBCPP_TEMPLATE_VIS time_point |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1329 | { |
| 1330 | static_assert(__is_duration<_Duration>::value, |
| 1331 | "Second template parameter of time_point must be a std::chrono::duration"); |
| 1332 | public: |
| 1333 | typedef _Clock clock; |
| 1334 | typedef _Duration duration; |
| 1335 | typedef typename duration::rep rep; |
| 1336 | typedef typename duration::period period; |
| 1337 | private: |
| 1338 | duration __d_; |
| 1339 | |
| 1340 | public: |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1341 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {} |
| 1342 | _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] | 1343 | |
| 1344 | // conversions |
| 1345 | template <class _Duration2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1346 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1347 | time_point(const time_point<clock, _Duration2>& t, |
| 1348 | typename enable_if |
| 1349 | < |
| 1350 | is_convertible<_Duration2, duration>::value |
| 1351 | >::type* = 0) |
| 1352 | : __d_(t.time_since_epoch()) {} |
| 1353 | |
| 1354 | // observer |
| 1355 | |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1356 | _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] | 1357 | |
| 1358 | // arithmetic |
| 1359 | |
Marshall Clow | df247eb | 2018-08-29 23:02:15 +0000 | [diff] [blame^] | 1360 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} |
| 1361 | _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] | 1362 | |
| 1363 | // special values |
| 1364 | |
Howard Hinnant | cf3143c | 2012-07-13 19:17:27 +0000 | [diff] [blame] | 1365 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());} |
| 1366 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1367 | }; |
| 1368 | |
| 1369 | } // chrono |
| 1370 | |
| 1371 | template <class _Clock, class _Duration1, class _Duration2> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1372 | struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>, |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1373 | chrono::time_point<_Clock, _Duration2> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1374 | { |
| 1375 | typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; |
| 1376 | }; |
| 1377 | |
| 1378 | namespace chrono { |
| 1379 | |
| 1380 | template <class _ToDuration, class _Clock, class _Duration> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1381 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1382 | time_point<_Clock, _ToDuration> |
| 1383 | time_point_cast(const time_point<_Clock, _Duration>& __t) |
| 1384 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1385 | return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Marshall Clow | f2eabaf | 2015-11-05 19:33:59 +0000 | [diff] [blame] | 1388 | #if _LIBCPP_STD_VER > 14 |
| 1389 | template <class _ToDuration, class _Clock, class _Duration> |
| 1390 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 1391 | typename enable_if |
| 1392 | < |
| 1393 | __is_duration<_ToDuration>::value, |
| 1394 | time_point<_Clock, _ToDuration> |
| 1395 | >::type |
| 1396 | floor(const time_point<_Clock, _Duration>& __t) |
| 1397 | { |
| 1398 | return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())}; |
| 1399 | } |
| 1400 | |
| 1401 | template <class _ToDuration, class _Clock, class _Duration> |
| 1402 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 1403 | typename enable_if |
| 1404 | < |
| 1405 | __is_duration<_ToDuration>::value, |
| 1406 | time_point<_Clock, _ToDuration> |
| 1407 | >::type |
| 1408 | ceil(const time_point<_Clock, _Duration>& __t) |
| 1409 | { |
| 1410 | return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())}; |
| 1411 | } |
| 1412 | |
| 1413 | template <class _ToDuration, class _Clock, class _Duration> |
| 1414 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 1415 | typename enable_if |
| 1416 | < |
| 1417 | __is_duration<_ToDuration>::value, |
| 1418 | time_point<_Clock, _ToDuration> |
| 1419 | >::type |
| 1420 | round(const time_point<_Clock, _Duration>& __t) |
| 1421 | { |
| 1422 | return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())}; |
| 1423 | } |
| 1424 | |
| 1425 | template <class _Rep, class _Period> |
| 1426 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 1427 | typename enable_if |
| 1428 | < |
| 1429 | numeric_limits<_Rep>::is_signed, |
| 1430 | duration<_Rep, _Period> |
| 1431 | >::type |
| 1432 | abs(duration<_Rep, _Period> __d) |
| 1433 | { |
| 1434 | return __d >= __d.zero() ? __d : -__d; |
| 1435 | } |
| 1436 | #endif |
| 1437 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1438 | // time_point == |
| 1439 | |
| 1440 | template <class _Clock, class _Duration1, class _Duration2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1441 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1442 | bool |
| 1443 | operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1444 | { |
| 1445 | return __lhs.time_since_epoch() == __rhs.time_since_epoch(); |
| 1446 | } |
| 1447 | |
| 1448 | // time_point != |
| 1449 | |
| 1450 | template <class _Clock, class _Duration1, class _Duration2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1451 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1452 | bool |
| 1453 | operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1454 | { |
| 1455 | return !(__lhs == __rhs); |
| 1456 | } |
| 1457 | |
| 1458 | // time_point < |
| 1459 | |
| 1460 | template <class _Clock, class _Duration1, class _Duration2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1461 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1462 | bool |
| 1463 | operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1464 | { |
| 1465 | return __lhs.time_since_epoch() < __rhs.time_since_epoch(); |
| 1466 | } |
| 1467 | |
| 1468 | // time_point > |
| 1469 | |
| 1470 | template <class _Clock, class _Duration1, class _Duration2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1471 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1472 | bool |
| 1473 | operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1474 | { |
| 1475 | return __rhs < __lhs; |
| 1476 | } |
| 1477 | |
| 1478 | // time_point <= |
| 1479 | |
| 1480 | template <class _Clock, class _Duration1, class _Duration2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1481 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1482 | bool |
| 1483 | operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1484 | { |
| 1485 | return !(__rhs < __lhs); |
| 1486 | } |
| 1487 | |
| 1488 | // time_point >= |
| 1489 | |
| 1490 | template <class _Clock, class _Duration1, class _Duration2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1491 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1492 | bool |
| 1493 | operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1494 | { |
| 1495 | return !(__lhs < __rhs); |
| 1496 | } |
| 1497 | |
| 1498 | // time_point operator+(time_point x, duration y); |
| 1499 | |
| 1500 | template <class _Clock, class _Duration1, class _Rep2, class _Period2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1501 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1502 | time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> |
| 1503 | operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1504 | { |
| 1505 | 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] | 1506 | return _Tr (__lhs.time_since_epoch() + __rhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | // time_point operator+(duration x, time_point y); |
| 1510 | |
| 1511 | template <class _Rep1, class _Period1, class _Clock, class _Duration2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1512 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1513 | time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type> |
| 1514 | operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1515 | { |
| 1516 | return __rhs + __lhs; |
| 1517 | } |
| 1518 | |
| 1519 | // time_point operator-(time_point x, duration y); |
| 1520 | |
| 1521 | template <class _Clock, class _Duration1, class _Rep2, class _Period2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1522 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1523 | time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> |
| 1524 | operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1525 | { |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 1526 | typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret; |
| 1527 | return _Ret(__lhs.time_since_epoch() -__rhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | // duration operator-(time_point x, time_point y); |
| 1531 | |
| 1532 | template <class _Clock, class _Duration1, class _Duration2> |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1533 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1534 | typename common_type<_Duration1, _Duration2>::type |
| 1535 | operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1536 | { |
| 1537 | return __lhs.time_since_epoch() - __rhs.time_since_epoch(); |
| 1538 | } |
| 1539 | |
| 1540 | ////////////////////////////////////////////////////////// |
| 1541 | /////////////////////// clocks /////////////////////////// |
| 1542 | ////////////////////////////////////////////////////////// |
| 1543 | |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 1544 | class _LIBCPP_TYPE_VIS system_clock |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1545 | { |
| 1546 | public: |
| 1547 | typedef microseconds duration; |
| 1548 | typedef duration::rep rep; |
| 1549 | typedef duration::period period; |
| 1550 | typedef chrono::time_point<system_clock> time_point; |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1551 | static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1552 | |
Howard Hinnant | aa54ac4 | 2011-05-28 18:34:36 +0000 | [diff] [blame] | 1553 | static time_point now() _NOEXCEPT; |
| 1554 | static time_t to_time_t (const time_point& __t) _NOEXCEPT; |
| 1555 | static time_point from_time_t(time_t __t) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1556 | }; |
| 1557 | |
Jonathan Roelofs | cce96eb | 2014-09-02 21:14:38 +0000 | [diff] [blame] | 1558 | #ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 1559 | class _LIBCPP_TYPE_VIS steady_clock |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1560 | { |
| 1561 | public: |
| 1562 | typedef nanoseconds duration; |
| 1563 | typedef duration::rep rep; |
| 1564 | typedef duration::period period; |
Howard Hinnant | c8dbd22 | 2010-11-20 19:16:30 +0000 | [diff] [blame] | 1565 | typedef chrono::time_point<steady_clock, duration> time_point; |
Marshall Clow | 5c459c9 | 2013-07-31 19:32:19 +0000 | [diff] [blame] | 1566 | static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1567 | |
Howard Hinnant | aa54ac4 | 2011-05-28 18:34:36 +0000 | [diff] [blame] | 1568 | static time_point now() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1569 | }; |
| 1570 | |
Howard Hinnant | c8dbd22 | 2010-11-20 19:16:30 +0000 | [diff] [blame] | 1571 | typedef steady_clock high_resolution_clock; |
Jonathan Roelofs | cce96eb | 2014-09-02 21:14:38 +0000 | [diff] [blame] | 1572 | #else |
| 1573 | typedef system_clock high_resolution_clock; |
| 1574 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1575 | |
| 1576 | } // chrono |
| 1577 | |
Marshall Clow | ac86837 | 2013-10-05 21:18:32 +0000 | [diff] [blame] | 1578 | #if _LIBCPP_STD_VER > 11 |
| 1579 | // Suffixes for duration literals [time.duration.literals] |
| 1580 | inline namespace literals |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 1581 | { |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1582 | inline namespace chrono_literals |
| 1583 | { |
| 1584 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1585 | constexpr chrono::hours operator""h(unsigned long long __h) |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 1586 | { |
| 1587 | return chrono::hours(static_cast<chrono::hours::rep>(__h)); |
| 1588 | } |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1589 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1590 | 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] | 1591 | { |
| 1592 | return chrono::duration<long double, ratio<3600,1>>(__h); |
| 1593 | } |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1594 | |
| 1595 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1596 | constexpr chrono::minutes operator""min(unsigned long long __m) |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 1597 | { |
| 1598 | return chrono::minutes(static_cast<chrono::minutes::rep>(__m)); |
| 1599 | } |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1600 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1601 | 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] | 1602 | { |
| 1603 | return chrono::duration<long double, ratio<60,1>> (__m); |
| 1604 | } |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1605 | |
| 1606 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1607 | constexpr chrono::seconds operator""s(unsigned long long __s) |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 1608 | { |
| 1609 | return chrono::seconds(static_cast<chrono::seconds::rep>(__s)); |
| 1610 | } |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1611 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1612 | constexpr chrono::duration<long double> operator""s(long double __s) |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 1613 | { |
| 1614 | return chrono::duration<long double> (__s); |
| 1615 | } |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1616 | |
| 1617 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1618 | constexpr chrono::milliseconds operator""ms(unsigned long long __ms) |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 1619 | { |
| 1620 | return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms)); |
| 1621 | } |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1622 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1623 | constexpr chrono::duration<long double, milli> operator""ms(long double __ms) |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 1624 | { |
| 1625 | return chrono::duration<long double, milli>(__ms); |
| 1626 | } |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1627 | |
| 1628 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1629 | constexpr chrono::microseconds operator""us(unsigned long long __us) |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 1630 | { |
| 1631 | return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us)); |
| 1632 | } |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1633 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1634 | constexpr chrono::duration<long double, micro> operator""us(long double __us) |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 1635 | { |
| 1636 | return chrono::duration<long double, micro> (__us); |
| 1637 | } |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 1638 | |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1639 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1640 | constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 1641 | { |
| 1642 | return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns)); |
| 1643 | } |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1644 | |
Marshall Clow | 2ac805a | 2017-08-09 15:42:50 +0000 | [diff] [blame] | 1645 | constexpr chrono::duration<long double, nano> operator""ns(long double __ns) |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 1646 | { |
| 1647 | return chrono::duration<long double, nano> (__ns); |
| 1648 | } |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1649 | |
| 1650 | }} |
Marshall Clow | ac86837 | 2013-10-05 21:18:32 +0000 | [diff] [blame] | 1651 | |
| 1652 | namespace chrono { // hoist the literals into namespace std::chrono |
| 1653 | using namespace literals::chrono_literals; |
| 1654 | } |
| 1655 | |
Marshall Clow | eb41e5c | 2013-07-24 21:18:14 +0000 | [diff] [blame] | 1656 | #endif |
| 1657 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1658 | _LIBCPP_END_NAMESPACE_STD |
| 1659 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 1660 | _LIBCPP_POP_MACROS |
| 1661 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1662 | #endif // _LIBCPP_CHRONO |