annotate libstdc++-v3/include/std/chrono @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // <chrono> -*- C++ -*-
kono
parents:
diff changeset
2
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
3 // Copyright (C) 2008-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
4 //
kono
parents:
diff changeset
5 // This file is part of the GNU ISO C++ Library. This library is free
kono
parents:
diff changeset
6 // software; you can redistribute it and/or modify it under the
kono
parents:
diff changeset
7 // terms of the GNU General Public License as published by the
kono
parents:
diff changeset
8 // Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 // any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 // This library is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 // GNU General Public License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 // Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 // permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 // 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 // a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 // <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 /** @file include/chrono
kono
parents:
diff changeset
26 * This is a Standard C++ Library header.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
27 * @ingroup chrono
111
kono
parents:
diff changeset
28 */
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 #ifndef _GLIBCXX_CHRONO
kono
parents:
diff changeset
31 #define _GLIBCXX_CHRONO 1
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 #pragma GCC system_header
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 #if __cplusplus < 201103L
kono
parents:
diff changeset
36 # include <bits/c++0x_warning.h>
kono
parents:
diff changeset
37 #else
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 #include <ratio>
kono
parents:
diff changeset
40 #include <type_traits>
kono
parents:
diff changeset
41 #include <limits>
kono
parents:
diff changeset
42 #include <ctime>
kono
parents:
diff changeset
43 #include <bits/parse_numbers.h> // for literals support.
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 namespace std _GLIBCXX_VISIBILITY(default)
kono
parents:
diff changeset
46 {
kono
parents:
diff changeset
47 _GLIBCXX_BEGIN_NAMESPACE_VERSION
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 /**
kono
parents:
diff changeset
50 * @defgroup chrono Time
kono
parents:
diff changeset
51 * @ingroup utilities
kono
parents:
diff changeset
52 *
kono
parents:
diff changeset
53 * Classes and functions for time.
kono
parents:
diff changeset
54 * @{
kono
parents:
diff changeset
55 */
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 /** @namespace std::chrono
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
58 * @brief ISO C++ 2011 namespace for date and time utilities
111
kono
parents:
diff changeset
59 */
kono
parents:
diff changeset
60 namespace chrono
kono
parents:
diff changeset
61 {
kono
parents:
diff changeset
62 template<typename _Rep, typename _Period = ratio<1>>
kono
parents:
diff changeset
63 struct duration;
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 template<typename _Clock, typename _Dur = typename _Clock::duration>
kono
parents:
diff changeset
66 struct time_point;
kono
parents:
diff changeset
67 }
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 // 20.11.4.3 specialization of common_type (for duration, sfinae-friendly)
kono
parents:
diff changeset
70
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
71 /// @cond undocumented
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
72
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
73 template<typename _CT, typename _Period1, typename _Period2, typename = void>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
74 struct __duration_common_type
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
75 { };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
76
111
kono
parents:
diff changeset
77 template<typename _CT, typename _Period1, typename _Period2>
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
78 struct __duration_common_type<_CT, _Period1, _Period2,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
79 __void_t<typename _CT::type>>
111
kono
parents:
diff changeset
80 {
kono
parents:
diff changeset
81 private:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
82 using __gcd_num = __static_gcd<_Period1::num, _Period2::num>;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
83 using __gcd_den = __static_gcd<_Period1::den, _Period2::den>;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
84 using __cr = typename _CT::type;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
85 using __r = ratio<__gcd_num::value,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
86 (_Period1::den / __gcd_den::value) * _Period2::den>;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
87
111
kono
parents:
diff changeset
88 public:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
89 using type = chrono::duration<__cr, __r>;
111
kono
parents:
diff changeset
90 };
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 template<typename _Period1, typename _Period2>
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
93 struct __duration_common_type<__failure_type, _Period1, _Period2>
111
kono
parents:
diff changeset
94 { typedef __failure_type type; };
kono
parents:
diff changeset
95
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
96 /// @endcond
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
97
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
98 /// Specialization of common_type for chrono::duration types.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
99 /// @relates duration
111
kono
parents:
diff changeset
100 template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2>
kono
parents:
diff changeset
101 struct common_type<chrono::duration<_Rep1, _Period1>,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
102 chrono::duration<_Rep2, _Period2>>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
103 : __duration_common_type<common_type<_Rep1, _Rep2>, _Period1, _Period2>
111
kono
parents:
diff changeset
104 { };
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 // 20.11.4.3 specialization of common_type (for time_point, sfinae-friendly)
kono
parents:
diff changeset
107
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
108 /// @cond undocumented
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
109
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
110 template<typename _CT, typename _Clock, typename = void>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
111 struct __timepoint_common_type
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
112 { };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
113
111
kono
parents:
diff changeset
114 template<typename _CT, typename _Clock>
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
115 struct __timepoint_common_type<_CT, _Clock, __void_t<typename _CT::type>>
111
kono
parents:
diff changeset
116 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
117 using type = chrono::time_point<_Clock, typename _CT::type>;
111
kono
parents:
diff changeset
118 };
kono
parents:
diff changeset
119
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
120 /// @endcond
111
kono
parents:
diff changeset
121
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
122 /// Specialization of common_type for chrono::time_point types.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
123 /// @relates time_point
111
kono
parents:
diff changeset
124 template<typename _Clock, typename _Duration1, typename _Duration2>
kono
parents:
diff changeset
125 struct common_type<chrono::time_point<_Clock, _Duration1>,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
126 chrono::time_point<_Clock, _Duration2>>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
127 : __timepoint_common_type<common_type<_Duration1, _Duration2>, _Clock>
111
kono
parents:
diff changeset
128 { };
kono
parents:
diff changeset
129
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
130 // @} group chrono
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
131
111
kono
parents:
diff changeset
132 namespace chrono
kono
parents:
diff changeset
133 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
134 /// @addtogroup chrono
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
135 /// @{
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
136
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
137 /// @cond undocumented
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
138
111
kono
parents:
diff changeset
139 // Primary template for duration_cast impl.
kono
parents:
diff changeset
140 template<typename _ToDur, typename _CF, typename _CR,
kono
parents:
diff changeset
141 bool _NumIsOne = false, bool _DenIsOne = false>
kono
parents:
diff changeset
142 struct __duration_cast_impl
kono
parents:
diff changeset
143 {
kono
parents:
diff changeset
144 template<typename _Rep, typename _Period>
kono
parents:
diff changeset
145 static constexpr _ToDur
kono
parents:
diff changeset
146 __cast(const duration<_Rep, _Period>& __d)
kono
parents:
diff changeset
147 {
kono
parents:
diff changeset
148 typedef typename _ToDur::rep __to_rep;
kono
parents:
diff changeset
149 return _ToDur(static_cast<__to_rep>(static_cast<_CR>(__d.count())
kono
parents:
diff changeset
150 * static_cast<_CR>(_CF::num)
kono
parents:
diff changeset
151 / static_cast<_CR>(_CF::den)));
kono
parents:
diff changeset
152 }
kono
parents:
diff changeset
153 };
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 template<typename _ToDur, typename _CF, typename _CR>
kono
parents:
diff changeset
156 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
kono
parents:
diff changeset
157 {
kono
parents:
diff changeset
158 template<typename _Rep, typename _Period>
kono
parents:
diff changeset
159 static constexpr _ToDur
kono
parents:
diff changeset
160 __cast(const duration<_Rep, _Period>& __d)
kono
parents:
diff changeset
161 {
kono
parents:
diff changeset
162 typedef typename _ToDur::rep __to_rep;
kono
parents:
diff changeset
163 return _ToDur(static_cast<__to_rep>(__d.count()));
kono
parents:
diff changeset
164 }
kono
parents:
diff changeset
165 };
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 template<typename _ToDur, typename _CF, typename _CR>
kono
parents:
diff changeset
168 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
kono
parents:
diff changeset
169 {
kono
parents:
diff changeset
170 template<typename _Rep, typename _Period>
kono
parents:
diff changeset
171 static constexpr _ToDur
kono
parents:
diff changeset
172 __cast(const duration<_Rep, _Period>& __d)
kono
parents:
diff changeset
173 {
kono
parents:
diff changeset
174 typedef typename _ToDur::rep __to_rep;
kono
parents:
diff changeset
175 return _ToDur(static_cast<__to_rep>(
kono
parents:
diff changeset
176 static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den)));
kono
parents:
diff changeset
177 }
kono
parents:
diff changeset
178 };
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 template<typename _ToDur, typename _CF, typename _CR>
kono
parents:
diff changeset
181 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
kono
parents:
diff changeset
182 {
kono
parents:
diff changeset
183 template<typename _Rep, typename _Period>
kono
parents:
diff changeset
184 static constexpr _ToDur
kono
parents:
diff changeset
185 __cast(const duration<_Rep, _Period>& __d)
kono
parents:
diff changeset
186 {
kono
parents:
diff changeset
187 typedef typename _ToDur::rep __to_rep;
kono
parents:
diff changeset
188 return _ToDur(static_cast<__to_rep>(
kono
parents:
diff changeset
189 static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num)));
kono
parents:
diff changeset
190 }
kono
parents:
diff changeset
191 };
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 template<typename _Tp>
kono
parents:
diff changeset
194 struct __is_duration
kono
parents:
diff changeset
195 : std::false_type
kono
parents:
diff changeset
196 { };
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 template<typename _Rep, typename _Period>
kono
parents:
diff changeset
199 struct __is_duration<duration<_Rep, _Period>>
kono
parents:
diff changeset
200 : std::true_type
kono
parents:
diff changeset
201 { };
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 template<typename _Tp>
kono
parents:
diff changeset
204 using __enable_if_is_duration
kono
parents:
diff changeset
205 = typename enable_if<__is_duration<_Tp>::value, _Tp>::type;
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 template<typename _Tp>
kono
parents:
diff changeset
208 using __disable_if_is_duration
kono
parents:
diff changeset
209 = typename enable_if<!__is_duration<_Tp>::value, _Tp>::type;
kono
parents:
diff changeset
210
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
211 /// @endcond
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
212
111
kono
parents:
diff changeset
213 /// duration_cast
kono
parents:
diff changeset
214 template<typename _ToDur, typename _Rep, typename _Period>
kono
parents:
diff changeset
215 constexpr __enable_if_is_duration<_ToDur>
kono
parents:
diff changeset
216 duration_cast(const duration<_Rep, _Period>& __d)
kono
parents:
diff changeset
217 {
kono
parents:
diff changeset
218 typedef typename _ToDur::period __to_period;
kono
parents:
diff changeset
219 typedef typename _ToDur::rep __to_rep;
kono
parents:
diff changeset
220 typedef ratio_divide<_Period, __to_period> __cf;
kono
parents:
diff changeset
221 typedef typename common_type<__to_rep, _Rep, intmax_t>::type
kono
parents:
diff changeset
222 __cr;
kono
parents:
diff changeset
223 typedef __duration_cast_impl<_ToDur, __cf, __cr,
kono
parents:
diff changeset
224 __cf::num == 1, __cf::den == 1> __dc;
kono
parents:
diff changeset
225 return __dc::__cast(__d);
kono
parents:
diff changeset
226 }
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 /// treat_as_floating_point
kono
parents:
diff changeset
229 template<typename _Rep>
kono
parents:
diff changeset
230 struct treat_as_floating_point
kono
parents:
diff changeset
231 : is_floating_point<_Rep>
kono
parents:
diff changeset
232 { };
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 #if __cplusplus > 201402L
kono
parents:
diff changeset
235 template <typename _Rep>
kono
parents:
diff changeset
236 inline constexpr bool treat_as_floating_point_v =
kono
parents:
diff changeset
237 treat_as_floating_point<_Rep>::value;
kono
parents:
diff changeset
238 #endif // C++17
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 #if __cplusplus >= 201703L
kono
parents:
diff changeset
241 # define __cpp_lib_chrono 201611
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 template<typename _ToDur, typename _Rep, typename _Period>
kono
parents:
diff changeset
244 constexpr __enable_if_is_duration<_ToDur>
kono
parents:
diff changeset
245 floor(const duration<_Rep, _Period>& __d)
kono
parents:
diff changeset
246 {
kono
parents:
diff changeset
247 auto __to = chrono::duration_cast<_ToDur>(__d);
kono
parents:
diff changeset
248 if (__to > __d)
kono
parents:
diff changeset
249 return __to - _ToDur{1};
kono
parents:
diff changeset
250 return __to;
kono
parents:
diff changeset
251 }
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 template<typename _ToDur, typename _Rep, typename _Period>
kono
parents:
diff changeset
254 constexpr __enable_if_is_duration<_ToDur>
kono
parents:
diff changeset
255 ceil(const duration<_Rep, _Period>& __d)
kono
parents:
diff changeset
256 {
kono
parents:
diff changeset
257 auto __to = chrono::duration_cast<_ToDur>(__d);
kono
parents:
diff changeset
258 if (__to < __d)
kono
parents:
diff changeset
259 return __to + _ToDur{1};
kono
parents:
diff changeset
260 return __to;
kono
parents:
diff changeset
261 }
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 template <typename _ToDur, typename _Rep, typename _Period>
kono
parents:
diff changeset
264 constexpr enable_if_t<
kono
parents:
diff changeset
265 __and_<__is_duration<_ToDur>,
kono
parents:
diff changeset
266 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
kono
parents:
diff changeset
267 _ToDur>
kono
parents:
diff changeset
268 round(const duration<_Rep, _Period>& __d)
kono
parents:
diff changeset
269 {
kono
parents:
diff changeset
270 _ToDur __t0 = chrono::floor<_ToDur>(__d);
kono
parents:
diff changeset
271 _ToDur __t1 = __t0 + _ToDur{1};
kono
parents:
diff changeset
272 auto __diff0 = __d - __t0;
kono
parents:
diff changeset
273 auto __diff1 = __t1 - __d;
kono
parents:
diff changeset
274 if (__diff0 == __diff1)
kono
parents:
diff changeset
275 {
kono
parents:
diff changeset
276 if (__t0.count() & 1)
kono
parents:
diff changeset
277 return __t1;
kono
parents:
diff changeset
278 return __t0;
kono
parents:
diff changeset
279 }
kono
parents:
diff changeset
280 else if (__diff0 < __diff1)
kono
parents:
diff changeset
281 return __t0;
kono
parents:
diff changeset
282 return __t1;
kono
parents:
diff changeset
283 }
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 template<typename _Rep, typename _Period>
kono
parents:
diff changeset
286 constexpr
kono
parents:
diff changeset
287 enable_if_t<numeric_limits<_Rep>::is_signed, duration<_Rep, _Period>>
kono
parents:
diff changeset
288 abs(duration<_Rep, _Period> __d)
kono
parents:
diff changeset
289 {
kono
parents:
diff changeset
290 if (__d >= __d.zero())
kono
parents:
diff changeset
291 return __d;
kono
parents:
diff changeset
292 return -__d;
kono
parents:
diff changeset
293 }
kono
parents:
diff changeset
294 #endif // C++17
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 /// duration_values
kono
parents:
diff changeset
297 template<typename _Rep>
kono
parents:
diff changeset
298 struct duration_values
kono
parents:
diff changeset
299 {
kono
parents:
diff changeset
300 static constexpr _Rep
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
301 zero() noexcept
111
kono
parents:
diff changeset
302 { return _Rep(0); }
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 static constexpr _Rep
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
305 max() noexcept
111
kono
parents:
diff changeset
306 { return numeric_limits<_Rep>::max(); }
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 static constexpr _Rep
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
309 min() noexcept
111
kono
parents:
diff changeset
310 { return numeric_limits<_Rep>::lowest(); }
kono
parents:
diff changeset
311 };
kono
parents:
diff changeset
312
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
313 /// @cond undocumented
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
314
111
kono
parents:
diff changeset
315 template<typename _Tp>
kono
parents:
diff changeset
316 struct __is_ratio
kono
parents:
diff changeset
317 : std::false_type
kono
parents:
diff changeset
318 { };
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 template<intmax_t _Num, intmax_t _Den>
kono
parents:
diff changeset
321 struct __is_ratio<ratio<_Num, _Den>>
kono
parents:
diff changeset
322 : std::true_type
kono
parents:
diff changeset
323 { };
kono
parents:
diff changeset
324
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
325 /// @endcond
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
326
111
kono
parents:
diff changeset
327 /// duration
kono
parents:
diff changeset
328 template<typename _Rep, typename _Period>
kono
parents:
diff changeset
329 struct duration
kono
parents:
diff changeset
330 {
kono
parents:
diff changeset
331 private:
kono
parents:
diff changeset
332 template<typename _Rep2>
kono
parents:
diff changeset
333 using __is_float = treat_as_floating_point<_Rep2>;
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 // _Period2 is an exact multiple of _Period
kono
parents:
diff changeset
336 template<typename _Period2>
kono
parents:
diff changeset
337 using __is_harmonic
kono
parents:
diff changeset
338 = __bool_constant<ratio_divide<_Period2, _Period>::den == 1>;
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 public:
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 typedef _Rep rep;
kono
parents:
diff changeset
343 typedef _Period period;
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration");
kono
parents:
diff changeset
346 static_assert(__is_ratio<_Period>::value,
kono
parents:
diff changeset
347 "period must be a specialization of ratio");
kono
parents:
diff changeset
348 static_assert(_Period::num > 0, "period must be positive");
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 // 20.11.5.1 construction / copy / destroy
kono
parents:
diff changeset
351 constexpr duration() = default;
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 duration(const duration&) = default;
kono
parents:
diff changeset
354
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
355 // _GLIBCXX_RESOLVE_LIB_DEFECTS
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
356 // 3050. Conversion specification problem in chrono::duration
111
kono
parents:
diff changeset
357 template<typename _Rep2, typename = _Require<
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
358 is_convertible<const _Rep2&, rep>,
111
kono
parents:
diff changeset
359 __or_<__is_float<rep>, __not_<__is_float<_Rep2>>>>>
kono
parents:
diff changeset
360 constexpr explicit duration(const _Rep2& __rep)
kono
parents:
diff changeset
361 : __r(static_cast<rep>(__rep)) { }
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 template<typename _Rep2, typename _Period2, typename = _Require<
kono
parents:
diff changeset
364 __or_<__is_float<rep>,
kono
parents:
diff changeset
365 __and_<__is_harmonic<_Period2>,
kono
parents:
diff changeset
366 __not_<__is_float<_Rep2>>>>>>
kono
parents:
diff changeset
367 constexpr duration(const duration<_Rep2, _Period2>& __d)
kono
parents:
diff changeset
368 : __r(duration_cast<duration>(__d).count()) { }
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 ~duration() = default;
kono
parents:
diff changeset
371 duration& operator=(const duration&) = default;
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 // 20.11.5.2 observer
kono
parents:
diff changeset
374 constexpr rep
kono
parents:
diff changeset
375 count() const
kono
parents:
diff changeset
376 { return __r; }
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 // 20.11.5.3 arithmetic
kono
parents:
diff changeset
379 constexpr duration
kono
parents:
diff changeset
380 operator+() const
kono
parents:
diff changeset
381 { return *this; }
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 constexpr duration
kono
parents:
diff changeset
384 operator-() const
kono
parents:
diff changeset
385 { return duration(-__r); }
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 _GLIBCXX17_CONSTEXPR duration&
kono
parents:
diff changeset
388 operator++()
kono
parents:
diff changeset
389 {
kono
parents:
diff changeset
390 ++__r;
kono
parents:
diff changeset
391 return *this;
kono
parents:
diff changeset
392 }
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 _GLIBCXX17_CONSTEXPR duration
kono
parents:
diff changeset
395 operator++(int)
kono
parents:
diff changeset
396 { return duration(__r++); }
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 _GLIBCXX17_CONSTEXPR duration&
kono
parents:
diff changeset
399 operator--()
kono
parents:
diff changeset
400 {
kono
parents:
diff changeset
401 --__r;
kono
parents:
diff changeset
402 return *this;
kono
parents:
diff changeset
403 }
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 _GLIBCXX17_CONSTEXPR duration
kono
parents:
diff changeset
406 operator--(int)
kono
parents:
diff changeset
407 { return duration(__r--); }
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 _GLIBCXX17_CONSTEXPR duration&
kono
parents:
diff changeset
410 operator+=(const duration& __d)
kono
parents:
diff changeset
411 {
kono
parents:
diff changeset
412 __r += __d.count();
kono
parents:
diff changeset
413 return *this;
kono
parents:
diff changeset
414 }
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 _GLIBCXX17_CONSTEXPR duration&
kono
parents:
diff changeset
417 operator-=(const duration& __d)
kono
parents:
diff changeset
418 {
kono
parents:
diff changeset
419 __r -= __d.count();
kono
parents:
diff changeset
420 return *this;
kono
parents:
diff changeset
421 }
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 _GLIBCXX17_CONSTEXPR duration&
kono
parents:
diff changeset
424 operator*=(const rep& __rhs)
kono
parents:
diff changeset
425 {
kono
parents:
diff changeset
426 __r *= __rhs;
kono
parents:
diff changeset
427 return *this;
kono
parents:
diff changeset
428 }
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 _GLIBCXX17_CONSTEXPR duration&
kono
parents:
diff changeset
431 operator/=(const rep& __rhs)
kono
parents:
diff changeset
432 {
kono
parents:
diff changeset
433 __r /= __rhs;
kono
parents:
diff changeset
434 return *this;
kono
parents:
diff changeset
435 }
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 // DR 934.
kono
parents:
diff changeset
438 template<typename _Rep2 = rep>
kono
parents:
diff changeset
439 _GLIBCXX17_CONSTEXPR
kono
parents:
diff changeset
440 typename enable_if<!treat_as_floating_point<_Rep2>::value,
kono
parents:
diff changeset
441 duration&>::type
kono
parents:
diff changeset
442 operator%=(const rep& __rhs)
kono
parents:
diff changeset
443 {
kono
parents:
diff changeset
444 __r %= __rhs;
kono
parents:
diff changeset
445 return *this;
kono
parents:
diff changeset
446 }
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 template<typename _Rep2 = rep>
kono
parents:
diff changeset
449 _GLIBCXX17_CONSTEXPR
kono
parents:
diff changeset
450 typename enable_if<!treat_as_floating_point<_Rep2>::value,
kono
parents:
diff changeset
451 duration&>::type
kono
parents:
diff changeset
452 operator%=(const duration& __d)
kono
parents:
diff changeset
453 {
kono
parents:
diff changeset
454 __r %= __d.count();
kono
parents:
diff changeset
455 return *this;
kono
parents:
diff changeset
456 }
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 // 20.11.5.4 special values
kono
parents:
diff changeset
459 static constexpr duration
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
460 zero() noexcept
111
kono
parents:
diff changeset
461 { return duration(duration_values<rep>::zero()); }
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 static constexpr duration
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
464 min() noexcept
111
kono
parents:
diff changeset
465 { return duration(duration_values<rep>::min()); }
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 static constexpr duration
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
468 max() noexcept
111
kono
parents:
diff changeset
469 { return duration(duration_values<rep>::max()); }
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 private:
kono
parents:
diff changeset
472 rep __r;
kono
parents:
diff changeset
473 };
kono
parents:
diff changeset
474
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
475 /// @relates duration @{
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
476
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
477 /// The sum of two durations.
111
kono
parents:
diff changeset
478 template<typename _Rep1, typename _Period1,
kono
parents:
diff changeset
479 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
480 constexpr typename common_type<duration<_Rep1, _Period1>,
kono
parents:
diff changeset
481 duration<_Rep2, _Period2>>::type
kono
parents:
diff changeset
482 operator+(const duration<_Rep1, _Period1>& __lhs,
kono
parents:
diff changeset
483 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
484 {
kono
parents:
diff changeset
485 typedef duration<_Rep1, _Period1> __dur1;
kono
parents:
diff changeset
486 typedef duration<_Rep2, _Period2> __dur2;
kono
parents:
diff changeset
487 typedef typename common_type<__dur1,__dur2>::type __cd;
kono
parents:
diff changeset
488 return __cd(__cd(__lhs).count() + __cd(__rhs).count());
kono
parents:
diff changeset
489 }
kono
parents:
diff changeset
490
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
491 /// The difference between two durations.
111
kono
parents:
diff changeset
492 template<typename _Rep1, typename _Period1,
kono
parents:
diff changeset
493 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
494 constexpr typename common_type<duration<_Rep1, _Period1>,
kono
parents:
diff changeset
495 duration<_Rep2, _Period2>>::type
kono
parents:
diff changeset
496 operator-(const duration<_Rep1, _Period1>& __lhs,
kono
parents:
diff changeset
497 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
498 {
kono
parents:
diff changeset
499 typedef duration<_Rep1, _Period1> __dur1;
kono
parents:
diff changeset
500 typedef duration<_Rep2, _Period2> __dur2;
kono
parents:
diff changeset
501 typedef typename common_type<__dur1,__dur2>::type __cd;
kono
parents:
diff changeset
502 return __cd(__cd(__lhs).count() - __cd(__rhs).count());
kono
parents:
diff changeset
503 }
kono
parents:
diff changeset
504
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
505 /// @}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
506
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
507 /// @cond undocumented
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
508
111
kono
parents:
diff changeset
509 // SFINAE helper to obtain common_type<_Rep1, _Rep2> only if _Rep2
kono
parents:
diff changeset
510 // is implicitly convertible to it.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
511 // _GLIBCXX_RESOLVE_LIB_DEFECTS
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
512 // 3050. Conversion specification problem in chrono::duration constructor
111
kono
parents:
diff changeset
513 template<typename _Rep1, typename _Rep2,
kono
parents:
diff changeset
514 typename _CRep = typename common_type<_Rep1, _Rep2>::type>
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
515 using __common_rep_t = typename
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
516 enable_if<is_convertible<const _Rep2&, _CRep>::value, _CRep>::type;
111
kono
parents:
diff changeset
517
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
518 /// @endcond
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
519
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
520 /// @relates duration @{
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
521
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
522 /// Multiply a duration by a scalar value.
111
kono
parents:
diff changeset
523 template<typename _Rep1, typename _Period, typename _Rep2>
kono
parents:
diff changeset
524 constexpr duration<__common_rep_t<_Rep1, _Rep2>, _Period>
kono
parents:
diff changeset
525 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
kono
parents:
diff changeset
526 {
kono
parents:
diff changeset
527 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
kono
parents:
diff changeset
528 __cd;
kono
parents:
diff changeset
529 return __cd(__cd(__d).count() * __s);
kono
parents:
diff changeset
530 }
kono
parents:
diff changeset
531
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
532 /// Multiply a duration by a scalar value.
111
kono
parents:
diff changeset
533 template<typename _Rep1, typename _Rep2, typename _Period>
kono
parents:
diff changeset
534 constexpr duration<__common_rep_t<_Rep2, _Rep1>, _Period>
kono
parents:
diff changeset
535 operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
kono
parents:
diff changeset
536 { return __d * __s; }
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538 template<typename _Rep1, typename _Period, typename _Rep2>
kono
parents:
diff changeset
539 constexpr
kono
parents:
diff changeset
540 duration<__common_rep_t<_Rep1, __disable_if_is_duration<_Rep2>>, _Period>
kono
parents:
diff changeset
541 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
kono
parents:
diff changeset
542 {
kono
parents:
diff changeset
543 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
kono
parents:
diff changeset
544 __cd;
kono
parents:
diff changeset
545 return __cd(__cd(__d).count() / __s);
kono
parents:
diff changeset
546 }
kono
parents:
diff changeset
547
kono
parents:
diff changeset
548 template<typename _Rep1, typename _Period1,
kono
parents:
diff changeset
549 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
550 constexpr typename common_type<_Rep1, _Rep2>::type
kono
parents:
diff changeset
551 operator/(const duration<_Rep1, _Period1>& __lhs,
kono
parents:
diff changeset
552 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
553 {
kono
parents:
diff changeset
554 typedef duration<_Rep1, _Period1> __dur1;
kono
parents:
diff changeset
555 typedef duration<_Rep2, _Period2> __dur2;
kono
parents:
diff changeset
556 typedef typename common_type<__dur1,__dur2>::type __cd;
kono
parents:
diff changeset
557 return __cd(__lhs).count() / __cd(__rhs).count();
kono
parents:
diff changeset
558 }
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 // DR 934.
kono
parents:
diff changeset
561 template<typename _Rep1, typename _Period, typename _Rep2>
kono
parents:
diff changeset
562 constexpr
kono
parents:
diff changeset
563 duration<__common_rep_t<_Rep1, __disable_if_is_duration<_Rep2>>, _Period>
kono
parents:
diff changeset
564 operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
kono
parents:
diff changeset
565 {
kono
parents:
diff changeset
566 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
kono
parents:
diff changeset
567 __cd;
kono
parents:
diff changeset
568 return __cd(__cd(__d).count() % __s);
kono
parents:
diff changeset
569 }
kono
parents:
diff changeset
570
kono
parents:
diff changeset
571 template<typename _Rep1, typename _Period1,
kono
parents:
diff changeset
572 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
573 constexpr typename common_type<duration<_Rep1, _Period1>,
kono
parents:
diff changeset
574 duration<_Rep2, _Period2>>::type
kono
parents:
diff changeset
575 operator%(const duration<_Rep1, _Period1>& __lhs,
kono
parents:
diff changeset
576 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
577 {
kono
parents:
diff changeset
578 typedef duration<_Rep1, _Period1> __dur1;
kono
parents:
diff changeset
579 typedef duration<_Rep2, _Period2> __dur2;
kono
parents:
diff changeset
580 typedef typename common_type<__dur1,__dur2>::type __cd;
kono
parents:
diff changeset
581 return __cd(__cd(__lhs).count() % __cd(__rhs).count());
kono
parents:
diff changeset
582 }
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 // comparisons
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
585
111
kono
parents:
diff changeset
586 template<typename _Rep1, typename _Period1,
kono
parents:
diff changeset
587 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
588 constexpr bool
kono
parents:
diff changeset
589 operator==(const duration<_Rep1, _Period1>& __lhs,
kono
parents:
diff changeset
590 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
591 {
kono
parents:
diff changeset
592 typedef duration<_Rep1, _Period1> __dur1;
kono
parents:
diff changeset
593 typedef duration<_Rep2, _Period2> __dur2;
kono
parents:
diff changeset
594 typedef typename common_type<__dur1,__dur2>::type __ct;
kono
parents:
diff changeset
595 return __ct(__lhs).count() == __ct(__rhs).count();
kono
parents:
diff changeset
596 }
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 template<typename _Rep1, typename _Period1,
kono
parents:
diff changeset
599 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
600 constexpr bool
kono
parents:
diff changeset
601 operator<(const duration<_Rep1, _Period1>& __lhs,
kono
parents:
diff changeset
602 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
603 {
kono
parents:
diff changeset
604 typedef duration<_Rep1, _Period1> __dur1;
kono
parents:
diff changeset
605 typedef duration<_Rep2, _Period2> __dur2;
kono
parents:
diff changeset
606 typedef typename common_type<__dur1,__dur2>::type __ct;
kono
parents:
diff changeset
607 return __ct(__lhs).count() < __ct(__rhs).count();
kono
parents:
diff changeset
608 }
kono
parents:
diff changeset
609
kono
parents:
diff changeset
610 template<typename _Rep1, typename _Period1,
kono
parents:
diff changeset
611 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
612 constexpr bool
kono
parents:
diff changeset
613 operator!=(const duration<_Rep1, _Period1>& __lhs,
kono
parents:
diff changeset
614 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
615 { return !(__lhs == __rhs); }
kono
parents:
diff changeset
616
kono
parents:
diff changeset
617 template<typename _Rep1, typename _Period1,
kono
parents:
diff changeset
618 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
619 constexpr bool
kono
parents:
diff changeset
620 operator<=(const duration<_Rep1, _Period1>& __lhs,
kono
parents:
diff changeset
621 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
622 { return !(__rhs < __lhs); }
kono
parents:
diff changeset
623
kono
parents:
diff changeset
624 template<typename _Rep1, typename _Period1,
kono
parents:
diff changeset
625 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
626 constexpr bool
kono
parents:
diff changeset
627 operator>(const duration<_Rep1, _Period1>& __lhs,
kono
parents:
diff changeset
628 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
629 { return __rhs < __lhs; }
kono
parents:
diff changeset
630
kono
parents:
diff changeset
631 template<typename _Rep1, typename _Period1,
kono
parents:
diff changeset
632 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
633 constexpr bool
kono
parents:
diff changeset
634 operator>=(const duration<_Rep1, _Period1>& __lhs,
kono
parents:
diff changeset
635 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
636 { return !(__lhs < __rhs); }
kono
parents:
diff changeset
637
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
638 /// @}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
639
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
640 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
641 # define _GLIBCXX_CHRONO_INT64_T int64_t
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
642 #elif defined __INT64_TYPE__
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
643 # define _GLIBCXX_CHRONO_INT64_T __INT64_TYPE__
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
644 #else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
645 static_assert(std::numeric_limits<unsigned long long>::digits >= 64,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
646 "Representation type for nanoseconds must have at least 64 bits");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
647 # define _GLIBCXX_CHRONO_INT64_T long long
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
648 #endif
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
649
111
kono
parents:
diff changeset
650 /// nanoseconds
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
651 typedef duration<_GLIBCXX_CHRONO_INT64_T, nano> nanoseconds;
111
kono
parents:
diff changeset
652
kono
parents:
diff changeset
653 /// microseconds
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
654 typedef duration<_GLIBCXX_CHRONO_INT64_T, micro> microseconds;
111
kono
parents:
diff changeset
655
kono
parents:
diff changeset
656 /// milliseconds
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
657 typedef duration<_GLIBCXX_CHRONO_INT64_T, milli> milliseconds;
111
kono
parents:
diff changeset
658
kono
parents:
diff changeset
659 /// seconds
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
660 typedef duration<_GLIBCXX_CHRONO_INT64_T> seconds;
111
kono
parents:
diff changeset
661
kono
parents:
diff changeset
662 /// minutes
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
663 typedef duration<_GLIBCXX_CHRONO_INT64_T, ratio< 60>> minutes;
111
kono
parents:
diff changeset
664
kono
parents:
diff changeset
665 /// hours
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
666 typedef duration<_GLIBCXX_CHRONO_INT64_T, ratio<3600>> hours;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
667
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
668 #undef _GLIBCXX_CHRONO_INT64_T
111
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 /// time_point
kono
parents:
diff changeset
671 template<typename _Clock, typename _Dur>
kono
parents:
diff changeset
672 struct time_point
kono
parents:
diff changeset
673 {
kono
parents:
diff changeset
674 typedef _Clock clock;
kono
parents:
diff changeset
675 typedef _Dur duration;
kono
parents:
diff changeset
676 typedef typename duration::rep rep;
kono
parents:
diff changeset
677 typedef typename duration::period period;
kono
parents:
diff changeset
678
kono
parents:
diff changeset
679 constexpr time_point() : __d(duration::zero())
kono
parents:
diff changeset
680 { }
kono
parents:
diff changeset
681
kono
parents:
diff changeset
682 constexpr explicit time_point(const duration& __dur)
kono
parents:
diff changeset
683 : __d(__dur)
kono
parents:
diff changeset
684 { }
kono
parents:
diff changeset
685
kono
parents:
diff changeset
686 // conversions
kono
parents:
diff changeset
687 template<typename _Dur2,
kono
parents:
diff changeset
688 typename = _Require<is_convertible<_Dur2, _Dur>>>
kono
parents:
diff changeset
689 constexpr time_point(const time_point<clock, _Dur2>& __t)
kono
parents:
diff changeset
690 : __d(__t.time_since_epoch())
kono
parents:
diff changeset
691 { }
kono
parents:
diff changeset
692
kono
parents:
diff changeset
693 // observer
kono
parents:
diff changeset
694 constexpr duration
kono
parents:
diff changeset
695 time_since_epoch() const
kono
parents:
diff changeset
696 { return __d; }
kono
parents:
diff changeset
697
kono
parents:
diff changeset
698 // arithmetic
kono
parents:
diff changeset
699 _GLIBCXX17_CONSTEXPR time_point&
kono
parents:
diff changeset
700 operator+=(const duration& __dur)
kono
parents:
diff changeset
701 {
kono
parents:
diff changeset
702 __d += __dur;
kono
parents:
diff changeset
703 return *this;
kono
parents:
diff changeset
704 }
kono
parents:
diff changeset
705
kono
parents:
diff changeset
706 _GLIBCXX17_CONSTEXPR time_point&
kono
parents:
diff changeset
707 operator-=(const duration& __dur)
kono
parents:
diff changeset
708 {
kono
parents:
diff changeset
709 __d -= __dur;
kono
parents:
diff changeset
710 return *this;
kono
parents:
diff changeset
711 }
kono
parents:
diff changeset
712
kono
parents:
diff changeset
713 // special values
kono
parents:
diff changeset
714 static constexpr time_point
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
715 min() noexcept
111
kono
parents:
diff changeset
716 { return time_point(duration::min()); }
kono
parents:
diff changeset
717
kono
parents:
diff changeset
718 static constexpr time_point
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
719 max() noexcept
111
kono
parents:
diff changeset
720 { return time_point(duration::max()); }
kono
parents:
diff changeset
721
kono
parents:
diff changeset
722 private:
kono
parents:
diff changeset
723 duration __d;
kono
parents:
diff changeset
724 };
kono
parents:
diff changeset
725
kono
parents:
diff changeset
726 /// time_point_cast
kono
parents:
diff changeset
727 template<typename _ToDur, typename _Clock, typename _Dur>
kono
parents:
diff changeset
728 constexpr typename enable_if<__is_duration<_ToDur>::value,
kono
parents:
diff changeset
729 time_point<_Clock, _ToDur>>::type
kono
parents:
diff changeset
730 time_point_cast(const time_point<_Clock, _Dur>& __t)
kono
parents:
diff changeset
731 {
kono
parents:
diff changeset
732 typedef time_point<_Clock, _ToDur> __time_point;
kono
parents:
diff changeset
733 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
kono
parents:
diff changeset
734 }
kono
parents:
diff changeset
735
kono
parents:
diff changeset
736 #if __cplusplus > 201402L
kono
parents:
diff changeset
737 template<typename _ToDur, typename _Clock, typename _Dur>
kono
parents:
diff changeset
738 constexpr
kono
parents:
diff changeset
739 enable_if_t<__is_duration<_ToDur>::value, time_point<_Clock, _ToDur>>
kono
parents:
diff changeset
740 floor(const time_point<_Clock, _Dur>& __tp)
kono
parents:
diff changeset
741 {
kono
parents:
diff changeset
742 return time_point<_Clock, _ToDur>{
kono
parents:
diff changeset
743 chrono::floor<_ToDur>(__tp.time_since_epoch())};
kono
parents:
diff changeset
744 }
kono
parents:
diff changeset
745
kono
parents:
diff changeset
746 template<typename _ToDur, typename _Clock, typename _Dur>
kono
parents:
diff changeset
747 constexpr
kono
parents:
diff changeset
748 enable_if_t<__is_duration<_ToDur>::value, time_point<_Clock, _ToDur>>
kono
parents:
diff changeset
749 ceil(const time_point<_Clock, _Dur>& __tp)
kono
parents:
diff changeset
750 {
kono
parents:
diff changeset
751 return time_point<_Clock, _ToDur>{
kono
parents:
diff changeset
752 chrono::ceil<_ToDur>(__tp.time_since_epoch())};
kono
parents:
diff changeset
753 }
kono
parents:
diff changeset
754
kono
parents:
diff changeset
755 template<typename _ToDur, typename _Clock, typename _Dur>
kono
parents:
diff changeset
756 constexpr enable_if_t<
kono
parents:
diff changeset
757 __and_<__is_duration<_ToDur>,
kono
parents:
diff changeset
758 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
kono
parents:
diff changeset
759 time_point<_Clock, _ToDur>>
kono
parents:
diff changeset
760 round(const time_point<_Clock, _Dur>& __tp)
kono
parents:
diff changeset
761 {
kono
parents:
diff changeset
762 return time_point<_Clock, _ToDur>{
kono
parents:
diff changeset
763 chrono::round<_ToDur>(__tp.time_since_epoch())};
kono
parents:
diff changeset
764 }
kono
parents:
diff changeset
765 #endif // C++17
kono
parents:
diff changeset
766
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
767 /// @relates time_point @{
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
768
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
769 /// Adjust a time point forwards by the given duration.
111
kono
parents:
diff changeset
770 template<typename _Clock, typename _Dur1,
kono
parents:
diff changeset
771 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
772 constexpr time_point<_Clock,
kono
parents:
diff changeset
773 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
kono
parents:
diff changeset
774 operator+(const time_point<_Clock, _Dur1>& __lhs,
kono
parents:
diff changeset
775 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
776 {
kono
parents:
diff changeset
777 typedef duration<_Rep2, _Period2> __dur2;
kono
parents:
diff changeset
778 typedef typename common_type<_Dur1,__dur2>::type __ct;
kono
parents:
diff changeset
779 typedef time_point<_Clock, __ct> __time_point;
kono
parents:
diff changeset
780 return __time_point(__lhs.time_since_epoch() + __rhs);
kono
parents:
diff changeset
781 }
kono
parents:
diff changeset
782
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
783 /// Adjust a time point forwards by the given duration.
111
kono
parents:
diff changeset
784 template<typename _Rep1, typename _Period1,
kono
parents:
diff changeset
785 typename _Clock, typename _Dur2>
kono
parents:
diff changeset
786 constexpr time_point<_Clock,
kono
parents:
diff changeset
787 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
kono
parents:
diff changeset
788 operator+(const duration<_Rep1, _Period1>& __lhs,
kono
parents:
diff changeset
789 const time_point<_Clock, _Dur2>& __rhs)
kono
parents:
diff changeset
790 {
kono
parents:
diff changeset
791 typedef duration<_Rep1, _Period1> __dur1;
kono
parents:
diff changeset
792 typedef typename common_type<__dur1,_Dur2>::type __ct;
kono
parents:
diff changeset
793 typedef time_point<_Clock, __ct> __time_point;
kono
parents:
diff changeset
794 return __time_point(__rhs.time_since_epoch() + __lhs);
kono
parents:
diff changeset
795 }
kono
parents:
diff changeset
796
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
797 /// Adjust a time point backwards by the given duration.
111
kono
parents:
diff changeset
798 template<typename _Clock, typename _Dur1,
kono
parents:
diff changeset
799 typename _Rep2, typename _Period2>
kono
parents:
diff changeset
800 constexpr time_point<_Clock,
kono
parents:
diff changeset
801 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
kono
parents:
diff changeset
802 operator-(const time_point<_Clock, _Dur1>& __lhs,
kono
parents:
diff changeset
803 const duration<_Rep2, _Period2>& __rhs)
kono
parents:
diff changeset
804 {
kono
parents:
diff changeset
805 typedef duration<_Rep2, _Period2> __dur2;
kono
parents:
diff changeset
806 typedef typename common_type<_Dur1,__dur2>::type __ct;
kono
parents:
diff changeset
807 typedef time_point<_Clock, __ct> __time_point;
kono
parents:
diff changeset
808 return __time_point(__lhs.time_since_epoch() -__rhs);
kono
parents:
diff changeset
809 }
kono
parents:
diff changeset
810
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
811 /// @}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
812
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
813 /// @relates time_point @{
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
814
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
815 /// The difference between two time points (as a duration)
111
kono
parents:
diff changeset
816 template<typename _Clock, typename _Dur1, typename _Dur2>
kono
parents:
diff changeset
817 constexpr typename common_type<_Dur1, _Dur2>::type
kono
parents:
diff changeset
818 operator-(const time_point<_Clock, _Dur1>& __lhs,
kono
parents:
diff changeset
819 const time_point<_Clock, _Dur2>& __rhs)
kono
parents:
diff changeset
820 { return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
kono
parents:
diff changeset
821
kono
parents:
diff changeset
822 template<typename _Clock, typename _Dur1, typename _Dur2>
kono
parents:
diff changeset
823 constexpr bool
kono
parents:
diff changeset
824 operator==(const time_point<_Clock, _Dur1>& __lhs,
kono
parents:
diff changeset
825 const time_point<_Clock, _Dur2>& __rhs)
kono
parents:
diff changeset
826 { return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 template<typename _Clock, typename _Dur1, typename _Dur2>
kono
parents:
diff changeset
829 constexpr bool
kono
parents:
diff changeset
830 operator!=(const time_point<_Clock, _Dur1>& __lhs,
kono
parents:
diff changeset
831 const time_point<_Clock, _Dur2>& __rhs)
kono
parents:
diff changeset
832 { return !(__lhs == __rhs); }
kono
parents:
diff changeset
833
kono
parents:
diff changeset
834 template<typename _Clock, typename _Dur1, typename _Dur2>
kono
parents:
diff changeset
835 constexpr bool
kono
parents:
diff changeset
836 operator<(const time_point<_Clock, _Dur1>& __lhs,
kono
parents:
diff changeset
837 const time_point<_Clock, _Dur2>& __rhs)
kono
parents:
diff changeset
838 { return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
kono
parents:
diff changeset
839
kono
parents:
diff changeset
840 template<typename _Clock, typename _Dur1, typename _Dur2>
kono
parents:
diff changeset
841 constexpr bool
kono
parents:
diff changeset
842 operator<=(const time_point<_Clock, _Dur1>& __lhs,
kono
parents:
diff changeset
843 const time_point<_Clock, _Dur2>& __rhs)
kono
parents:
diff changeset
844 { return !(__rhs < __lhs); }
kono
parents:
diff changeset
845
kono
parents:
diff changeset
846 template<typename _Clock, typename _Dur1, typename _Dur2>
kono
parents:
diff changeset
847 constexpr bool
kono
parents:
diff changeset
848 operator>(const time_point<_Clock, _Dur1>& __lhs,
kono
parents:
diff changeset
849 const time_point<_Clock, _Dur2>& __rhs)
kono
parents:
diff changeset
850 { return __rhs < __lhs; }
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 template<typename _Clock, typename _Dur1, typename _Dur2>
kono
parents:
diff changeset
853 constexpr bool
kono
parents:
diff changeset
854 operator>=(const time_point<_Clock, _Dur1>& __lhs,
kono
parents:
diff changeset
855 const time_point<_Clock, _Dur2>& __rhs)
kono
parents:
diff changeset
856 { return !(__lhs < __rhs); }
kono
parents:
diff changeset
857
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
858 // @}
111
kono
parents:
diff changeset
859
kono
parents:
diff changeset
860 // Clocks.
kono
parents:
diff changeset
861
kono
parents:
diff changeset
862 // Why nanosecond resolution as the default?
kono
parents:
diff changeset
863 // Why have std::system_clock always count in the highest
kono
parents:
diff changeset
864 // resolution (ie nanoseconds), even if on some OSes the low 3
kono
parents:
diff changeset
865 // or 9 decimal digits will be always zero? This allows later
kono
parents:
diff changeset
866 // implementations to change the system_clock::now()
kono
parents:
diff changeset
867 // implementation any time to provide better resolution without
kono
parents:
diff changeset
868 // changing function signature or units.
kono
parents:
diff changeset
869
kono
parents:
diff changeset
870 // To support the (forward) evolution of the library's defined
kono
parents:
diff changeset
871 // clocks, wrap inside inline namespace so that the current
kono
parents:
diff changeset
872 // defintions of system_clock, steady_clock, and
kono
parents:
diff changeset
873 // high_resolution_clock types are uniquely mangled. This way, new
kono
parents:
diff changeset
874 // code can use the latests clocks, while the library can contain
kono
parents:
diff changeset
875 // compatibility definitions for previous versions. At some
kono
parents:
diff changeset
876 // point, when these clocks settle down, the inlined namespaces
kono
parents:
diff changeset
877 // can be removed. XXX GLIBCXX_ABI Deprecated
kono
parents:
diff changeset
878 inline namespace _V2 {
kono
parents:
diff changeset
879
kono
parents:
diff changeset
880 /**
kono
parents:
diff changeset
881 * @brief System clock.
kono
parents:
diff changeset
882 *
kono
parents:
diff changeset
883 * Time returned represents wall time from the system-wide clock.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
884 * @ingroup chrono
111
kono
parents:
diff changeset
885 */
kono
parents:
diff changeset
886 struct system_clock
kono
parents:
diff changeset
887 {
kono
parents:
diff changeset
888 typedef chrono::nanoseconds duration;
kono
parents:
diff changeset
889 typedef duration::rep rep;
kono
parents:
diff changeset
890 typedef duration::period period;
kono
parents:
diff changeset
891 typedef chrono::time_point<system_clock, duration> time_point;
kono
parents:
diff changeset
892
kono
parents:
diff changeset
893 static_assert(system_clock::duration::min()
kono
parents:
diff changeset
894 < system_clock::duration::zero(),
kono
parents:
diff changeset
895 "a clock's minimum duration cannot be less than its epoch");
kono
parents:
diff changeset
896
kono
parents:
diff changeset
897 static constexpr bool is_steady = false;
kono
parents:
diff changeset
898
kono
parents:
diff changeset
899 static time_point
kono
parents:
diff changeset
900 now() noexcept;
kono
parents:
diff changeset
901
kono
parents:
diff changeset
902 // Map to C API
kono
parents:
diff changeset
903 static std::time_t
kono
parents:
diff changeset
904 to_time_t(const time_point& __t) noexcept
kono
parents:
diff changeset
905 {
kono
parents:
diff changeset
906 return std::time_t(duration_cast<chrono::seconds>
kono
parents:
diff changeset
907 (__t.time_since_epoch()).count());
kono
parents:
diff changeset
908 }
kono
parents:
diff changeset
909
kono
parents:
diff changeset
910 static time_point
kono
parents:
diff changeset
911 from_time_t(std::time_t __t) noexcept
kono
parents:
diff changeset
912 {
kono
parents:
diff changeset
913 typedef chrono::time_point<system_clock, seconds> __from;
kono
parents:
diff changeset
914 return time_point_cast<system_clock::duration>
kono
parents:
diff changeset
915 (__from(chrono::seconds(__t)));
kono
parents:
diff changeset
916 }
kono
parents:
diff changeset
917 };
kono
parents:
diff changeset
918
kono
parents:
diff changeset
919
kono
parents:
diff changeset
920 /**
kono
parents:
diff changeset
921 * @brief Monotonic clock
kono
parents:
diff changeset
922 *
kono
parents:
diff changeset
923 * Time returned has the property of only increasing at a uniform rate.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
924 * @ingroup chrono
111
kono
parents:
diff changeset
925 */
kono
parents:
diff changeset
926 struct steady_clock
kono
parents:
diff changeset
927 {
kono
parents:
diff changeset
928 typedef chrono::nanoseconds duration;
kono
parents:
diff changeset
929 typedef duration::rep rep;
kono
parents:
diff changeset
930 typedef duration::period period;
kono
parents:
diff changeset
931 typedef chrono::time_point<steady_clock, duration> time_point;
kono
parents:
diff changeset
932
kono
parents:
diff changeset
933 static constexpr bool is_steady = true;
kono
parents:
diff changeset
934
kono
parents:
diff changeset
935 static time_point
kono
parents:
diff changeset
936 now() noexcept;
kono
parents:
diff changeset
937 };
kono
parents:
diff changeset
938
kono
parents:
diff changeset
939
kono
parents:
diff changeset
940 /**
kono
parents:
diff changeset
941 * @brief Highest-resolution clock
kono
parents:
diff changeset
942 *
kono
parents:
diff changeset
943 * This is the clock "with the shortest tick period." Alias to
kono
parents:
diff changeset
944 * std::system_clock until higher-than-nanosecond definitions
kono
parents:
diff changeset
945 * become feasible.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
946 * @ingroup chrono
111
kono
parents:
diff changeset
947 */
kono
parents:
diff changeset
948 using high_resolution_clock = system_clock;
kono
parents:
diff changeset
949
kono
parents:
diff changeset
950 } // end inline namespace _V2
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
951 // @}
111
kono
parents:
diff changeset
952 } // namespace chrono
kono
parents:
diff changeset
953
kono
parents:
diff changeset
954 #if __cplusplus > 201103L
kono
parents:
diff changeset
955
kono
parents:
diff changeset
956 #define __cpp_lib_chrono_udls 201304
kono
parents:
diff changeset
957
kono
parents:
diff changeset
958 inline namespace literals
kono
parents:
diff changeset
959 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
960 /** ISO C++ 2014 namespace for suffixes for duration literals.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
961 *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
962 * These suffixes can be used to create `chrono::duration` values with
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
963 * tick periods of hours, minutes, seconds, milliseconds, microseconds
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
964 * or nanoseconds. For example, `std::chrono::seconds(5)` can be written
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
965 * as `5s` after making the suffix visible in the current scope.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
966 * The suffixes can be made visible by a using-directive or
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
967 * using-declaration such as:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
968 * - `using namespace std::chrono_literals;`
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
969 * - `using namespace std::literals;`
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
970 * - `using namespace std::chrono;`
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
971 * - `using namespace std;`
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
972 * - `using std::chrono_literals::operator""s;`
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
973 *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
974 * The result of these suffixes on an integer literal is one of the
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
975 * standard typedefs such as `std::chrono::hours`.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
976 * The result on a floating-point literal is a duration type with the
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
977 * specified tick period and an unspecified floating-point representation,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
978 * for example `1.5e2ms` might be equivalent to
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
979 * `chrono::duration<long double, chrono::milli>(1.5e2)`.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
980 *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
981 * @ingroup chrono
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
982 */
111
kono
parents:
diff changeset
983 inline namespace chrono_literals
kono
parents:
diff changeset
984 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
985 #pragma GCC diagnostic push
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
986 #pragma GCC diagnostic ignored "-Wliteral-suffix"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
987 /// @cond undocumented
111
kono
parents:
diff changeset
988 template<typename _Dur, char... _Digits>
kono
parents:
diff changeset
989 constexpr _Dur __check_overflow()
kono
parents:
diff changeset
990 {
kono
parents:
diff changeset
991 using _Val = __parse_int::_Parse_int<_Digits...>;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
992 constexpr typename _Dur::rep __repval = _Val::value;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
993 static_assert(__repval >= 0 && __repval == _Val::value,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
994 "literal value cannot be represented by duration type");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
995 return _Dur(__repval);
111
kono
parents:
diff changeset
996 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
997 /// @endcond
111
kono
parents:
diff changeset
998
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
999 /// Literal suffix for durations representing non-integer hours
111
kono
parents:
diff changeset
1000 constexpr chrono::duration<long double, ratio<3600,1>>
kono
parents:
diff changeset
1001 operator""h(long double __hours)
kono
parents:
diff changeset
1002 { return chrono::duration<long double, ratio<3600,1>>{__hours}; }
kono
parents:
diff changeset
1003
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1004 /// Literal suffix for durations of type `std::chrono::hours`
111
kono
parents:
diff changeset
1005 template <char... _Digits>
kono
parents:
diff changeset
1006 constexpr chrono::hours
kono
parents:
diff changeset
1007 operator""h()
kono
parents:
diff changeset
1008 { return __check_overflow<chrono::hours, _Digits...>(); }
kono
parents:
diff changeset
1009
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1010 /// Literal suffix for durations representing non-integer minutes
111
kono
parents:
diff changeset
1011 constexpr chrono::duration<long double, ratio<60,1>>
kono
parents:
diff changeset
1012 operator""min(long double __mins)
kono
parents:
diff changeset
1013 { return chrono::duration<long double, ratio<60,1>>{__mins}; }
kono
parents:
diff changeset
1014
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1015 /// Literal suffix for durations of type `std::chrono::minutes`
111
kono
parents:
diff changeset
1016 template <char... _Digits>
kono
parents:
diff changeset
1017 constexpr chrono::minutes
kono
parents:
diff changeset
1018 operator""min()
kono
parents:
diff changeset
1019 { return __check_overflow<chrono::minutes, _Digits...>(); }
kono
parents:
diff changeset
1020
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1021 /// Literal suffix for durations representing non-integer seconds
111
kono
parents:
diff changeset
1022 constexpr chrono::duration<long double>
kono
parents:
diff changeset
1023 operator""s(long double __secs)
kono
parents:
diff changeset
1024 { return chrono::duration<long double>{__secs}; }
kono
parents:
diff changeset
1025
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1026 /// Literal suffix for durations of type `std::chrono::seconds`
111
kono
parents:
diff changeset
1027 template <char... _Digits>
kono
parents:
diff changeset
1028 constexpr chrono::seconds
kono
parents:
diff changeset
1029 operator""s()
kono
parents:
diff changeset
1030 { return __check_overflow<chrono::seconds, _Digits...>(); }
kono
parents:
diff changeset
1031
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1032 /// Literal suffix for durations representing non-integer milliseconds
111
kono
parents:
diff changeset
1033 constexpr chrono::duration<long double, milli>
kono
parents:
diff changeset
1034 operator""ms(long double __msecs)
kono
parents:
diff changeset
1035 { return chrono::duration<long double, milli>{__msecs}; }
kono
parents:
diff changeset
1036
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1037 /// Literal suffix for durations of type `std::chrono::milliseconds`
111
kono
parents:
diff changeset
1038 template <char... _Digits>
kono
parents:
diff changeset
1039 constexpr chrono::milliseconds
kono
parents:
diff changeset
1040 operator""ms()
kono
parents:
diff changeset
1041 { return __check_overflow<chrono::milliseconds, _Digits...>(); }
kono
parents:
diff changeset
1042
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1043 /// Literal suffix for durations representing non-integer microseconds
111
kono
parents:
diff changeset
1044 constexpr chrono::duration<long double, micro>
kono
parents:
diff changeset
1045 operator""us(long double __usecs)
kono
parents:
diff changeset
1046 { return chrono::duration<long double, micro>{__usecs}; }
kono
parents:
diff changeset
1047
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1048 /// Literal suffix for durations of type `std::chrono::microseconds`
111
kono
parents:
diff changeset
1049 template <char... _Digits>
kono
parents:
diff changeset
1050 constexpr chrono::microseconds
kono
parents:
diff changeset
1051 operator""us()
kono
parents:
diff changeset
1052 { return __check_overflow<chrono::microseconds, _Digits...>(); }
kono
parents:
diff changeset
1053
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1054 /// Literal suffix for durations representing non-integer nanoseconds
111
kono
parents:
diff changeset
1055 constexpr chrono::duration<long double, nano>
kono
parents:
diff changeset
1056 operator""ns(long double __nsecs)
kono
parents:
diff changeset
1057 { return chrono::duration<long double, nano>{__nsecs}; }
kono
parents:
diff changeset
1058
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1059 /// Literal suffix for durations of type `std::chrono::nanoseconds`
111
kono
parents:
diff changeset
1060 template <char... _Digits>
kono
parents:
diff changeset
1061 constexpr chrono::nanoseconds
kono
parents:
diff changeset
1062 operator""ns()
kono
parents:
diff changeset
1063 { return __check_overflow<chrono::nanoseconds, _Digits...>(); }
kono
parents:
diff changeset
1064
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1065 #pragma GCC diagnostic pop
111
kono
parents:
diff changeset
1066 } // inline namespace chrono_literals
kono
parents:
diff changeset
1067 } // inline namespace literals
kono
parents:
diff changeset
1068
kono
parents:
diff changeset
1069 namespace chrono
kono
parents:
diff changeset
1070 {
kono
parents:
diff changeset
1071 using namespace literals::chrono_literals;
kono
parents:
diff changeset
1072 } // namespace chrono
kono
parents:
diff changeset
1073
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1074 #endif // C++14
111
kono
parents:
diff changeset
1075
kono
parents:
diff changeset
1076 _GLIBCXX_END_NAMESPACE_VERSION
kono
parents:
diff changeset
1077 } // namespace std
kono
parents:
diff changeset
1078
kono
parents:
diff changeset
1079 #endif // C++11
kono
parents:
diff changeset
1080
kono
parents:
diff changeset
1081 #endif //_GLIBCXX_CHRONO