libstdc++
chrono.h
Go to the documentation of this file.
1// chrono::duration and chrono::time_point -*- C++ -*-
2
3// Copyright (C) 2008-2022 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file include/bits/chrono.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{chrono}
28 */
29
30#ifndef _GLIBCXX_CHRONO_H
31#define _GLIBCXX_CHRONO_H 1
32
33#pragma GCC system_header
34
35#if __cplusplus >= 201103L
36
37#include <ratio>
38#include <type_traits>
39#include <limits>
40#include <ctime>
41#include <bits/parse_numbers.h> // for literals support.
42#if __cplusplus >= 202002L
43# include <concepts>
44# include <compare>
45#endif
46
47namespace std _GLIBCXX_VISIBILITY(default)
48{
49_GLIBCXX_BEGIN_NAMESPACE_VERSION
50
51#if __cplusplus >= 201703L
52 namespace filesystem { struct __file_clock; };
53#endif
54
55 namespace chrono
56 {
57 /// @addtogroup chrono
58 /// @{
59
60 /// `chrono::duration` represents a distance between two points in time
61 template<typename _Rep, typename _Period = ratio<1>>
62 class duration;
63
64 /// `chrono::time_point` represents a point in time as measured by a clock
65 template<typename _Clock, typename _Dur = typename _Clock::duration>
66 class time_point;
67 /// @}
68 }
69
70 /// @addtogroup chrono
71 /// @{
72
73 // 20.11.4.3 specialization of common_type (for duration, sfinae-friendly)
74
75 /// @cond undocumented
76
77 template<typename _CT, typename _Period1, typename _Period2, typename = void>
78 struct __duration_common_type
79 { };
80
81 template<typename _CT, typename _Period1, typename _Period2>
82 struct __duration_common_type<_CT, _Period1, _Period2,
83 __void_t<typename _CT::type>>
84 {
85 private:
86 using __gcd_num = __static_gcd<_Period1::num, _Period2::num>;
87 using __gcd_den = __static_gcd<_Period1::den, _Period2::den>;
88 using __cr = typename _CT::type;
89 using __r = ratio<__gcd_num::value,
90 (_Period1::den / __gcd_den::value) * _Period2::den>;
91
92 public:
93 using type = chrono::duration<__cr, typename __r::type>;
94 };
95
96 /// @endcond
97
98 /// @{
99 /// @relates chrono::duration
100
101 /// Specialization of common_type for chrono::duration types.
102 template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2>
103 struct common_type<chrono::duration<_Rep1, _Period1>,
104 chrono::duration<_Rep2, _Period2>>
105 : __duration_common_type<common_type<_Rep1, _Rep2>,
106 typename _Period1::type,
107 typename _Period2::type>
108 { };
109
110 /// Specialization of common_type for two identical chrono::duration types.
111 template<typename _Rep, typename _Period>
112 struct common_type<chrono::duration<_Rep, _Period>,
113 chrono::duration<_Rep, _Period>>
114 {
116 typename _Period::type>;
117 };
118
119 /// Specialization of common_type for one chrono::duration type.
120 template<typename _Rep, typename _Period>
121 struct common_type<chrono::duration<_Rep, _Period>>
122 {
124 typename _Period::type>;
125 };
126 /// @}
127
128 // 20.11.4.3 specialization of common_type (for time_point, sfinae-friendly)
129
130 /// @cond undocumented
131
132 template<typename _CT, typename _Clock, typename = void>
133 struct __timepoint_common_type
134 { };
135
136 template<typename _CT, typename _Clock>
137 struct __timepoint_common_type<_CT, _Clock, __void_t<typename _CT::type>>
138 {
139 using type = chrono::time_point<_Clock, typename _CT::type>;
140 };
141
142 /// @endcond
143
144 /// @{
145 /// @relates chrono::time_point
146
147 /// Specialization of common_type for chrono::time_point types.
148 template<typename _Clock, typename _Duration1, typename _Duration2>
149 struct common_type<chrono::time_point<_Clock, _Duration1>,
150 chrono::time_point<_Clock, _Duration2>>
151 : __timepoint_common_type<common_type<_Duration1, _Duration2>, _Clock>
152 { };
153
154 /// Specialization of common_type for two identical chrono::time_point types.
155 template<typename _Clock, typename _Duration>
156 struct common_type<chrono::time_point<_Clock, _Duration>,
157 chrono::time_point<_Clock, _Duration>>
159
160 /// Specialization of common_type for one chrono::time_point type.
161 template<typename _Clock, typename _Duration>
162 struct common_type<chrono::time_point<_Clock, _Duration>>
164 /// @}
165
166 /// @} group chrono
167
168 namespace chrono
169 {
170 /// @addtogroup chrono
171 /// @{
172
173 /// @cond undocumented
174
175 // Primary template for duration_cast impl.
176 template<typename _ToDur, typename _CF, typename _CR,
177 bool _NumIsOne = false, bool _DenIsOne = false>
178 struct __duration_cast_impl
179 {
180 template<typename _Rep, typename _Period>
181 static constexpr _ToDur
182 __cast(const duration<_Rep, _Period>& __d)
183 {
184 typedef typename _ToDur::rep __to_rep;
185 return _ToDur(static_cast<__to_rep>(static_cast<_CR>(__d.count())
186 * static_cast<_CR>(_CF::num)
187 / static_cast<_CR>(_CF::den)));
188 }
189 };
190
191 template<typename _ToDur, typename _CF, typename _CR>
192 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
193 {
194 template<typename _Rep, typename _Period>
195 static constexpr _ToDur
196 __cast(const duration<_Rep, _Period>& __d)
197 {
198 typedef typename _ToDur::rep __to_rep;
199 return _ToDur(static_cast<__to_rep>(__d.count()));
200 }
201 };
202
203 template<typename _ToDur, typename _CF, typename _CR>
204 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
205 {
206 template<typename _Rep, typename _Period>
207 static constexpr _ToDur
208 __cast(const duration<_Rep, _Period>& __d)
209 {
210 typedef typename _ToDur::rep __to_rep;
211 return _ToDur(static_cast<__to_rep>(
212 static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den)));
213 }
214 };
215
216 template<typename _ToDur, typename _CF, typename _CR>
217 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
218 {
219 template<typename _Rep, typename _Period>
220 static constexpr _ToDur
221 __cast(const duration<_Rep, _Period>& __d)
222 {
223 typedef typename _ToDur::rep __to_rep;
224 return _ToDur(static_cast<__to_rep>(
225 static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num)));
226 }
227 };
228
229 template<typename _Tp>
230 struct __is_duration
232 { };
233
234 template<typename _Rep, typename _Period>
235 struct __is_duration<duration<_Rep, _Period>>
237 { };
238
239 template<typename _Tp>
240 using __enable_if_is_duration
241 = typename enable_if<__is_duration<_Tp>::value, _Tp>::type;
242
243 template<typename _Tp>
244 using __disable_if_is_duration
245 = typename enable_if<!__is_duration<_Tp>::value, _Tp>::type;
246
247 /// @endcond
248
249 /** Convert a `duration` to type `ToDur`.
250 *
251 * If the duration cannot be represented accurately in the result type,
252 * returns the result of integer truncation (i.e., rounded towards zero).
253 *
254 * @tparam _ToDur The result type must be a `duration`.
255 * @param __d A duration.
256 * @return The value of `__d` converted to type `_ToDur`.
257 * @since C++11
258 */
259 template<typename _ToDur, typename _Rep, typename _Period>
260 _GLIBCXX_NODISCARD
261 constexpr __enable_if_is_duration<_ToDur>
263 {
264 typedef typename _ToDur::period __to_period;
265 typedef typename _ToDur::rep __to_rep;
268 typedef __duration_cast_impl<_ToDur, __cf, __cr,
269 __cf::num == 1, __cf::den == 1> __dc;
270 return __dc::__cast(__d);
271 }
272
273 /** Trait indicating whether to treat a type as a floating-point type.
274 *
275 * The chrono library uses this trait to tell whether a `duration` can
276 * represent fractional values of the given precision, or only integral
277 * values.
278 *
279 * You should specialize this trait for your own numeric types that are
280 * used with `duration` and can represent non-integral values.
281 *
282 * @since C++11
283 */
284 template<typename _Rep>
286 : is_floating_point<_Rep>
287 { };
288
289#if __cplusplus > 201402L
290 template <typename _Rep>
291 inline constexpr bool treat_as_floating_point_v =
293#endif // C++17
294
295#if __cplusplus > 201703L
296#if __cpp_lib_concepts
297 template<typename _Tp>
298 inline constexpr bool is_clock_v = false;
299
300 template<typename _Tp>
301 requires requires {
302 typename _Tp::rep;
303 typename _Tp::period;
304 typename _Tp::duration;
305 typename _Tp::time_point::clock;
306 typename _Tp::time_point::duration;
307 { &_Tp::is_steady } -> same_as<const bool*>;
308 { _Tp::now() } -> same_as<typename _Tp::time_point>;
309 requires same_as<typename _Tp::duration,
310 duration<typename _Tp::rep, typename _Tp::period>>;
311 requires same_as<typename _Tp::time_point::duration,
312 typename _Tp::duration>;
313 }
314 inline constexpr bool is_clock_v<_Tp> = true;
315#else
316 template<typename _Tp, typename = void>
317 inline constexpr bool is_clock_v = false;
318
319 template<typename _Tp>
320 inline constexpr bool
321 is_clock_v<_Tp, void_t<typename _Tp::rep, typename _Tp::period,
322 typename _Tp::duration,
323 typename _Tp::time_point::duration,
324 decltype(_Tp::is_steady),
325 decltype(_Tp::now())>>
326 = __and_v<is_same<typename _Tp::duration,
327 duration<typename _Tp::rep, typename _Tp::period>>,
328 is_same<typename _Tp::time_point::duration,
329 typename _Tp::duration>,
330 is_same<decltype(&_Tp::is_steady), const bool*>,
331 is_same<decltype(_Tp::now()), typename _Tp::time_point>>;
332#endif
333
334 template<typename _Tp>
335 struct is_clock
336 : bool_constant<is_clock_v<_Tp>>
337 { };
338#endif // C++20
339
340#if __cplusplus >= 201703L
341# define __cpp_lib_chrono 201611L
342
343 /** Convert a `duration` to type `ToDur` and round down.
344 *
345 * If the duration cannot be represented exactly in the result type,
346 * returns the closest value that is less than the argument.
347 *
348 * @tparam _ToDur The result type must be a `duration`.
349 * @param __d A duration.
350 * @return The value of `__d` converted to type `_ToDur`.
351 * @since C++17
352 */
353 template<typename _ToDur, typename _Rep, typename _Period>
354 [[nodiscard]] constexpr __enable_if_is_duration<_ToDur>
355 floor(const duration<_Rep, _Period>& __d)
356 {
357 auto __to = chrono::duration_cast<_ToDur>(__d);
358 if (__to > __d)
359 return __to - _ToDur{1};
360 return __to;
361 }
362
363 /** Convert a `duration` to type `ToDur` and round up.
364 *
365 * If the duration cannot be represented exactly in the result type,
366 * returns the closest value that is greater than the argument.
367 *
368 * @tparam _ToDur The result type must be a `duration`.
369 * @param __d A duration.
370 * @return The value of `__d` converted to type `_ToDur`.
371 * @since C++17
372 */
373 template<typename _ToDur, typename _Rep, typename _Period>
374 [[nodiscard]] constexpr __enable_if_is_duration<_ToDur>
375 ceil(const duration<_Rep, _Period>& __d)
376 {
377 auto __to = chrono::duration_cast<_ToDur>(__d);
378 if (__to < __d)
379 return __to + _ToDur{1};
380 return __to;
381 }
382
383 /** Convert a `duration` to type `ToDur` and round to the closest value.
384 *
385 * If the duration cannot be represented exactly in the result type,
386 * returns the closest value, rounding ties to even.
387 *
388 * @tparam _ToDur The result type must be a `duration` with a
389 * non-floating-point `rep` type.
390 * @param __d A duration.
391 * @return The value of `__d` converted to type `_ToDur`.
392 * @since C++17
393 */
394 template <typename _ToDur, typename _Rep, typename _Period>
395 [[nodiscard]] constexpr
397 __and_<__is_duration<_ToDur>,
398 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
399 _ToDur>
401 {
402 _ToDur __t0 = chrono::floor<_ToDur>(__d);
403 _ToDur __t1 = __t0 + _ToDur{1};
404 auto __diff0 = __d - __t0;
405 auto __diff1 = __t1 - __d;
406 if (__diff0 == __diff1)
407 {
408 if (__t0.count() & 1)
409 return __t1;
410 return __t0;
411 }
412 else if (__diff0 < __diff1)
413 return __t0;
414 return __t1;
415 }
416
417 /** The absolute (non-negative) value of a duration.
418 *
419 * @param __d A duration with a signed `rep` type.
420 * @return A duration of the same type as the argument, with value |d|.
421 * @since C++17
422 */
423 template<typename _Rep, typename _Period>
424 [[nodiscard]] constexpr
425 enable_if_t<numeric_limits<_Rep>::is_signed, duration<_Rep, _Period>>
427 {
428 if (__d >= __d.zero())
429 return __d;
430 return -__d;
431 }
432
433 // Make chrono::ceil<D> also usable as chrono::__detail::ceil<D>.
434 namespace __detail { using chrono::ceil; }
435
436#else // ! C++17
437
438 // We want to use ceil even when compiling for earlier standards versions.
439 // C++11 only allows a single statement in a constexpr function, so we
440 // need to move the comparison into a separate function, __ceil_impl.
441 namespace __detail
442 {
443 template<typename _Tp, typename _Up>
444 constexpr _Tp
445 __ceil_impl(const _Tp& __t, const _Up& __u)
446 {
447 return (__t < __u) ? (__t + _Tp{1}) : __t;
448 }
449
450 // C++11-friendly version of std::chrono::ceil<D> for internal use.
451 template<typename _ToDur, typename _Rep, typename _Period>
452 constexpr _ToDur
453 ceil(const duration<_Rep, _Period>& __d)
454 {
455 return __detail::__ceil_impl(chrono::duration_cast<_ToDur>(__d), __d);
456 }
457 }
458#endif // C++17
459
460 /// duration_values
461 template<typename _Rep>
463 {
464 static constexpr _Rep
465 zero() noexcept
466 { return _Rep(0); }
467
468 static constexpr _Rep
469 max() noexcept
470 { return numeric_limits<_Rep>::max(); }
471
472 static constexpr _Rep
473 min() noexcept
474 { return numeric_limits<_Rep>::lowest(); }
475 };
476
477 /// @cond undocumented
478
479 template<typename _Tp>
480 struct __is_ratio
482 { };
483
484 template<intmax_t _Num, intmax_t _Den>
485 struct __is_ratio<ratio<_Num, _Den>>
487 { };
488
489 /// @endcond
490
491 template<typename _Rep, typename _Period>
493 {
494 static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration");
495 static_assert(__is_ratio<_Period>::value,
496 "period must be a specialization of ratio");
497 static_assert(_Period::num > 0, "period must be positive");
498
499 template<typename _Rep2>
501
502 static constexpr intmax_t
503 _S_gcd(intmax_t __m, intmax_t __n) noexcept
504 {
505 // Duration only allows positive periods so we don't need to
506 // handle negative values here (unlike __static_gcd and std::gcd).
507#if __cplusplus >= 201402L
508 do
509 {
510 intmax_t __rem = __m % __n;
511 __m = __n;
512 __n = __rem;
513 }
514 while (__n != 0);
515 return __m;
516#else
517 // C++11 doesn't allow loops in constexpr functions, but this
518 // recursive version can be more expensive to evaluate.
519 return (__n == 0) ? __m : _S_gcd(__n, __m % __n);
520#endif
521 }
522
523 // _GLIBCXX_RESOLVE_LIB_DEFECTS
524 // 2094. overflow shouldn't participate in overload resolution
525 // 3090. What is [2094] intended to mean?
526 // This only produces a valid type if no overflow occurs.
527 template<typename _R1, typename _R2,
528 intmax_t __gcd1 = _S_gcd(_R1::num, _R2::num),
529 intmax_t __gcd2 = _S_gcd(_R1::den, _R2::den)>
530 using __divide = ratio<(_R1::num / __gcd1) * (_R2::den / __gcd2),
531 (_R1::den / __gcd2) * (_R2::num / __gcd1)>;
532
533 // _Period2 is an exact multiple of _Period
534 template<typename _Period2>
535 using __is_harmonic
536 = __bool_constant<__divide<_Period2, _Period>::den == 1>;
537
538 public:
539
540 using rep = _Rep;
541 using period = typename _Period::type;
542
543 // 20.11.5.1 construction / copy / destroy
544 constexpr duration() = default;
545
546 duration(const duration&) = default;
547
548 // _GLIBCXX_RESOLVE_LIB_DEFECTS
549 // 3050. Conversion specification problem in chrono::duration
550 template<typename _Rep2, typename = _Require<
551 is_convertible<const _Rep2&, rep>,
552 __or_<__is_float<rep>, __not_<__is_float<_Rep2>>>>>
553 constexpr explicit duration(const _Rep2& __rep)
554 : __r(static_cast<rep>(__rep)) { }
555
556 template<typename _Rep2, typename _Period2, typename = _Require<
557 is_convertible<const _Rep2&, rep>,
558 __or_<__is_float<rep>,
559 __and_<__is_harmonic<_Period2>,
560 __not_<__is_float<_Rep2>>>>>>
561 constexpr duration(const duration<_Rep2, _Period2>& __d)
562 : __r(duration_cast<duration>(__d).count()) { }
563
564 ~duration() = default;
565 duration& operator=(const duration&) = default;
566
567 // 20.11.5.2 observer
568 constexpr rep
569 count() const
570 { return __r; }
571
572 // 20.11.5.3 arithmetic
573
575 operator+() const
576 { return duration<typename common_type<rep>::type, period>(__r); }
577
579 operator-() const
580 { return duration<typename common_type<rep>::type, period>(-__r); }
581
582 _GLIBCXX17_CONSTEXPR duration&
583 operator++()
584 {
585 ++__r;
586 return *this;
587 }
588
589 _GLIBCXX17_CONSTEXPR duration
590 operator++(int)
591 { return duration(__r++); }
592
593 _GLIBCXX17_CONSTEXPR duration&
594 operator--()
595 {
596 --__r;
597 return *this;
598 }
599
600 _GLIBCXX17_CONSTEXPR duration
601 operator--(int)
602 { return duration(__r--); }
603
604 _GLIBCXX17_CONSTEXPR duration&
605 operator+=(const duration& __d)
606 {
607 __r += __d.count();
608 return *this;
609 }
610
611 _GLIBCXX17_CONSTEXPR duration&
612 operator-=(const duration& __d)
613 {
614 __r -= __d.count();
615 return *this;
616 }
617
618 _GLIBCXX17_CONSTEXPR duration&
619 operator*=(const rep& __rhs)
620 {
621 __r *= __rhs;
622 return *this;
623 }
624
625 _GLIBCXX17_CONSTEXPR duration&
626 operator/=(const rep& __rhs)
627 {
628 __r /= __rhs;
629 return *this;
630 }
631
632 // DR 934.
633 template<typename _Rep2 = rep>
634 _GLIBCXX17_CONSTEXPR
636 duration&>::type
637 operator%=(const rep& __rhs)
638 {
639 __r %= __rhs;
640 return *this;
641 }
642
643 template<typename _Rep2 = rep>
644 _GLIBCXX17_CONSTEXPR
646 duration&>::type
647 operator%=(const duration& __d)
648 {
649 __r %= __d.count();
650 return *this;
651 }
652
653 // 20.11.5.4 special values
654 static constexpr duration
655 zero() noexcept
657
658 static constexpr duration
659 min() noexcept
661
662 static constexpr duration
663 max() noexcept
665
666 private:
667 rep __r;
668 };
669
670 /// @{
671 /// @relates std::chrono::duration
672
673 /// The sum of two durations.
674 template<typename _Rep1, typename _Period1,
675 typename _Rep2, typename _Period2>
676 constexpr typename common_type<duration<_Rep1, _Period1>,
679 const duration<_Rep2, _Period2>& __rhs)
680 {
681 typedef duration<_Rep1, _Period1> __dur1;
682 typedef duration<_Rep2, _Period2> __dur2;
683 typedef typename common_type<__dur1,__dur2>::type __cd;
684 return __cd(__cd(__lhs).count() + __cd(__rhs).count());
685 }
686
687 /// The difference between two durations.
688 template<typename _Rep1, typename _Period1,
689 typename _Rep2, typename _Period2>
690 constexpr typename common_type<duration<_Rep1, _Period1>,
693 const duration<_Rep2, _Period2>& __rhs)
694 {
695 typedef duration<_Rep1, _Period1> __dur1;
696 typedef duration<_Rep2, _Period2> __dur2;
697 typedef typename common_type<__dur1,__dur2>::type __cd;
698 return __cd(__cd(__lhs).count() - __cd(__rhs).count());
699 }
700
701 /// @}
702
703 /// @cond undocumented
704
705 // SFINAE helper to obtain common_type<_Rep1, _Rep2> only if _Rep2
706 // is implicitly convertible to it.
707 // _GLIBCXX_RESOLVE_LIB_DEFECTS
708 // 3050. Conversion specification problem in chrono::duration constructor
709 template<typename _Rep1, typename _Rep2,
710 typename _CRep = typename common_type<_Rep1, _Rep2>::type>
711 using __common_rep_t = typename
713
714 /// @endcond
715
716 /** @{
717 * Arithmetic operators for chrono::duration
718 * @relates std::chrono::duration
719 */
720
721 template<typename _Rep1, typename _Period, typename _Rep2>
722 constexpr duration<__common_rep_t<_Rep1, _Rep2>, _Period>
723 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
724 {
726 __cd;
727 return __cd(__cd(__d).count() * __s);
728 }
729
730 template<typename _Rep1, typename _Rep2, typename _Period>
731 constexpr duration<__common_rep_t<_Rep2, _Rep1>, _Period>
732 operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
733 { return __d * __s; }
734
735 template<typename _Rep1, typename _Period, typename _Rep2>
736 constexpr
737 duration<__common_rep_t<_Rep1, __disable_if_is_duration<_Rep2>>, _Period>
738 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
739 {
741 __cd;
742 return __cd(__cd(__d).count() / __s);
743 }
744
745 template<typename _Rep1, typename _Period1,
746 typename _Rep2, typename _Period2>
747 constexpr typename common_type<_Rep1, _Rep2>::type
749 const duration<_Rep2, _Period2>& __rhs)
750 {
751 typedef duration<_Rep1, _Period1> __dur1;
752 typedef duration<_Rep2, _Period2> __dur2;
753 typedef typename common_type<__dur1,__dur2>::type __cd;
754 return __cd(__lhs).count() / __cd(__rhs).count();
755 }
756
757 // DR 934.
758 template<typename _Rep1, typename _Period, typename _Rep2>
759 constexpr
760 duration<__common_rep_t<_Rep1, __disable_if_is_duration<_Rep2>>, _Period>
761 operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
762 {
764 __cd;
765 return __cd(__cd(__d).count() % __s);
766 }
767
768 template<typename _Rep1, typename _Period1,
769 typename _Rep2, typename _Period2>
770 constexpr typename common_type<duration<_Rep1, _Period1>,
771 duration<_Rep2, _Period2>>::type
773 const duration<_Rep2, _Period2>& __rhs)
774 {
775 typedef duration<_Rep1, _Period1> __dur1;
776 typedef duration<_Rep2, _Period2> __dur2;
777 typedef typename common_type<__dur1,__dur2>::type __cd;
778 return __cd(__cd(__lhs).count() % __cd(__rhs).count());
779 }
780 /// @}
781
782 // comparisons
783
784 /** @{
785 * Comparisons for chrono::duration
786 * @relates std::chrono::duration
787 */
788
789 template<typename _Rep1, typename _Period1,
790 typename _Rep2, typename _Period2>
791 constexpr bool
793 const duration<_Rep2, _Period2>& __rhs)
794 {
795 typedef duration<_Rep1, _Period1> __dur1;
796 typedef duration<_Rep2, _Period2> __dur2;
797 typedef typename common_type<__dur1,__dur2>::type __ct;
798 return __ct(__lhs).count() == __ct(__rhs).count();
799 }
800
801 template<typename _Rep1, typename _Period1,
802 typename _Rep2, typename _Period2>
803 constexpr bool
805 const duration<_Rep2, _Period2>& __rhs)
806 {
807 typedef duration<_Rep1, _Period1> __dur1;
808 typedef duration<_Rep2, _Period2> __dur2;
809 typedef typename common_type<__dur1,__dur2>::type __ct;
810 return __ct(__lhs).count() < __ct(__rhs).count();
811 }
812
813#if __cpp_lib_three_way_comparison
814 template<typename _Rep1, typename _Period1,
815 typename _Rep2, typename _Period2>
816 requires three_way_comparable<common_type_t<_Rep1, _Rep2>>
817 constexpr auto
818 operator<=>(const duration<_Rep1, _Period1>& __lhs,
819 const duration<_Rep2, _Period2>& __rhs)
820 {
822 duration<_Rep2, _Period2>>;
823 return __ct(__lhs).count() <=> __ct(__rhs).count();
824 }
825#else
826 template<typename _Rep1, typename _Period1,
827 typename _Rep2, typename _Period2>
828 constexpr bool
830 const duration<_Rep2, _Period2>& __rhs)
831 { return !(__lhs == __rhs); }
832#endif
833
834 template<typename _Rep1, typename _Period1,
835 typename _Rep2, typename _Period2>
836 constexpr bool
838 const duration<_Rep2, _Period2>& __rhs)
839 { return !(__rhs < __lhs); }
840
841 template<typename _Rep1, typename _Period1,
842 typename _Rep2, typename _Period2>
843 constexpr bool
845 const duration<_Rep2, _Period2>& __rhs)
846 { return __rhs < __lhs; }
847
848 template<typename _Rep1, typename _Period1,
849 typename _Rep2, typename _Period2>
850 constexpr bool
852 const duration<_Rep2, _Period2>& __rhs)
853 { return !(__lhs < __rhs); }
854
855 /// @}
856
857 /// @cond undocumented
858#ifdef _GLIBCXX_USE_C99_STDINT_TR1
859# define _GLIBCXX_CHRONO_INT64_T int64_t
860#elif defined __INT64_TYPE__
861# define _GLIBCXX_CHRONO_INT64_T __INT64_TYPE__
862#else
864 "Representation type for nanoseconds must have at least 64 bits");
865# define _GLIBCXX_CHRONO_INT64_T long long
866#endif
867 /// @endcond
868
869 /// nanoseconds
871
872 /// microseconds
874
875 /// milliseconds
877
878 /// seconds
880
881 /// minutes
883
884 /// hours
886
887#if __cplusplus > 201703L
888 /// days
890
891 /// weeks
893
894 /// years
896
897 /// months
899#endif // C++20
900
901#undef _GLIBCXX_CHRONO_INT64_T
902
903 template<typename _Clock, typename _Dur>
905 {
906 static_assert(__is_duration<_Dur>::value,
907 "duration must be a specialization of std::chrono::duration");
908
909 public:
910 typedef _Clock clock;
911 typedef _Dur duration;
912 typedef typename duration::rep rep;
913 typedef typename duration::period period;
914
915 constexpr time_point() : __d(duration::zero())
916 { }
917
918 constexpr explicit time_point(const duration& __dur)
919 : __d(__dur)
920 { }
921
922 // conversions
923 template<typename _Dur2,
924 typename = _Require<is_convertible<_Dur2, _Dur>>>
925 constexpr time_point(const time_point<clock, _Dur2>& __t)
926 : __d(__t.time_since_epoch())
927 { }
928
929 // observer
930 constexpr duration
931 time_since_epoch() const
932 { return __d; }
933
934#if __cplusplus > 201703L
935 constexpr time_point&
936 operator++()
937 {
938 ++__d;
939 return *this;
940 }
941
942 constexpr time_point
943 operator++(int)
944 { return time_point{__d++}; }
945
946 constexpr time_point&
947 operator--()
948 {
949 --__d;
950 return *this;
951 }
952
953 constexpr time_point
954 operator--(int)
955 { return time_point{__d--}; }
956#endif
957
958 // arithmetic
959 _GLIBCXX17_CONSTEXPR time_point&
960 operator+=(const duration& __dur)
961 {
962 __d += __dur;
963 return *this;
964 }
965
966 _GLIBCXX17_CONSTEXPR time_point&
967 operator-=(const duration& __dur)
968 {
969 __d -= __dur;
970 return *this;
971 }
972
973 // special values
974 static constexpr time_point
975 min() noexcept
976 { return time_point(duration::min()); }
977
978 static constexpr time_point
979 max() noexcept
980 { return time_point(duration::max()); }
981
982 private:
983 duration __d;
984 };
985
986 /** Convert a `time_point` to use `duration` type `ToDur`.
987 *
988 * The result is the same time point as measured by the same clock, but
989 * using the specified `duration` to represent the time.
990 * If the time point cannot be represented accurately in the result type,
991 * returns the result of integer truncation (i.e., rounded towards zero).
992 *
993 * @tparam _ToDur The `duration` type to use for the result.
994 * @param __t A time point.
995 * @return The value of `__t` converted to use type `_ToDur`.
996 * @since C++11
997 */
998 template<typename _ToDur, typename _Clock, typename _Dur>
999 _GLIBCXX_NODISCARD constexpr
1000 __enable_if_t<__is_duration<_ToDur>::value, time_point<_Clock, _ToDur>>
1002 {
1003 typedef time_point<_Clock, _ToDur> __time_point;
1004 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
1005 }
1006
1007#if __cplusplus > 201402L
1008 /** Convert a `time_point` to type `ToDur` and round down.
1009 *
1010 * The result is the same time point as measured by the same clock, but
1011 * using the specified `duration` to represent the time.
1012 * If the time point cannot be represented exactly in the result type,
1013 * returns the closest value that is less than the argument.
1014 *
1015 * @tparam _ToDur The `duration` type to use for the result.
1016 * @param __t A time point.
1017 * @return The value of `__d` converted to type `_ToDur`.
1018 * @since C++17
1019 */
1020 template<typename _ToDur, typename _Clock, typename _Dur>
1021 [[nodiscard]] constexpr
1022 enable_if_t<__is_duration<_ToDur>::value, time_point<_Clock, _ToDur>>
1023 floor(const time_point<_Clock, _Dur>& __tp)
1024 {
1026 chrono::floor<_ToDur>(__tp.time_since_epoch())};
1027 }
1028
1029 /** Convert a `time_point` to type `ToDur` and round up.
1030 *
1031 * The result is the same time point as measured by the same clock, but
1032 * using the specified `duration` to represent the time.
1033 * If the time point cannot be represented exactly in the result type,
1034 * returns the closest value that is greater than the argument.
1035 *
1036 * @tparam _ToDur The `duration` type to use for the result.
1037 * @param __t A time point.
1038 * @return The value of `__d` converted to type `_ToDur`.
1039 * @since C++17
1040 */
1041 template<typename _ToDur, typename _Clock, typename _Dur>
1042 [[nodiscard]] constexpr
1043 enable_if_t<__is_duration<_ToDur>::value, time_point<_Clock, _ToDur>>
1045 {
1047 chrono::ceil<_ToDur>(__tp.time_since_epoch())};
1048 }
1049
1050 /** Convert a `time_point` to type `ToDur` and round to the closest value.
1051 *
1052 * The result is the same time point as measured by the same clock, but
1053 * using the specified `duration` to represent the time.
1054 * If the time point cannot be represented exactly in the result type,
1055 * returns the closest value, rounding ties to even.
1056 *
1057 * @tparam _ToDur The `duration` type to use for the result,
1058 * which must have a non-floating-point `rep` type.
1059 * @param __t A time point.
1060 * @return The value of `__d` converted to type `_ToDur`.
1061 * @since C++17
1062 */
1063 template<typename _ToDur, typename _Clock, typename _Dur>
1064 [[nodiscard]] constexpr
1066 __and_<__is_duration<_ToDur>,
1067 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
1068 time_point<_Clock, _ToDur>>
1070 {
1072 chrono::round<_ToDur>(__tp.time_since_epoch())};
1073 }
1074#endif // C++17
1075
1076 /// @{
1077 /// @relates time_point
1078
1079 /// Adjust a time point forwards by the given duration.
1080 template<typename _Clock, typename _Dur1,
1081 typename _Rep2, typename _Period2>
1082 constexpr time_point<_Clock,
1085 const duration<_Rep2, _Period2>& __rhs)
1086 {
1087 typedef duration<_Rep2, _Period2> __dur2;
1088 typedef typename common_type<_Dur1,__dur2>::type __ct;
1089 typedef time_point<_Clock, __ct> __time_point;
1090 return __time_point(__lhs.time_since_epoch() + __rhs);
1091 }
1092
1093 /// Adjust a time point forwards by the given duration.
1094 template<typename _Rep1, typename _Period1,
1095 typename _Clock, typename _Dur2>
1096 constexpr time_point<_Clock,
1097 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
1099 const time_point<_Clock, _Dur2>& __rhs)
1100 {
1101 typedef duration<_Rep1, _Period1> __dur1;
1102 typedef typename common_type<__dur1,_Dur2>::type __ct;
1103 typedef time_point<_Clock, __ct> __time_point;
1104 return __time_point(__rhs.time_since_epoch() + __lhs);
1105 }
1106
1107 /// Adjust a time point backwards by the given duration.
1108 template<typename _Clock, typename _Dur1,
1109 typename _Rep2, typename _Period2>
1110 constexpr time_point<_Clock,
1113 const duration<_Rep2, _Period2>& __rhs)
1114 {
1115 typedef duration<_Rep2, _Period2> __dur2;
1116 typedef typename common_type<_Dur1,__dur2>::type __ct;
1117 typedef time_point<_Clock, __ct> __time_point;
1118 return __time_point(__lhs.time_since_epoch() -__rhs);
1119 }
1120
1121 /// The difference between two time points (as a duration)
1122 template<typename _Clock, typename _Dur1, typename _Dur2>
1123 constexpr typename common_type<_Dur1, _Dur2>::type
1125 const time_point<_Clock, _Dur2>& __rhs)
1126 { return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
1127 /// @}
1128
1129 /** @{
1130 * Comparisons for time_point
1131 * @relates chrono::time_point
1132 */
1133
1134 template<typename _Clock, typename _Dur1, typename _Dur2>
1135 constexpr bool
1136 operator==(const time_point<_Clock, _Dur1>& __lhs,
1137 const time_point<_Clock, _Dur2>& __rhs)
1138 { return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
1139
1140#if __cpp_lib_three_way_comparison
1141 template<typename _Clock, typename _Dur1,
1142 three_way_comparable_with<_Dur1> _Dur2>
1143 constexpr auto
1144 operator<=>(const time_point<_Clock, _Dur1>& __lhs,
1145 const time_point<_Clock, _Dur2>& __rhs)
1146 { return __lhs.time_since_epoch() <=> __rhs.time_since_epoch(); }
1147#else
1148 template<typename _Clock, typename _Dur1, typename _Dur2>
1149 constexpr bool
1150 operator!=(const time_point<_Clock, _Dur1>& __lhs,
1151 const time_point<_Clock, _Dur2>& __rhs)
1152 { return !(__lhs == __rhs); }
1153#endif
1154
1155 template<typename _Clock, typename _Dur1, typename _Dur2>
1156 constexpr bool
1157 operator<(const time_point<_Clock, _Dur1>& __lhs,
1158 const time_point<_Clock, _Dur2>& __rhs)
1159 { return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
1160
1161 template<typename _Clock, typename _Dur1, typename _Dur2>
1162 constexpr bool
1163 operator<=(const time_point<_Clock, _Dur1>& __lhs,
1164 const time_point<_Clock, _Dur2>& __rhs)
1165 { return !(__rhs < __lhs); }
1166
1167 template<typename _Clock, typename _Dur1, typename _Dur2>
1168 constexpr bool
1169 operator>(const time_point<_Clock, _Dur1>& __lhs,
1170 const time_point<_Clock, _Dur2>& __rhs)
1171 { return __rhs < __lhs; }
1172
1173 template<typename _Clock, typename _Dur1, typename _Dur2>
1174 constexpr bool
1175 operator>=(const time_point<_Clock, _Dur1>& __lhs,
1176 const time_point<_Clock, _Dur2>& __rhs)
1177 { return !(__lhs < __rhs); }
1178
1179 /// @}
1180 /// @} group chrono
1181
1182 // Clocks.
1183
1184 // Why nanosecond resolution as the default?
1185 // Why have std::system_clock always count in the highest
1186 // resolution (ie nanoseconds), even if on some OSes the low 3
1187 // or 9 decimal digits will be always zero? This allows later
1188 // implementations to change the system_clock::now()
1189 // implementation any time to provide better resolution without
1190 // changing function signature or units.
1191
1192 // To support the (forward) evolution of the library's defined
1193 // clocks, wrap inside inline namespace so that the current
1194 // defintions of system_clock, steady_clock, and
1195 // high_resolution_clock types are uniquely mangled. This way, new
1196 // code can use the latests clocks, while the library can contain
1197 // compatibility definitions for previous versions. At some
1198 // point, when these clocks settle down, the inlined namespaces
1199 // can be removed. XXX GLIBCXX_ABI Deprecated
1200_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
1201
1202 /**
1203 * @brief System clock.
1204 *
1205 * Time returned represents wall time from the system-wide clock.
1206 * @ingroup chrono
1207 */
1209 {
1211 typedef duration::rep rep;
1212 typedef duration::period period;
1214
1215 static_assert(system_clock::duration::min()
1216 < system_clock::duration::zero(),
1217 "a clock's minimum duration cannot be less than its epoch");
1218
1219 static constexpr bool is_steady = false;
1220
1221 static time_point
1222 now() noexcept;
1223
1224 // Map to C API
1225 static std::time_t
1226 to_time_t(const time_point& __t) noexcept
1227 {
1228 return std::time_t(duration_cast<chrono::seconds>
1229 (__t.time_since_epoch()).count());
1230 }
1231
1232 static time_point
1233 from_time_t(std::time_t __t) noexcept
1234 {
1236 return time_point_cast<system_clock::duration>
1237 (__from(chrono::seconds(__t)));
1238 }
1239 };
1240
1241
1242 /**
1243 * @brief Monotonic clock
1244 *
1245 * Time returned has the property of only increasing at a uniform rate.
1246 * @ingroup chrono
1247 */
1249 {
1251 typedef duration::rep rep;
1252 typedef duration::period period;
1254
1255 static constexpr bool is_steady = true;
1256
1257 static time_point
1258 now() noexcept;
1259 };
1260
1261
1262 /**
1263 * @brief Highest-resolution clock
1264 *
1265 * This is the clock "with the shortest tick period." Alias to
1266 * std::system_clock until higher-than-nanosecond definitions
1267 * become feasible.
1268 * @ingroup chrono
1269 */
1271
1272_GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
1273
1274#if __cplusplus >= 202002L
1275 /// @addtogroup chrono
1276 /// @{
1277 template<typename _Duration>
1280 using sys_days = sys_time<days>;
1281
1282 using file_clock = ::std::filesystem::__file_clock;
1283
1284 template<typename _Duration>
1286
1287 template<> struct is_clock<system_clock> : true_type { };
1288 template<> struct is_clock<steady_clock> : true_type { };
1289 template<> struct is_clock<file_clock> : true_type { };
1290
1291 template<> inline constexpr bool is_clock_v<system_clock> = true;
1292 template<> inline constexpr bool is_clock_v<steady_clock> = true;
1293 template<> inline constexpr bool is_clock_v<file_clock> = true;
1294 /// @}
1295#endif // C++20
1296 } // namespace chrono
1297
1298#if __cplusplus >= 201402L
1299#define __cpp_lib_chrono_udls 201304L
1300
1301 inline namespace literals
1302 {
1303 /** ISO C++ 2014 namespace for suffixes for duration literals.
1304 *
1305 * These suffixes can be used to create `chrono::duration` values with
1306 * tick periods of hours, minutes, seconds, milliseconds, microseconds
1307 * or nanoseconds. For example, `std::chrono::seconds(5)` can be written
1308 * as `5s` after making the suffix visible in the current scope.
1309 * The suffixes can be made visible by a using-directive or
1310 * using-declaration such as:
1311 * - `using namespace std::chrono_literals;`
1312 * - `using namespace std::literals;`
1313 * - `using namespace std::chrono;`
1314 * - `using namespace std;`
1315 * - `using std::chrono_literals::operator""s;`
1316 *
1317 * The result of these suffixes on an integer literal is one of the
1318 * standard typedefs such as `std::chrono::hours`.
1319 * The result on a floating-point literal is a duration type with the
1320 * specified tick period and an unspecified floating-point representation,
1321 * for example `1.5e2ms` might be equivalent to
1322 * `chrono::duration<long double, chrono::milli>(1.5e2)`.
1323 *
1324 * @since C+14
1325 * @ingroup chrono
1326 */
1327 inline namespace chrono_literals
1328 {
1329 /// @addtogroup chrono
1330 /// @{
1331
1332#pragma GCC diagnostic push
1333#pragma GCC diagnostic ignored "-Wliteral-suffix"
1334 /// @cond undocumented
1335 template<typename _Dur, char... _Digits>
1336 constexpr _Dur __check_overflow()
1337 {
1338 using _Val = __parse_int::_Parse_int<_Digits...>;
1339 constexpr typename _Dur::rep __repval = _Val::value;
1340 static_assert(__repval >= 0 && __repval == _Val::value,
1341 "literal value cannot be represented by duration type");
1342 return _Dur(__repval);
1343 }
1344 /// @endcond
1345
1346 /// Literal suffix for durations representing non-integer hours
1347 constexpr chrono::duration<long double, ratio<3600,1>>
1348 operator""h(long double __hours)
1350
1351 /// Literal suffix for durations of type `std::chrono::hours`
1352 template <char... _Digits>
1353 constexpr chrono::hours
1354 operator""h()
1355 { return __check_overflow<chrono::hours, _Digits...>(); }
1356
1357 /// Literal suffix for durations representing non-integer minutes
1359 operator""min(long double __mins)
1361
1362 /// Literal suffix for durations of type `std::chrono::minutes`
1363 template <char... _Digits>
1364 constexpr chrono::minutes
1365 operator""min()
1366 { return __check_overflow<chrono::minutes, _Digits...>(); }
1367
1368 /// Literal suffix for durations representing non-integer seconds
1370 operator""s(long double __secs)
1371 { return chrono::duration<long double>{__secs}; }
1372
1373 /// Literal suffix for durations of type `std::chrono::seconds`
1374 template <char... _Digits>
1375 constexpr chrono::seconds
1376 operator""s()
1377 { return __check_overflow<chrono::seconds, _Digits...>(); }
1378
1379 /// Literal suffix for durations representing non-integer milliseconds
1381 operator""ms(long double __msecs)
1382 { return chrono::duration<long double, milli>{__msecs}; }
1383
1384 /// Literal suffix for durations of type `std::chrono::milliseconds`
1385 template <char... _Digits>
1386 constexpr chrono::milliseconds
1387 operator""ms()
1388 { return __check_overflow<chrono::milliseconds, _Digits...>(); }
1389
1390 /// Literal suffix for durations representing non-integer microseconds
1392 operator""us(long double __usecs)
1393 { return chrono::duration<long double, micro>{__usecs}; }
1394
1395 /// Literal suffix for durations of type `std::chrono::microseconds`
1396 template <char... _Digits>
1397 constexpr chrono::microseconds
1398 operator""us()
1399 { return __check_overflow<chrono::microseconds, _Digits...>(); }
1400
1401 /// Literal suffix for durations representing non-integer nanoseconds
1403 operator""ns(long double __nsecs)
1404 { return chrono::duration<long double, nano>{__nsecs}; }
1405
1406 /// Literal suffix for durations of type `std::chrono::nanoseconds`
1407 template <char... _Digits>
1408 constexpr chrono::nanoseconds
1409 operator""ns()
1410 { return __check_overflow<chrono::nanoseconds, _Digits...>(); }
1411
1412#pragma GCC diagnostic pop
1413 /// @}
1414 } // inline namespace chrono_literals
1415 } // inline namespace literals
1416
1417 namespace chrono
1418 {
1419 using namespace literals::chrono_literals;
1420 } // namespace chrono
1421#endif // C++14
1422
1423#if __cplusplus >= 201703L
1424 namespace filesystem
1425 {
1426 struct __file_clock
1427 {
1428 using duration = chrono::nanoseconds;
1429 using rep = duration::rep;
1430 using period = duration::period;
1431 using time_point = chrono::time_point<__file_clock>;
1432 static constexpr bool is_steady = false;
1433
1434 static time_point
1435 now() noexcept
1436 { return _S_from_sys(chrono::system_clock::now()); }
1437
1438#if __cplusplus > 201703L
1439 template<typename _Dur>
1440 static
1441 chrono::file_time<_Dur>
1442 from_sys(const chrono::sys_time<_Dur>& __t) noexcept
1443 { return _S_from_sys(__t); }
1444
1445 // For internal use only
1446 template<typename _Dur>
1447 static
1448 chrono::sys_time<_Dur>
1449 to_sys(const chrono::file_time<_Dur>& __t) noexcept
1450 { return _S_to_sys(__t); }
1451#endif // C++20
1452
1453 private:
1454 using __sys_clock = chrono::system_clock;
1455
1456 // This clock's (unspecified) epoch is 2174-01-01 00:00:00 UTC.
1457 // A signed 64-bit duration with nanosecond resolution gives roughly
1458 // +/- 292 years, which covers the 1901-2446 date range for ext4.
1459 static constexpr chrono::seconds _S_epoch_diff{6437664000};
1460
1461 protected:
1462 // For internal use only
1463 template<typename _Dur>
1464 static
1465 chrono::time_point<__file_clock, _Dur>
1466 _S_from_sys(const chrono::time_point<__sys_clock, _Dur>& __t) noexcept
1467 {
1468 using __file_time = chrono::time_point<__file_clock, _Dur>;
1469 return __file_time{__t.time_since_epoch()} - _S_epoch_diff;
1470 }
1471
1472 // For internal use only
1473 template<typename _Dur>
1474 static
1475 chrono::time_point<__sys_clock, _Dur>
1476 _S_to_sys(const chrono::time_point<__file_clock, _Dur>& __t) noexcept
1477 {
1478 using __sys_time = chrono::time_point<__sys_clock, _Dur>;
1479 return __sys_time{__t.time_since_epoch()} + _S_epoch_diff;
1480 }
1481 };
1482 } // namespace filesystem
1483#endif // C++17
1484
1485_GLIBCXX_END_NAMESPACE_VERSION
1486} // namespace std
1487
1488#endif // C++11
1489
1490#endif //_GLIBCXX_CHRONO_H
constexpr bool operator==(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition: chrono.h:792
duration< int64_t > seconds
seconds
Definition: chrono.h:879
constexpr enable_if_t< __and_< __is_duration< _ToDur >, __not_< treat_as_floating_point< typename _ToDur::rep > > >::value, _ToDur > round(const duration< _Rep, _Period > &__d)
Definition: chrono.h:400
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition: chrono.h:837
duration< int64_t, ratio< 3600 > > hours
hours
Definition: chrono.h:885
duration< int64_t, milli > milliseconds
milliseconds
Definition: chrono.h:876
duration< int64_t, micro > microseconds
microseconds
Definition: chrono.h:873
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition: chrono.h:851
constexpr bool operator!=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition: chrono.h:829
constexpr duration< __common_rep_t< _Rep2, _Rep1 >, _Period > operator*(const _Rep1 &__s, const duration< _Rep2, _Period > &__d)
Definition: chrono.h:732
duration< int64_t, nano > nanoseconds
nanoseconds
Definition: chrono.h:870
constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator%(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
Definition: chrono.h:761
constexpr time_point< _Clock, typename common_type< _Dur1, duration< _Rep2, _Period2 > >::type > operator+(const time_point< _Clock, _Dur1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition: chrono.h:1084
constexpr __enable_if_t< __is_duration< _ToDur >::value, time_point< _Clock, _ToDur > > time_point_cast(const time_point< _Clock, _Dur > &__t)
Definition: chrono.h:1001
duration< int64_t, ratio< 60 > > minutes
minutes
Definition: chrono.h:882
constexpr time_point< _Clock, typename common_type< duration< _Rep1, _Period1 >, _Dur2 >::type > operator+(const duration< _Rep1, _Period1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs)
Adjust a time point forwards by the given duration.
Definition: chrono.h:1098
constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator+(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition: chrono.h:678
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition: chrono.h:804
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition: chrono.h:844
constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator-(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
The difference between two durations.
Definition: chrono.h:692
constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator/(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
Definition: chrono.h:738
constexpr duration< __common_rep_t< _Rep1, _Rep2 >, _Period > operator*(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
Definition: chrono.h:723
constexpr __enable_if_is_duration< _ToDur > ceil(const duration< _Rep, _Period > &__d)
Definition: chrono.h:375
constexpr __enable_if_is_duration< _ToDur > duration_cast(const duration< _Rep, _Period > &__d)
Definition: chrono.h:262
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
Definition: complex:891
typename __ratio_divide< _R1, _R2 >::type ratio_divide
ratio_divide
Definition: ratio:353
integral_constant< bool, __v > bool_constant
Alias template for compile-time boolean constant types.
Definition: type_traits:98
void void_t
A metafunction that always yields void, used for detecting valid types.
Definition: type_traits:2616
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
Definition: type_traits:82
typename common_type< _Tp... >::type common_type_t
Alias template for common_type.
Definition: type_traits:2602
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
Definition: type_traits:2594
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
Definition: stl_algobase.h:230
ISO C++ entities toplevel namespace is std.
Properties of fundamental types.
Definition: limits:313
static constexpr _Tp max() noexcept
Definition: limits:321
static constexpr _Tp lowest() noexcept
Definition: limits:327
Provides compile-time rational arithmetic.
Definition: ratio:267
integral_constant
Definition: type_traits:63
Define a member typedef type only if a boolean constant is true.
Definition: type_traits:107
is_floating_point
Definition: type_traits:503
common_type
Definition: type_traits:2232
chrono::duration represents a distance between two points in time
Definition: chrono.h:493
chrono::time_point represents a point in time as measured by a clock
Definition: chrono.h:905
duration_values
Definition: chrono.h:463
Monotonic clock.
Definition: chrono.h:1249
[concept.same], concept same_as
Definition: concepts:63