annotate libcxx/include/chrono @ 196:ccaec67bcdbb

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