29 #ifndef _GLIBCXX_CHRONO 30 #define _GLIBCXX_CHRONO 1 32 #pragma GCC system_header 34 #if __cplusplus < 201103L 44 namespace std _GLIBCXX_VISIBILITY(default)
46 _GLIBCXX_BEGIN_NAMESPACE_VERSION
61 template<
typename _Rep,
typename _Period = ratio<1>>
64 template<
typename _Clock,
typename _Dur =
typename _Clock::duration>
70 template<
typename _CT,
typename _Period1,
typename _Period2>
71 struct __duration_common_type_wrapper
74 typedef __static_gcd<_Period1::num, _Period2::num> __gcd_num;
75 typedef __static_gcd<_Period1::den, _Period2::den> __gcd_den;
76 typedef typename _CT::type __cr;
77 typedef ratio<__gcd_num::value,
78 (_Period1::den / __gcd_den::value) * _Period2::den> __r;
80 typedef __success_type<chrono::duration<__cr, __r>> type;
83 template<
typename _Period1,
typename _Period2>
84 struct __duration_common_type_wrapper<__failure_type, _Period1, _Period2>
85 {
typedef __failure_type type; };
87 template<
typename _Rep1,
typename _Period1,
typename _Rep2,
typename _Period2>
88 struct common_type<chrono::duration<_Rep1, _Period1>,
90 :
public __duration_common_type_wrapper<typename __member_type_wrapper<
91 common_type<_Rep1, _Rep2>>::type, _Period1, _Period2>::type
96 template<
typename _CT,
typename _Clock>
97 struct __timepoint_common_type_wrapper
99 typedef __success_type<chrono::time_point<_Clock, typename _CT::type>>
103 template<
typename _Clock>
104 struct __timepoint_common_type_wrapper<__failure_type, _Clock>
105 {
typedef __failure_type type; };
107 template<
typename _Clock,
typename _Duration1,
typename _Duration2>
110 :
public __timepoint_common_type_wrapper<typename __member_type_wrapper<
111 common_type<_Duration1, _Duration2>>::type, _Clock>::type
117 template<
typename _ToDur,
typename _CF,
typename _CR,
118 bool _NumIsOne =
false,
bool _DenIsOne =
false>
119 struct __duration_cast_impl
121 template<
typename _Rep,
typename _Period>
122 static constexpr _ToDur
123 __cast(
const duration<_Rep, _Period>& __d)
125 typedef typename _ToDur::rep __to_rep;
126 return _ToDur(static_cast<__to_rep>(static_cast<_CR>(__d.count())
127 * static_cast<_CR>(_CF::num)
128 /
static_cast<_CR
>(_CF::den)));
132 template<
typename _ToDur,
typename _CF,
typename _CR>
133 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
135 template<
typename _Rep,
typename _Period>
136 static constexpr _ToDur
137 __cast(
const duration<_Rep, _Period>& __d)
139 typedef typename _ToDur::rep __to_rep;
140 return _ToDur(static_cast<__to_rep>(__d.count()));
144 template<
typename _ToDur,
typename _CF,
typename _CR>
145 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
147 template<
typename _Rep,
typename _Period>
148 static constexpr _ToDur
149 __cast(
const duration<_Rep, _Period>& __d)
151 typedef typename _ToDur::rep __to_rep;
152 return _ToDur(static_cast<__to_rep>(
153 static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den)));
157 template<
typename _ToDur,
typename _CF,
typename _CR>
158 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
160 template<
typename _Rep,
typename _Period>
161 static constexpr _ToDur
162 __cast(
const duration<_Rep, _Period>& __d)
164 typedef typename _ToDur::rep __to_rep;
165 return _ToDur(static_cast<__to_rep>(
166 static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num)));
170 template<
typename _Tp>
175 template<
typename _Rep,
typename _Period>
176 struct __is_duration<duration<_Rep, _Period>>
180 template<
typename _Tp>
181 using __enable_if_is_duration
184 template<
typename _Tp>
185 using __disable_if_is_duration
189 template<
typename _ToDur,
typename _Rep,
typename _Period>
190 constexpr __enable_if_is_duration<_ToDur>
193 typedef typename _ToDur::period __to_period;
194 typedef typename _ToDur::rep __to_rep;
198 typedef __duration_cast_impl<_ToDur, __cf, __cr,
199 __cf::num == 1, __cf::den == 1> __dc;
200 return __dc::__cast(__d);
204 template<
typename _Rep>
209 #if __cplusplus > 201402L 210 template <
typename _Rep>
211 inline constexpr
bool treat_as_floating_point_v =
215 #if __cplusplus >= 201703L 216 # define __cpp_lib_chrono 201611 218 template<
typename _ToDur,
typename _Rep,
typename _Period>
219 constexpr __enable_if_is_duration<_ToDur>
224 return __to - _ToDur{1};
228 template<
typename _ToDur,
typename _Rep,
typename _Period>
229 constexpr __enable_if_is_duration<_ToDur>
234 return __to + _ToDur{1};
238 template <
typename _ToDur,
typename _Rep,
typename _Period>
240 __and_<__is_duration<_ToDur>,
241 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
245 _ToDur __t0 = chrono::floor<_ToDur>(__d);
246 _ToDur __t1 = __t0 + _ToDur{1};
247 auto __diff0 = __d - __t0;
248 auto __diff1 = __t1 - __d;
249 if (__diff0 == __diff1)
251 if (__t0.count() & 1)
255 else if (__diff0 < __diff1)
260 template<
typename _Rep,
typename _Period>
265 if (__d >= __d.zero())
272 template<
typename _Rep>
275 static constexpr _Rep
279 static constexpr _Rep
283 static constexpr _Rep
288 template<
typename _Tp>
293 template<
intmax_t _Num,
intmax_t _Den>
294 struct __is_ratio<ratio<_Num, _Den>>
299 template<
typename _Rep,
typename _Period>
303 template<
typename _Rep2>
307 template<
typename _Period2>
314 typedef _Period period;
316 static_assert(!__is_duration<_Rep>::value,
"rep cannot be a duration");
317 static_assert(__is_ratio<_Period>::value,
318 "period must be a specialization of ratio");
319 static_assert(_Period::num > 0,
"period must be positive");
328 template<
typename _Rep2,
typename = _Require<
330 __or_<__is_float<rep>, __not_<__is_float<_Rep2>>>>>
331 constexpr
explicit duration(
const _Rep2& __rep)
332 : __r(static_cast<rep>(__rep)) { }
334 template<
typename _Rep2,
typename _Period2,
typename = _Require<
335 __or_<__is_float<rep>,
336 __and_<__is_harmonic<_Period2>,
337 __not_<__is_float<_Rep2>>>>>>
339 : __r(duration_cast<duration>(__d).count()) { }
341 ~duration() =
default;
342 duration& operator=(
const duration&) =
default;
356 {
return duration(-__r); }
358 _GLIBCXX17_CONSTEXPR duration&
365 _GLIBCXX17_CONSTEXPR duration
367 {
return duration(__r++); }
369 _GLIBCXX17_CONSTEXPR duration&
376 _GLIBCXX17_CONSTEXPR duration
378 {
return duration(__r--); }
380 _GLIBCXX17_CONSTEXPR duration&
381 operator+=(
const duration& __d)
387 _GLIBCXX17_CONSTEXPR duration&
388 operator-=(
const duration& __d)
394 _GLIBCXX17_CONSTEXPR duration&
395 operator*=(
const rep& __rhs)
401 _GLIBCXX17_CONSTEXPR duration&
402 operator/=(
const rep& __rhs)
409 template<
typename _Rep2 = rep>
413 operator%=(
const rep& __rhs)
419 template<
typename _Rep2 = rep>
421 typename enable_if<!treat_as_floating_point<_Rep2>::value,
423 operator%=(
const duration& __d)
430 static constexpr duration
434 static constexpr duration
438 static constexpr duration
446 template<
typename _Rep1,
typename _Period1,
447 typename _Rep2,
typename _Period2>
456 return __cd(__cd(__lhs).count() + __cd(__rhs).count());
459 template<
typename _Rep1,
typename _Period1,
460 typename _Rep2,
typename _Period2>
461 constexpr
typename common_type<duration<_Rep1, _Period1>,
469 return __cd(__cd(__lhs).count() - __cd(__rhs).count());
476 template<
typename _Rep1,
typename _Rep2,
478 using __common_rep_t =
typename 481 template<
typename _Rep1,
typename _Period,
typename _Rep2>
487 return __cd(__cd(__d).count() * __s);
490 template<
typename _Rep1,
typename _Rep2,
typename _Period>
493 {
return __d * __s; }
495 template<
typename _Rep1,
typename _Period,
typename _Rep2>
502 return __cd(__cd(__d).count() / __s);
505 template<
typename _Rep1,
typename _Period1,
506 typename _Rep2,
typename _Period2>
514 return __cd(__lhs).count() / __cd(__rhs).count();
518 template<
typename _Rep1,
typename _Period,
typename _Rep2>
520 duration<__common_rep_t<_Rep1, __disable_if_is_duration<_Rep2>>, _Period>
525 return __cd(__cd(__d).count() % __s);
528 template<
typename _Rep1,
typename _Period1,
529 typename _Rep2,
typename _Period2>
530 constexpr
typename common_type<duration<_Rep1, _Period1>,
538 return __cd(__cd(__lhs).count() % __cd(__rhs).count());
542 template<
typename _Rep1,
typename _Period1,
543 typename _Rep2,
typename _Period2>
551 return __ct(__lhs).count() == __ct(__rhs).count();
554 template<
typename _Rep1,
typename _Period1,
555 typename _Rep2,
typename _Period2>
557 operator<(const duration<_Rep1, _Period1>& __lhs,
563 return __ct(__lhs).count() < __ct(__rhs).count();
566 template<
typename _Rep1,
typename _Period1,
567 typename _Rep2,
typename _Period2>
571 {
return !(__lhs == __rhs); }
573 template<
typename _Rep1,
typename _Period1,
574 typename _Rep2,
typename _Period2>
576 operator<=(const duration<_Rep1, _Period1>& __lhs,
578 {
return !(__rhs < __lhs); }
580 template<
typename _Rep1,
typename _Period1,
581 typename _Rep2,
typename _Period2>
585 {
return __rhs < __lhs; }
587 template<
typename _Rep1,
typename _Period1,
588 typename _Rep2,
typename _Period2>
592 {
return !(__lhs < __rhs); }
594 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 595 # define _GLIBCXX_CHRONO_INT64_T int64_t 596 #elif defined __INT64_TYPE__ 597 # define _GLIBCXX_CHRONO_INT64_T __INT64_TYPE__ 600 "Representation type for nanoseconds must have at least 64 bits");
601 # define _GLIBCXX_CHRONO_INT64_T long long 622 #undef _GLIBCXX_CHRONO_INT64_T 625 template<
typename _Clock,
typename _Dur>
628 typedef _Clock clock;
630 typedef typename duration::rep rep;
631 typedef typename duration::period period;
633 constexpr
time_point() : __d(duration::zero())
636 constexpr
explicit time_point(
const duration& __dur)
641 template<
typename _Dur2,
642 typename = _Require<is_convertible<_Dur2, _Dur>>>
644 : __d(__t.time_since_epoch())
649 time_since_epoch()
const 653 _GLIBCXX17_CONSTEXPR time_point&
654 operator+=(
const duration& __dur)
660 _GLIBCXX17_CONSTEXPR time_point&
661 operator-=(
const duration& __dur)
668 static constexpr time_point
670 {
return time_point(duration::min()); }
672 static constexpr time_point
674 {
return time_point(duration::max()); }
681 template<
typename _ToDur,
typename _Clock,
typename _Dur>
687 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
690 #if __cplusplus > 201402L 691 template<
typename _ToDur,
typename _Clock,
typename _Dur>
697 chrono::floor<_ToDur>(__tp.time_since_epoch())};
700 template<
typename _ToDur,
typename _Clock,
typename _Dur>
706 chrono::ceil<_ToDur>(__tp.time_since_epoch())};
709 template<
typename _ToDur,
typename _Clock,
typename _Dur>
711 __and_<__is_duration<_ToDur>,
712 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
717 chrono::round<_ToDur>(__tp.time_since_epoch())};
721 template<
typename _Clock,
typename _Dur1,
722 typename _Rep2,
typename _Period2>
731 return __time_point(__lhs.time_since_epoch() + __rhs);
734 template<
typename _Rep1,
typename _Period1,
735 typename _Clock,
typename _Dur2>
737 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
744 return __time_point(__rhs.time_since_epoch() + __lhs);
747 template<
typename _Clock,
typename _Dur1,
748 typename _Rep2,
typename _Period2>
757 return __time_point(__lhs.time_since_epoch() -__rhs);
760 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
764 {
return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
766 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
770 {
return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
772 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
776 {
return !(__lhs == __rhs); }
778 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
780 operator<(const time_point<_Clock, _Dur1>& __lhs,
782 {
return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
784 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
786 operator<=(const time_point<_Clock, _Dur1>& __lhs,
788 {
return !(__rhs < __lhs); }
790 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
794 {
return __rhs < __lhs; }
796 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
800 {
return !(__lhs < __rhs); }
821 inline namespace _V2 {
831 typedef duration::rep rep;
832 typedef duration::period period;
836 < system_clock::duration::zero(),
837 "a clock's minimum duration cannot be less than its epoch");
839 static constexpr
bool is_steady =
false;
846 to_time_t(
const time_point& __t) noexcept
848 return std::time_t(duration_cast<chrono::seconds>
849 (__t.time_since_epoch()).count());
853 from_time_t(std::time_t __t) noexcept
870 typedef duration::rep rep;
871 typedef duration::period period;
874 static constexpr
bool is_steady =
true;
893 #if __cplusplus > 201103L 895 #define __cpp_lib_chrono_udls 201304 897 inline namespace literals
899 inline namespace chrono_literals
901 #pragma GCC diagnostic push 902 #pragma GCC diagnostic ignored "-Wliteral-suffix" 903 template<
typename _Dur,
char... _Digits>
904 constexpr _Dur __check_overflow()
906 using _Val = __parse_int::_Parse_int<_Digits...>;
907 constexpr
typename _Dur::rep __repval = _Val::value;
908 static_assert(__repval >= 0 && __repval == _Val::value,
909 "literal value cannot be represented by duration type");
910 return _Dur(__repval);
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
985 #endif //_GLIBCXX_CHRONO static constexpr _Tp lowest() noexcept
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
duration< int64_t, nano > nanoseconds
nanoseconds
duration< int64_t, micro > microseconds
microseconds
duration< int64_t, milli > milliseconds
milliseconds
Provides compile-time rational arithmetic.
ISO C++ entities toplevel namespace is std.
Properties of fundamental types.
Define a member typedef type only if a boolean constant is true.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
static constexpr _Tp max() noexcept
duration< int64_t, ratio< 3600 > > hours
hours
typename __ratio_divide< _R1, _R2 >::type ratio_divide
ratio_divide
constexpr enable_if< __is_duration< _ToDur >::value, time_point< _Clock, _ToDur > >::type time_point_cast(const time_point< _Clock, _Dur > &__t)
time_point_cast
constexpr __enable_if_is_duration< _ToDur > duration_cast(const duration< _Rep, _Period > &__d)
duration_cast
duration< int64_t > seconds
seconds
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
duration< int64_t, ratio< 60 > > minutes
minutes