30 #ifndef _GLIBCXX_CHRONO 31 #define _GLIBCXX_CHRONO 1 33 #pragma GCC system_header 35 #if __cplusplus < 201103L 45 namespace std _GLIBCXX_VISIBILITY(default)
47 _GLIBCXX_BEGIN_NAMESPACE_VERSION
62 template<
typename _Rep,
typename _Period = ratio<1>>
65 template<
typename _Clock,
typename _Dur =
typename _Clock::duration>
73 template<
typename _CT,
typename _Period1,
typename _Period2,
typename =
void>
74 struct __duration_common_type
77 template<
typename _CT,
typename _Period1,
typename _Period2>
78 struct __duration_common_type<_CT, _Period1, _Period2,
79 __void_t<typename _CT::type>>
82 using __gcd_num = __static_gcd<_Period1::num, _Period2::num>;
83 using __gcd_den = __static_gcd<_Period1::den, _Period2::den>;
84 using __cr =
typename _CT::type;
85 using __r =
ratio<__gcd_num::value,
86 (_Period1::den / __gcd_den::value) * _Period2::den>;
92 template<
typename _Period1,
typename _Period2>
93 struct __duration_common_type<__failure_type, _Period1, _Period2>
94 {
typedef __failure_type type; };
100 template<
typename _Rep1,
typename _Period1,
typename _Rep2,
typename _Period2>
103 : __duration_common_type<common_type<_Rep1, _Rep2>, _Period1, _Period2>
110 template<
typename _CT,
typename _Clock,
typename =
void>
111 struct __timepoint_common_type
114 template<
typename _CT,
typename _Clock>
115 struct __timepoint_common_type<_CT, _Clock, __void_t<typename _CT::type>>
124 template<
typename _Clock,
typename _Duration1,
typename _Duration2>
127 : __timepoint_common_type<common_type<_Duration1, _Duration2>, _Clock>
140 template<
typename _ToDur,
typename _CF,
typename _CR,
141 bool _NumIsOne =
false,
bool _DenIsOne =
false>
142 struct __duration_cast_impl
144 template<
typename _Rep,
typename _Period>
145 static constexpr _ToDur
146 __cast(
const duration<_Rep, _Period>& __d)
148 typedef typename _ToDur::rep __to_rep;
149 return _ToDur(static_cast<__to_rep>(static_cast<_CR>(__d.count())
150 * static_cast<_CR>(_CF::num)
151 /
static_cast<_CR
>(_CF::den)));
155 template<
typename _ToDur,
typename _CF,
typename _CR>
156 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
158 template<
typename _Rep,
typename _Period>
159 static constexpr _ToDur
160 __cast(
const duration<_Rep, _Period>& __d)
162 typedef typename _ToDur::rep __to_rep;
163 return _ToDur(static_cast<__to_rep>(__d.count()));
167 template<
typename _ToDur,
typename _CF,
typename _CR>
168 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
170 template<
typename _Rep,
typename _Period>
171 static constexpr _ToDur
172 __cast(
const duration<_Rep, _Period>& __d)
174 typedef typename _ToDur::rep __to_rep;
175 return _ToDur(static_cast<__to_rep>(
176 static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den)));
180 template<
typename _ToDur,
typename _CF,
typename _CR>
181 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
183 template<
typename _Rep,
typename _Period>
184 static constexpr _ToDur
185 __cast(
const duration<_Rep, _Period>& __d)
187 typedef typename _ToDur::rep __to_rep;
188 return _ToDur(static_cast<__to_rep>(
189 static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num)));
193 template<
typename _Tp>
198 template<
typename _Rep,
typename _Period>
199 struct __is_duration<duration<_Rep, _Period>>
203 template<
typename _Tp>
204 using __enable_if_is_duration
207 template<
typename _Tp>
208 using __disable_if_is_duration
214 template<
typename _ToDur,
typename _Rep,
typename _Period>
215 constexpr __enable_if_is_duration<_ToDur>
218 typedef typename _ToDur::period __to_period;
219 typedef typename _ToDur::rep __to_rep;
223 typedef __duration_cast_impl<_ToDur, __cf, __cr,
224 __cf::num == 1, __cf::den == 1> __dc;
225 return __dc::__cast(__d);
229 template<
typename _Rep>
234 #if __cplusplus > 201402L 235 template <
typename _Rep>
236 inline constexpr
bool treat_as_floating_point_v =
240 #if __cplusplus >= 201703L 241 # define __cpp_lib_chrono 201611 243 template<
typename _ToDur,
typename _Rep,
typename _Period>
244 constexpr __enable_if_is_duration<_ToDur>
249 return __to - _ToDur{1};
253 template<
typename _ToDur,
typename _Rep,
typename _Period>
254 constexpr __enable_if_is_duration<_ToDur>
259 return __to + _ToDur{1};
263 template <
typename _ToDur,
typename _Rep,
typename _Period>
265 __and_<__is_duration<_ToDur>,
266 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
270 _ToDur __t0 = chrono::floor<_ToDur>(__d);
271 _ToDur __t1 = __t0 + _ToDur{1};
272 auto __diff0 = __d - __t0;
273 auto __diff1 = __t1 - __d;
274 if (__diff0 == __diff1)
276 if (__t0.count() & 1)
280 else if (__diff0 < __diff1)
285 template<
typename _Rep,
typename _Period>
290 if (__d >= __d.zero())
297 template<
typename _Rep>
300 static constexpr _Rep
304 static constexpr _Rep
308 static constexpr _Rep
315 template<
typename _Tp>
320 template<
intmax_t _Num,
intmax_t _Den>
321 struct __is_ratio<ratio<_Num, _Den>>
328 template<
typename _Rep,
typename _Period>
332 template<
typename _Rep2>
336 template<
typename _Period2>
343 typedef _Period period;
345 static_assert(!__is_duration<_Rep>::value,
"rep cannot be a duration");
346 static_assert(__is_ratio<_Period>::value,
347 "period must be a specialization of ratio");
348 static_assert(_Period::num > 0,
"period must be positive");
351 constexpr duration() =
default;
353 duration(
const duration&) =
default;
357 template<
typename _Rep2,
typename = _Require<
359 __or_<__is_float<rep>, __not_<__is_float<_Rep2>>>>>
360 constexpr
explicit duration(
const _Rep2& __rep)
361 : __r(static_cast<rep>(__rep)) { }
363 template<
typename _Rep2,
typename _Period2,
typename = _Require<
364 __or_<__is_float<rep>,
365 __and_<__is_harmonic<_Period2>,
366 __not_<__is_float<_Rep2>>>>>>
368 : __r(duration_cast<duration>(__d).count()) { }
370 ~duration() =
default;
371 duration& operator=(
const duration&) =
default;
385 {
return duration(-__r); }
387 _GLIBCXX17_CONSTEXPR duration&
394 _GLIBCXX17_CONSTEXPR duration
396 {
return duration(__r++); }
398 _GLIBCXX17_CONSTEXPR duration&
405 _GLIBCXX17_CONSTEXPR duration
407 {
return duration(__r--); }
409 _GLIBCXX17_CONSTEXPR duration&
410 operator+=(
const duration& __d)
416 _GLIBCXX17_CONSTEXPR duration&
417 operator-=(
const duration& __d)
423 _GLIBCXX17_CONSTEXPR duration&
424 operator*=(
const rep& __rhs)
430 _GLIBCXX17_CONSTEXPR duration&
431 operator/=(
const rep& __rhs)
438 template<
typename _Rep2 = rep>
442 operator%=(
const rep& __rhs)
448 template<
typename _Rep2 = rep>
450 typename enable_if<!treat_as_floating_point<_Rep2>::value,
452 operator%=(
const duration& __d)
459 static constexpr duration
463 static constexpr duration
467 static constexpr duration
478 template<
typename _Rep1,
typename _Period1,
479 typename _Rep2,
typename _Period2>
488 return __cd(__cd(__lhs).count() + __cd(__rhs).count());
492 template<
typename _Rep1,
typename _Period1,
493 typename _Rep2,
typename _Period2>
494 constexpr
typename common_type<duration<_Rep1, _Period1>,
502 return __cd(__cd(__lhs).count() - __cd(__rhs).count());
513 template<
typename _Rep1,
typename _Rep2,
515 using __common_rep_t =
typename 523 template<
typename _Rep1,
typename _Period,
typename _Rep2>
529 return __cd(__cd(__d).count() * __s);
533 template<
typename _Rep1,
typename _Rep2,
typename _Period>
536 {
return __d * __s; }
538 template<
typename _Rep1,
typename _Period,
typename _Rep2>
545 return __cd(__cd(__d).count() / __s);
548 template<
typename _Rep1,
typename _Period1,
549 typename _Rep2,
typename _Period2>
557 return __cd(__lhs).count() / __cd(__rhs).count();
561 template<
typename _Rep1,
typename _Period,
typename _Rep2>
563 duration<__common_rep_t<_Rep1, __disable_if_is_duration<_Rep2>>, _Period>
568 return __cd(__cd(__d).count() % __s);
571 template<
typename _Rep1,
typename _Period1,
572 typename _Rep2,
typename _Period2>
573 constexpr
typename common_type<duration<_Rep1, _Period1>,
581 return __cd(__cd(__lhs).count() % __cd(__rhs).count());
586 template<
typename _Rep1,
typename _Period1,
587 typename _Rep2,
typename _Period2>
595 return __ct(__lhs).count() == __ct(__rhs).count();
598 template<
typename _Rep1,
typename _Period1,
599 typename _Rep2,
typename _Period2>
601 operator<(const duration<_Rep1, _Period1>& __lhs,
607 return __ct(__lhs).count() < __ct(__rhs).count();
610 template<
typename _Rep1,
typename _Period1,
611 typename _Rep2,
typename _Period2>
615 {
return !(__lhs == __rhs); }
617 template<
typename _Rep1,
typename _Period1,
618 typename _Rep2,
typename _Period2>
620 operator<=(const duration<_Rep1, _Period1>& __lhs,
622 {
return !(__rhs < __lhs); }
624 template<
typename _Rep1,
typename _Period1,
625 typename _Rep2,
typename _Period2>
629 {
return __rhs < __lhs; }
631 template<
typename _Rep1,
typename _Period1,
632 typename _Rep2,
typename _Period2>
636 {
return !(__lhs < __rhs); }
640 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 641 # define _GLIBCXX_CHRONO_INT64_T int64_t 642 #elif defined __INT64_TYPE__ 643 # define _GLIBCXX_CHRONO_INT64_T __INT64_TYPE__ 646 "Representation type for nanoseconds must have at least 64 bits");
647 # define _GLIBCXX_CHRONO_INT64_T long long 668 #undef _GLIBCXX_CHRONO_INT64_T 671 template<
typename _Clock,
typename _Dur>
674 typedef _Clock clock;
675 typedef _Dur duration;
676 typedef typename duration::rep rep;
677 typedef typename duration::period period;
679 constexpr
time_point() : __d(duration::zero())
682 constexpr
explicit time_point(
const duration& __dur)
687 template<
typename _Dur2,
688 typename = _Require<is_convertible<_Dur2, _Dur>>>
690 : __d(__t.time_since_epoch())
695 time_since_epoch()
const 699 _GLIBCXX17_CONSTEXPR time_point&
700 operator+=(
const duration& __dur)
706 _GLIBCXX17_CONSTEXPR time_point&
707 operator-=(
const duration& __dur)
714 static constexpr time_point
716 {
return time_point(duration::min()); }
718 static constexpr time_point
720 {
return time_point(duration::max()); }
727 template<
typename _ToDur,
typename _Clock,
typename _Dur>
733 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
736 #if __cplusplus > 201402L 737 template<
typename _ToDur,
typename _Clock,
typename _Dur>
743 chrono::floor<_ToDur>(__tp.time_since_epoch())};
746 template<
typename _ToDur,
typename _Clock,
typename _Dur>
752 chrono::ceil<_ToDur>(__tp.time_since_epoch())};
755 template<
typename _ToDur,
typename _Clock,
typename _Dur>
757 __and_<__is_duration<_ToDur>,
758 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
763 chrono::round<_ToDur>(__tp.time_since_epoch())};
770 template<
typename _Clock,
typename _Dur1,
771 typename _Rep2,
typename _Period2>
775 const duration<_Rep2, _Period2>& __rhs)
777 typedef duration<_Rep2, _Period2> __dur2;
780 return __time_point(__lhs.time_since_epoch() + __rhs);
784 template<
typename _Rep1,
typename _Period1,
785 typename _Clock,
typename _Dur2>
787 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
791 typedef duration<_Rep1, _Period1> __dur1;
794 return __time_point(__rhs.time_since_epoch() + __lhs);
798 template<
typename _Clock,
typename _Dur1,
799 typename _Rep2,
typename _Period2>
803 const duration<_Rep2, _Period2>& __rhs)
805 typedef duration<_Rep2, _Period2> __dur2;
808 return __time_point(__lhs.time_since_epoch() -__rhs);
816 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
820 {
return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
822 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
826 {
return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
828 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
832 {
return !(__lhs == __rhs); }
834 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
836 operator<(const time_point<_Clock, _Dur1>& __lhs,
838 {
return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
840 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
842 operator<=(const time_point<_Clock, _Dur1>& __lhs,
844 {
return !(__rhs < __lhs); }
846 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
850 {
return __rhs < __lhs; }
852 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
856 {
return !(__lhs < __rhs); }
878 inline namespace _V2 {
889 typedef duration::rep rep;
890 typedef duration::period period;
894 < system_clock::duration::zero(),
895 "a clock's minimum duration cannot be less than its epoch");
897 static constexpr
bool is_steady =
false;
904 to_time_t(
const time_point& __t) noexcept
906 return std::time_t(duration_cast<chrono::seconds>
907 (__t.time_since_epoch()).count());
911 from_time_t(std::time_t __t) noexcept
929 typedef duration::rep rep;
930 typedef duration::period period;
933 static constexpr
bool is_steady =
true;
954 #if __cplusplus > 201103L 956 #define __cpp_lib_chrono_udls 201304 958 inline namespace literals
983 inline namespace chrono_literals
985 #pragma GCC diagnostic push 986 #pragma GCC diagnostic ignored "-Wliteral-suffix" 988 template<
typename _Dur,
char... _Digits>
989 constexpr _Dur __check_overflow()
991 using _Val = __parse_int::_Parse_int<_Digits...>;
992 constexpr
typename _Dur::rep __repval = _Val::value;
993 static_assert(__repval >= 0 && __repval == _Val::value,
994 "literal value cannot be represented by duration type");
995 return _Dur(__repval);
1001 operator""h(
long double __hours)
1005 template <
char... _Digits>
1012 operator""min(
long double __mins)
1016 template <
char... _Digits>
1023 operator""s(
long double __secs)
1027 template <
char... _Digits>
1034 operator""ms(
long double __msecs)
1038 template <
char... _Digits>
1045 operator""us(
long double __usecs)
1049 template <
char... _Digits>
1056 operator""ns(
long double __nsecs)
1060 template <
char... _Digits>
1065 #pragma GCC diagnostic pop 1071 using namespace literals::chrono_literals;
1076 _GLIBCXX_END_NAMESPACE_VERSION
1081 #endif //_GLIBCXX_CHRONO
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
constexpr duration< __common_rep_t< _Rep2, _Rep1 >, _Period > operator*(const _Rep1 &__s, const duration< _Rep2, _Period > &__d)
Multiply a duration by a scalar value.
constexpr enable_if< __is_duration< _ToDur >::value, time_point< _Clock, _ToDur > >::type time_point_cast(const time_point< _Clock, _Dur > &__t)
time_point_cast
static constexpr _Tp lowest() noexcept
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
duration< int64_t, milli > milliseconds
milliseconds
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.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
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.
constexpr common_type< _Dur1, _Dur2 >::type operator-(const time_point< _Clock, _Dur1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs)
The difference between two time points (as a duration)
Properties of fundamental types.
Provides compile-time rational arithmetic.
duration< int64_t, nano > nanoseconds
nanoseconds
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
static constexpr _Tp max() noexcept
typename __ratio_divide< _R1, _R2 >::type ratio_divide
ratio_divide
constexpr time_point< _Clock, typename common_type< _Dur1, duration< _Rep2, _Period2 > >::type > operator+(const time_point< _Clock, _Dur1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Adjust a time point forwards by the given duration.
constexpr duration< __common_rep_t< _Rep1, _Rep2 >, _Period > operator*(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
Multiply a duration by a scalar value.
duration< int64_t, ratio< 3600 > > hours
hours
ISO C++ entities toplevel namespace is std.
constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator+(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
The sum of two durations.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
constexpr complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
constexpr __enable_if_is_duration< _ToDur > duration_cast(const duration< _Rep, _Period > &__d)
duration_cast
duration< int64_t, micro > microseconds
microseconds
duration< int64_t, ratio< 60 > > minutes
minutes
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
Define a member typedef type only if a boolean constant is true.
duration< int64_t > seconds
seconds
constexpr time_point< _Clock, typename common_type< _Dur1, duration< _Rep2, _Period2 > >::type > operator-(const time_point< _Clock, _Dur1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Adjust a time point backwards by the given duration.