29 #ifndef _GLIBCXX_CHRONO 30 #define _GLIBCXX_CHRONO 1 32 #pragma GCC system_header 34 #if __cplusplus < 201103L 44 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 46 namespace std _GLIBCXX_VISIBILITY(default)
48 _GLIBCXX_BEGIN_NAMESPACE_VERSION
63 template<
typename _Rep,
typename _Period = ratio<1>>
66 template<
typename _Clock,
typename _Dur =
typename _Clock::duration>
72 template<
typename _CT,
typename _Period1,
typename _Period2>
73 struct __duration_common_type_wrapper
76 typedef __static_gcd<_Period1::num, _Period2::num> __gcd_num;
77 typedef __static_gcd<_Period1::den, _Period2::den> __gcd_den;
78 typedef typename _CT::type __cr;
79 typedef ratio<__gcd_num::value,
80 (_Period1::den / __gcd_den::value) * _Period2::den> __r;
82 typedef __success_type<chrono::duration<__cr, __r>> type;
85 template<
typename _Period1,
typename _Period2>
86 struct __duration_common_type_wrapper<__failure_type, _Period1, _Period2>
87 {
typedef __failure_type type; };
89 template<
typename _Rep1,
typename _Period1,
typename _Rep2,
typename _Period2>
90 struct common_type<chrono::duration<_Rep1, _Period1>,
92 :
public __duration_common_type_wrapper<typename __member_type_wrapper<
93 common_type<_Rep1, _Rep2>>::type, _Period1, _Period2>::type
98 template<
typename _CT,
typename _Clock>
99 struct __timepoint_common_type_wrapper
101 typedef __success_type<chrono::time_point<_Clock, typename _CT::type>>
105 template<
typename _Clock>
106 struct __timepoint_common_type_wrapper<__failure_type, _Clock>
107 {
typedef __failure_type type; };
109 template<
typename _Clock,
typename _Duration1,
typename _Duration2>
112 :
public __timepoint_common_type_wrapper<typename __member_type_wrapper<
113 common_type<_Duration1, _Duration2>>::type, _Clock>::type
119 template<
typename _ToDur,
typename _CF,
typename _CR,
120 bool _NumIsOne =
false,
bool _DenIsOne =
false>
121 struct __duration_cast_impl
123 template<
typename _Rep,
typename _Period>
124 static constexpr _ToDur
125 __cast(
const duration<_Rep, _Period>& __d)
127 typedef typename _ToDur::rep __to_rep;
128 return _ToDur(static_cast<__to_rep>(static_cast<_CR>(__d.count())
129 * static_cast<_CR>(_CF::num)
130 /
static_cast<_CR
>(_CF::den)));
134 template<
typename _ToDur,
typename _CF,
typename _CR>
135 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
137 template<
typename _Rep,
typename _Period>
138 static constexpr _ToDur
139 __cast(
const duration<_Rep, _Period>& __d)
141 typedef typename _ToDur::rep __to_rep;
142 return _ToDur(static_cast<__to_rep>(__d.count()));
146 template<
typename _ToDur,
typename _CF,
typename _CR>
147 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
149 template<
typename _Rep,
typename _Period>
150 static constexpr _ToDur
151 __cast(
const duration<_Rep, _Period>& __d)
153 typedef typename _ToDur::rep __to_rep;
154 return _ToDur(static_cast<__to_rep>(
155 static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den)));
159 template<
typename _ToDur,
typename _CF,
typename _CR>
160 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
162 template<
typename _Rep,
typename _Period>
163 static constexpr _ToDur
164 __cast(
const duration<_Rep, _Period>& __d)
166 typedef typename _ToDur::rep __to_rep;
167 return _ToDur(static_cast<__to_rep>(
168 static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num)));
172 template<
typename _Tp>
177 template<
typename _Rep,
typename _Period>
178 struct __is_duration<duration<_Rep, _Period>>
182 template<
typename _Tp>
183 using __enable_if_is_duration
186 template<
typename _Tp>
187 using __disable_if_is_duration
191 template<
typename _ToDur,
typename _Rep,
typename _Period>
192 constexpr __enable_if_is_duration<_ToDur>
195 typedef typename _ToDur::period __to_period;
196 typedef typename _ToDur::rep __to_rep;
200 typedef __duration_cast_impl<_ToDur, __cf, __cr,
201 __cf::num == 1, __cf::den == 1> __dc;
202 return __dc::__cast(__d);
206 template<
typename _Rep>
211 #if __cplusplus > 201402L 212 template <
typename _Rep>
213 inline constexpr
bool treat_as_floating_point_v =
217 #if __cplusplus >= 201703L 218 # define __cpp_lib_chrono 201611 220 template<
typename _ToDur,
typename _Rep,
typename _Period>
221 constexpr __enable_if_is_duration<_ToDur>
226 return __to - _ToDur{1};
230 template<
typename _ToDur,
typename _Rep,
typename _Period>
231 constexpr __enable_if_is_duration<_ToDur>
236 return __to + _ToDur{1};
240 template <
typename _ToDur,
typename _Rep,
typename _Period>
242 __and_<__is_duration<_ToDur>,
243 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
247 _ToDur __t0 = chrono::floor<_ToDur>(__d);
248 _ToDur __t1 = __t0 + _ToDur{1};
249 auto __diff0 = __d - __t0;
250 auto __diff1 = __t1 - __d;
251 if (__diff0 == __diff1)
253 if (__t0.count() & 1)
257 else if (__diff0 < __diff1)
262 template<
typename _Rep,
typename _Period>
267 if (__d >= __d.zero())
274 template<
typename _Rep>
277 static constexpr _Rep
281 static constexpr _Rep
285 static constexpr _Rep
290 template<
typename _Tp>
295 template<
intmax_t _Num,
intmax_t _Den>
296 struct __is_ratio<ratio<_Num, _Den>>
301 template<
typename _Rep,
typename _Period>
305 template<
typename _Rep2>
309 template<
typename _Period2>
316 typedef _Period period;
318 static_assert(!__is_duration<_Rep>::value,
"rep cannot be a duration");
319 static_assert(__is_ratio<_Period>::value,
320 "period must be a specialization of ratio");
321 static_assert(_Period::num > 0,
"period must be positive");
330 template<
typename _Rep2,
typename = _Require<
332 __or_<__is_float<rep>, __not_<__is_float<_Rep2>>>>>
333 constexpr
explicit duration(
const _Rep2& __rep)
334 : __r(static_cast<rep>(__rep)) { }
336 template<
typename _Rep2,
typename _Period2,
typename = _Require<
337 __or_<__is_float<rep>,
338 __and_<__is_harmonic<_Period2>,
339 __not_<__is_float<_Rep2>>>>>>
341 : __r(duration_cast<duration>(__d).count()) { }
343 ~duration() =
default;
344 duration& operator=(
const duration&) =
default;
358 {
return duration(-__r); }
360 _GLIBCXX17_CONSTEXPR duration&
367 _GLIBCXX17_CONSTEXPR duration
369 {
return duration(__r++); }
371 _GLIBCXX17_CONSTEXPR duration&
378 _GLIBCXX17_CONSTEXPR duration
380 {
return duration(__r--); }
382 _GLIBCXX17_CONSTEXPR duration&
383 operator+=(
const duration& __d)
389 _GLIBCXX17_CONSTEXPR duration&
390 operator-=(
const duration& __d)
396 _GLIBCXX17_CONSTEXPR duration&
397 operator*=(
const rep& __rhs)
403 _GLIBCXX17_CONSTEXPR duration&
404 operator/=(
const rep& __rhs)
411 template<
typename _Rep2 = rep>
415 operator%=(
const rep& __rhs)
421 template<
typename _Rep2 = rep>
423 typename enable_if<!treat_as_floating_point<_Rep2>::value,
425 operator%=(
const duration& __d)
432 static constexpr duration
436 static constexpr duration
440 static constexpr duration
448 template<
typename _Rep1,
typename _Period1,
449 typename _Rep2,
typename _Period2>
458 return __cd(__cd(__lhs).count() + __cd(__rhs).count());
461 template<
typename _Rep1,
typename _Period1,
462 typename _Rep2,
typename _Period2>
463 constexpr
typename common_type<duration<_Rep1, _Period1>,
471 return __cd(__cd(__lhs).count() - __cd(__rhs).count());
478 template<
typename _Rep1,
typename _Rep2,
480 using __common_rep_t =
typename 483 template<
typename _Rep1,
typename _Period,
typename _Rep2>
489 return __cd(__cd(__d).count() * __s);
492 template<
typename _Rep1,
typename _Rep2,
typename _Period>
495 {
return __d * __s; }
497 template<
typename _Rep1,
typename _Period,
typename _Rep2>
504 return __cd(__cd(__d).count() / __s);
507 template<
typename _Rep1,
typename _Period1,
508 typename _Rep2,
typename _Period2>
516 return __cd(__lhs).count() / __cd(__rhs).count();
520 template<
typename _Rep1,
typename _Period,
typename _Rep2>
522 duration<__common_rep_t<_Rep1, __disable_if_is_duration<_Rep2>>, _Period>
527 return __cd(__cd(__d).count() % __s);
530 template<
typename _Rep1,
typename _Period1,
531 typename _Rep2,
typename _Period2>
532 constexpr
typename common_type<duration<_Rep1, _Period1>,
540 return __cd(__cd(__lhs).count() % __cd(__rhs).count());
544 template<
typename _Rep1,
typename _Period1,
545 typename _Rep2,
typename _Period2>
553 return __ct(__lhs).count() == __ct(__rhs).count();
556 template<
typename _Rep1,
typename _Period1,
557 typename _Rep2,
typename _Period2>
559 operator<(const duration<_Rep1, _Period1>& __lhs,
565 return __ct(__lhs).count() < __ct(__rhs).count();
568 template<
typename _Rep1,
typename _Period1,
569 typename _Rep2,
typename _Period2>
573 {
return !(__lhs == __rhs); }
575 template<
typename _Rep1,
typename _Period1,
576 typename _Rep2,
typename _Period2>
578 operator<=(const duration<_Rep1, _Period1>& __lhs,
580 {
return !(__rhs < __lhs); }
582 template<
typename _Rep1,
typename _Period1,
583 typename _Rep2,
typename _Period2>
587 {
return __rhs < __lhs; }
589 template<
typename _Rep1,
typename _Period1,
590 typename _Rep2,
typename _Period2>
594 {
return !(__lhs < __rhs); }
615 template<
typename _Clock,
typename _Dur>
618 typedef _Clock clock;
620 typedef typename duration::rep rep;
621 typedef typename duration::period period;
623 constexpr
time_point() : __d(duration::zero())
626 constexpr
explicit time_point(
const duration& __dur)
631 template<
typename _Dur2,
632 typename = _Require<is_convertible<_Dur2, _Dur>>>
634 : __d(__t.time_since_epoch())
639 time_since_epoch()
const 643 _GLIBCXX17_CONSTEXPR time_point&
644 operator+=(
const duration& __dur)
650 _GLIBCXX17_CONSTEXPR time_point&
651 operator-=(
const duration& __dur)
658 static constexpr time_point
660 {
return time_point(duration::min()); }
662 static constexpr time_point
664 {
return time_point(duration::max()); }
671 template<
typename _ToDur,
typename _Clock,
typename _Dur>
677 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
680 #if __cplusplus > 201402L 681 template<
typename _ToDur,
typename _Clock,
typename _Dur>
687 chrono::floor<_ToDur>(__tp.time_since_epoch())};
690 template<
typename _ToDur,
typename _Clock,
typename _Dur>
696 chrono::ceil<_ToDur>(__tp.time_since_epoch())};
699 template<
typename _ToDur,
typename _Clock,
typename _Dur>
701 __and_<__is_duration<_ToDur>,
702 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
707 chrono::round<_ToDur>(__tp.time_since_epoch())};
711 template<
typename _Clock,
typename _Dur1,
712 typename _Rep2,
typename _Period2>
721 return __time_point(__lhs.time_since_epoch() + __rhs);
724 template<
typename _Rep1,
typename _Period1,
725 typename _Clock,
typename _Dur2>
727 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
734 return __time_point(__rhs.time_since_epoch() + __lhs);
737 template<
typename _Clock,
typename _Dur1,
738 typename _Rep2,
typename _Period2>
747 return __time_point(__lhs.time_since_epoch() -__rhs);
750 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
754 {
return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
756 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
760 {
return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
762 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
766 {
return !(__lhs == __rhs); }
768 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
770 operator<(const time_point<_Clock, _Dur1>& __lhs,
772 {
return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
774 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
776 operator<=(const time_point<_Clock, _Dur1>& __lhs,
778 {
return !(__rhs < __lhs); }
780 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
784 {
return __rhs < __lhs; }
786 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
790 {
return !(__lhs < __rhs); }
811 inline namespace _V2 {
821 typedef duration::rep rep;
822 typedef duration::period period;
826 < system_clock::duration::zero(),
827 "a clock's minimum duration cannot be less than its epoch");
829 static constexpr
bool is_steady =
false;
836 to_time_t(
const time_point& __t) noexcept
838 return std::time_t(duration_cast<chrono::seconds>
839 (__t.time_since_epoch()).count());
843 from_time_t(std::time_t __t) noexcept
860 typedef duration::rep rep;
861 typedef duration::period period;
864 static constexpr
bool is_steady =
true;
883 #if __cplusplus > 201103L 885 #define __cpp_lib_chrono_udls 201304 887 inline namespace literals
889 inline namespace chrono_literals
891 #pragma GCC diagnostic push 892 #pragma GCC diagnostic ignored "-Wliteral-suffix" 893 template<
typename _Rep,
unsigned long long _Val>
894 struct _Checked_integral_constant
897 static_assert(_Checked_integral_constant::value >= 0
898 && _Checked_integral_constant::value == _Val,
899 "literal value cannot be represented by duration type");
902 template<
typename _Dur,
char... _Digits>
903 constexpr _Dur __check_overflow()
905 using _Val = __parse_int::_Parse_int<_Digits...>;
906 using _Rep =
typename _Dur::rep;
909 using _CheckedVal = _Checked_integral_constant<_Rep, _Val::value>;
910 return _Dur{_CheckedVal::value};
914 operator""h(
long double __hours)
917 template <
char... _Digits>
923 operator""min(
long double __mins)
926 template <
char... _Digits>
932 operator""s(
long double __secs)
935 template <
char... _Digits>
941 operator""ms(
long double __msecs)
944 template <
char... _Digits>
950 operator""us(
long double __usecs)
953 template <
char... _Digits>
959 operator""ns(
long double __nsecs)
962 template <
char... _Digits>
967 #pragma GCC diagnostic pop 973 using namespace literals::chrono_literals;
980 _GLIBCXX_END_NAMESPACE_VERSION
983 #endif //_GLIBCXX_USE_C99_STDINT_TR1 987 #endif //_GLIBCXX_CHRONO constexpr enable_if< __is_duration< _ToDur >::value, time_point< _Clock, _ToDur > >::type time_point_cast(const time_point< _Clock, _Dur > &__t)
time_point_cast
duration< int64_t, ratio< 60 > > minutes
minutes
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
duration< int64_t, micro > microseconds
microseconds
duration< int64_t, milli > milliseconds
milliseconds
duration< int64_t, nano > nanoseconds
nanoseconds
static constexpr _Tp lowest() noexcept
ISO C++ entities toplevel namespace is std.
constexpr __enable_if_is_duration< _ToDur > duration_cast(const duration< _Rep, _Period > &__d)
duration_cast
Define a member typedef type only if a boolean constant is true.
static constexpr _Tp max() noexcept
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
Provides compile-time rational arithmetic.
duration< int64_t, ratio< 3600 > > hours
hours
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
typename __ratio_divide< _R1, _R2 >::type ratio_divide
ratio_divide
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
duration< int64_t > seconds
seconds