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)
61 _GLIBCXX_BEGIN_NAMESPACE_VERSION
63 template<
typename _Rep,
typename _Period = ratio<1>>
66 template<
typename _Clock,
typename _Dur =
typename _Clock::duration>
69 _GLIBCXX_END_NAMESPACE_VERSION
72 _GLIBCXX_BEGIN_NAMESPACE_VERSION
76 template<
typename _CT,
typename _Period1,
typename _Period2>
77 struct __duration_common_type_wrapper
80 typedef __static_gcd<_Period1::num, _Period2::num> __gcd_num;
81 typedef __static_gcd<_Period1::den, _Period2::den> __gcd_den;
82 typedef typename _CT::type __cr;
83 typedef ratio<__gcd_num::value,
84 (_Period1::den / __gcd_den::value) * _Period2::den> __r;
86 typedef __success_type<chrono::duration<__cr, __r>> type;
89 template<
typename _Period1,
typename _Period2>
90 struct __duration_common_type_wrapper<__failure_type, _Period1, _Period2>
91 {
typedef __failure_type type; };
93 template<
typename _Rep1,
typename _Period1,
typename _Rep2,
typename _Period2>
94 struct common_type<chrono::duration<_Rep1, _Period1>,
96 :
public __duration_common_type_wrapper<typename __member_type_wrapper<
97 common_type<_Rep1, _Rep2>>::type, _Period1, _Period2>::type
102 template<
typename _CT,
typename _Clock>
103 struct __timepoint_common_type_wrapper
105 typedef __success_type<chrono::time_point<_Clock, typename _CT::type>>
109 template<
typename _Clock>
110 struct __timepoint_common_type_wrapper<__failure_type, _Clock>
111 {
typedef __failure_type type; };
113 template<
typename _Clock,
typename _Duration1,
typename _Duration2>
114 struct common_type<chrono::
time_point<_Clock, _Duration1>,
116 :
public __timepoint_common_type_wrapper<typename __member_type_wrapper<
117 common_type<_Duration1, _Duration2>>::type, _Clock>::type
120 _GLIBCXX_END_NAMESPACE_VERSION
124 _GLIBCXX_BEGIN_NAMESPACE_VERSION
127 template<
typename _ToDur,
typename _CF,
typename _CR,
128 bool _NumIsOne =
false,
bool _DenIsOne =
false>
129 struct __duration_cast_impl
131 template<
typename _Rep,
typename _Period>
132 static constexpr _ToDur
133 __cast(
const duration<_Rep, _Period>& __d)
135 typedef typename _ToDur::rep __to_rep;
136 return _ToDur(static_cast<__to_rep>(static_cast<_CR>(__d.count())
137 * static_cast<_CR>(_CF::num)
138 /
static_cast<_CR
>(_CF::den)));
142 template<
typename _ToDur,
typename _CF,
typename _CR>
143 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
145 template<
typename _Rep,
typename _Period>
146 static constexpr _ToDur
147 __cast(
const duration<_Rep, _Period>& __d)
149 typedef typename _ToDur::rep __to_rep;
150 return _ToDur(static_cast<__to_rep>(__d.count()));
154 template<
typename _ToDur,
typename _CF,
typename _CR>
155 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
157 template<
typename _Rep,
typename _Period>
158 static constexpr _ToDur
159 __cast(
const duration<_Rep, _Period>& __d)
161 typedef typename _ToDur::rep __to_rep;
162 return _ToDur(static_cast<__to_rep>(
163 static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den)));
167 template<
typename _ToDur,
typename _CF,
typename _CR>
168 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
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::num)));
180 template<
typename _Tp>
185 template<
typename _Rep,
typename _Period>
186 struct __is_duration<duration<_Rep, _Period>>
191 template<
typename _ToDur,
typename _Rep,
typename _Period>
192 constexpr
typename enable_if<__is_duration<_ToDur>::value,
196 typedef typename _ToDur::period __to_period;
197 typedef typename _ToDur::rep __to_rep;
199 typedef typename common_type<__to_rep, _Rep, intmax_t>::type
201 typedef __duration_cast_impl<_ToDur, __cf, __cr,
202 __cf::num == 1, __cf::den == 1> __dc;
203 return __dc::__cast(__d);
207 template<
typename _Rep>
213 template<
typename _Rep>
216 static constexpr _Rep
220 static constexpr _Rep
224 static constexpr _Rep
229 template<
typename _Tp>
234 template<
intmax_t _Num,
intmax_t _Den>
235 struct __is_ratio<ratio<_Num, _Den>>
240 template<
typename _Rep,
typename _Period>
244 typedef _Period period;
246 static_assert(!__is_duration<_Rep>::value,
"rep cannot be a duration");
247 static_assert(__is_ratio<_Period>::value,
248 "period must be a specialization of ratio");
249 static_assert(_Period::num > 0,
"period must be positive");
259 template<
typename _Rep2,
typename =
typename 260 enable_if<is_convertible<_Rep2, rep>::value
263 constexpr
explicit duration(
const _Rep2& __rep)
264 : __r(static_cast<rep>(__rep)) { }
266 template<
typename _Rep2,
typename _Period2,
typename =
typename 267 enable_if<treat_as_floating_point<rep>::value
271 : __r(duration_cast<duration>(__d).count()) { }
327 operator*=(
const rep& __rhs)
334 operator/=(
const rep& __rhs)
341 template<
typename _Rep2 = rep>
342 typename enable_if<!treat_as_floating_point<_Rep2>::value,
344 operator%=(
const rep& __rhs)
350 template<
typename _Rep2 = rep>
351 typename enable_if<!treat_as_floating_point<_Rep2>::value,
376 template<
typename _Rep1,
typename _Period1,
377 typename _Rep2,
typename _Period2>
378 constexpr
typename common_type<duration<_Rep1, _Period1>,
385 typedef typename common_type<__dur1,__dur2>::type __cd;
386 return __cd(__cd(__lhs).count() + __cd(__rhs).count());
389 template<
typename _Rep1,
typename _Period1,
390 typename _Rep2,
typename _Period2>
391 constexpr
typename common_type<duration<_Rep1, _Period1>,
398 typedef typename common_type<__dur1,__dur2>::type __cd;
399 return __cd(__cd(__lhs).count() - __cd(__rhs).count());
402 template<
typename _Rep1,
typename _Rep2,
bool =
403 is_convertible<_Rep2,
404 typename common_type<_Rep1, _Rep2>::type>::value>
405 struct __common_rep_type { };
407 template<
typename _Rep1,
typename _Rep2>
408 struct __common_rep_type<_Rep1, _Rep2, true>
409 {
typedef typename common_type<_Rep1, _Rep2>::type type; };
411 template<
typename _Rep1,
typename _Period,
typename _Rep2>
418 return __cd(__cd(__d).count() * __s);
421 template<
typename _Rep1,
typename _Rep2,
typename _Period>
425 {
return __d * __s; }
427 template<
typename _Rep1,
typename _Period,
typename _Rep2>
428 constexpr
duration<
typename __common_rep_type<_Rep1,
typename 429 enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period>
434 return __cd(__cd(__d).count() / __s);
437 template<
typename _Rep1,
typename _Period1,
438 typename _Rep2,
typename _Period2>
439 constexpr
typename common_type<_Rep1, _Rep2>::type
445 typedef typename common_type<__dur1,__dur2>::type __cd;
446 return __cd(__lhs).count() / __cd(__rhs).count();
450 template<
typename _Rep1,
typename _Period,
typename _Rep2>
451 constexpr
duration<
typename __common_rep_type<_Rep1,
typename 452 enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period>
457 return __cd(__cd(__d).count() % __s);
460 template<
typename _Rep1,
typename _Period1,
461 typename _Rep2,
typename _Period2>
462 constexpr
typename common_type<duration<_Rep1, _Period1>,
469 typedef typename common_type<__dur1,__dur2>::type __cd;
470 return __cd(__cd(__lhs).count() % __cd(__rhs).count());
474 template<
typename _Rep1,
typename _Period1,
475 typename _Rep2,
typename _Period2>
482 typedef typename common_type<__dur1,__dur2>::type __ct;
483 return __ct(__lhs).count() == __ct(__rhs).count();
486 template<
typename _Rep1,
typename _Period1,
487 typename _Rep2,
typename _Period2>
489 operator<(const duration<_Rep1, _Period1>& __lhs,
494 typedef typename common_type<__dur1,__dur2>::type __ct;
495 return __ct(__lhs).count() < __ct(__rhs).count();
498 template<
typename _Rep1,
typename _Period1,
499 typename _Rep2,
typename _Period2>
503 {
return !(__lhs == __rhs); }
505 template<
typename _Rep1,
typename _Period1,
506 typename _Rep2,
typename _Period2>
508 operator<=(const duration<_Rep1, _Period1>& __lhs,
510 {
return !(__rhs < __lhs); }
512 template<
typename _Rep1,
typename _Period1,
513 typename _Rep2,
typename _Period2>
517 {
return __rhs < __lhs; }
519 template<
typename _Rep1,
typename _Period1,
520 typename _Rep2,
typename _Period2>
524 {
return !(__lhs < __rhs); }
545 template<
typename _Clock,
typename _Dur>
548 typedef _Clock clock;
550 typedef typename duration::rep rep;
551 typedef typename duration::period period;
553 constexpr
time_point() : __d(duration::zero())
556 constexpr
explicit time_point(
const duration& __dur)
561 template<
typename _Dur2,
562 typename = _Require<is_convertible<_Dur2, _Dur>>>
564 : __d(__t.time_since_epoch())
569 time_since_epoch()
const 574 operator+=(
const duration& __dur)
581 operator-=(
const duration& __dur)
588 static constexpr time_point
590 {
return time_point(duration::min()); }
592 static constexpr time_point
594 {
return time_point(duration::max()); }
601 template<
typename _ToDur,
typename _Clock,
typename _Dur>
602 constexpr
typename enable_if<__is_duration<_ToDur>::value,
607 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
610 template<
typename _Clock,
typename _Dur1,
611 typename _Rep2,
typename _Period2>
613 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
618 typedef typename common_type<_Dur1,__dur2>::type __ct;
620 return __time_point(__lhs.time_since_epoch() + __rhs);
623 template<
typename _Rep1,
typename _Period1,
624 typename _Clock,
typename _Dur2>
626 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
631 typedef typename common_type<__dur1,_Dur2>::type __ct;
633 return __time_point(__rhs.time_since_epoch() + __lhs);
636 template<
typename _Clock,
typename _Dur1,
637 typename _Rep2,
typename _Period2>
639 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
644 typedef typename common_type<_Dur1,__dur2>::type __ct;
646 return __time_point(__lhs.time_since_epoch() -__rhs);
649 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
650 constexpr
typename common_type<_Dur1, _Dur2>::type
653 {
return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
655 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
659 {
return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
661 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
665 {
return !(__lhs == __rhs); }
667 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
669 operator<(const time_point<_Clock, _Dur1>& __lhs,
671 {
return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
673 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
675 operator<=(const time_point<_Clock, _Dur1>& __lhs,
677 {
return !(__rhs < __lhs); }
679 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
683 {
return __rhs < __lhs; }
685 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
689 {
return !(__lhs < __rhs); }
710 inline namespace _V2 {
720 typedef duration::rep rep;
721 typedef duration::period period;
725 < system_clock::duration::zero(),
726 "a clock's minimum duration cannot be less than its epoch");
728 static constexpr
bool is_steady =
false;
735 to_time_t(
const time_point& __t) noexcept
737 return std::time_t(duration_cast<chrono::seconds>
738 (__t.time_since_epoch()).count());
742 from_time_t(std::time_t __t) noexcept
759 typedef duration::rep rep;
760 typedef duration::period period;
763 static constexpr
bool is_steady =
true;
781 _GLIBCXX_END_NAMESPACE_VERSION
784 #if __cplusplus > 201103L 786 #define __cpp_lib_chrono_udls 201304 788 inline namespace literals
790 inline namespace chrono_literals
792 _GLIBCXX_BEGIN_NAMESPACE_VERSION
794 template<
typename _Rep,
unsigned long long _Val>
795 struct _Checked_integral_constant
798 static_assert(_Checked_integral_constant::value >= 0
799 && _Checked_integral_constant::value == _Val,
800 "literal value cannot be represented by duration type");
803 template<
typename _Dur,
char... _Digits>
804 constexpr _Dur __check_overflow()
806 using _Val = __parse_int::_Parse_int<_Digits...>;
807 using _Rep =
typename _Dur::rep;
810 using _CheckedVal = _Checked_integral_constant<_Rep, _Val::value>;
811 return _Dur{_CheckedVal::value};
815 operator""h(
long double __hours)
818 template <
char... _Digits>
824 operator""min(
long double __mins)
827 template <
char... _Digits>
833 operator""s(
long double __secs)
836 template <
char... _Digits>
842 operator""ms(
long double __msecs)
845 template <
char... _Digits>
851 operator""us(
long double __usecs)
854 template <
char... _Digits>
860 operator""ns(
long double __nsecs)
863 template <
char... _Digits>
868 _GLIBCXX_END_NAMESPACE_VERSION
874 _GLIBCXX_BEGIN_NAMESPACE_VERSION
876 using namespace literals::chrono_literals;
878 _GLIBCXX_END_NAMESPACE_VERSION
881 #endif // __cplusplus > 201103L 886 #endif //_GLIBCXX_USE_C99_STDINT_TR1 890 #endif //_GLIBCXX_CHRONO
duration< int64_t, ratio< 3600 > > hours
hours
constexpr enable_if< __is_duration< _ToDur >::value, _ToDur >::type duration_cast(const duration< _Rep, _Period > &__d)
duration_cast
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
typename __ratio_divide< _R1, _R2 >::type ratio_divide
ratio_divide
duration< int64_t, micro > microseconds
microseconds
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
duration< int64_t, nano > nanoseconds
nanoseconds
duration< int64_t, ratio< 60 > > minutes
minutes
ISO C++ entities toplevel namespace is std.
duration< int64_t > seconds
seconds
Provides compile-time rational arithmetic.
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 max() noexcept
duration< int64_t, milli > milliseconds
milliseconds
static constexpr _Tp lowest() noexcept