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>,
95 chrono::duration<_Rep2, _Period2>>
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>,
115 chrono::time_point<_Clock, _Duration2>>
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");
252 constexpr duration() =
default;
257 duration(
const duration&) =
default;
259 template<
typename _Rep2,
typename =
typename
260 enable_if<is_convertible<_Rep2, rep>::value
261 && (treat_as_floating_point<rep>::value
262 || !treat_as_floating_point<_Rep2>::value)>::type>
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
268 || (ratio_divide<_Period2, period>::den == 1
269 && !treat_as_floating_point<_Rep2>::value)>::type>
270 constexpr duration(
const duration<_Rep2, _Period2>& __d)
271 : __r(duration_cast<duration>(__d).count()) { }
273 ~duration() =
default;
274 duration& operator=(
const duration&) =
default;
288 {
return duration(-__r); }
299 {
return duration(__r++); }
310 {
return duration(__r--); }
313 operator+=(
const duration& __d)
320 operator-=(
const duration& __d)
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,
353 operator%=(
const duration& __d)
360 static constexpr duration
362 {
return duration(duration_values<rep>::zero()); }
364 static constexpr duration
368 static constexpr duration
376 template<
typename _Rep1,
typename _Period1,
377 typename _Rep2,
typename _Period2>
378 constexpr
typename common_type<duration<_Rep1, _Period1>,
379 duration<_Rep2, _Period2>>::type
380 operator+(
const duration<_Rep1, _Period1>& __lhs,
381 const duration<_Rep2, _Period2>& __rhs)
383 typedef duration<_Rep1, _Period1> __dur1;
384 typedef duration<_Rep2, _Period2> __dur2;
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>,
392 duration<_Rep2, _Period2>>::type
393 operator-(
const duration<_Rep1, _Period1>& __lhs,
394 const duration<_Rep2, _Period2>& __rhs)
396 typedef duration<_Rep1, _Period1> __dur1;
397 typedef duration<_Rep2, _Period2> __dur2;
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>
413 duration<typename __common_rep_type<_Rep1, _Rep2>::type, _Period>
414 operator*(
const duration<_Rep1, _Period>& __d,
const _Rep2& __s)
416 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
418 return __cd(__cd(__d).count() * __s);
421 template<
typename _Rep1,
typename _Rep2,
typename _Period>
423 duration<typename __common_rep_type<_Rep2, _Rep1>::type, _Period>
424 operator*(
const _Rep1& __s,
const duration<_Rep2, _Period>& __d)
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>
430 operator/(
const duration<_Rep1, _Period>& __d,
const _Rep2& __s)
432 typedef duration<typename common_type<_Rep1, _Rep2>::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
440 operator/(
const duration<_Rep1, _Period1>& __lhs,
441 const duration<_Rep2, _Period2>& __rhs)
443 typedef duration<_Rep1, _Period1> __dur1;
444 typedef duration<_Rep2, _Period2> __dur2;
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>
453 operator%(
const duration<_Rep1, _Period>& __d,
const _Rep2& __s)
455 typedef duration<typename common_type<_Rep1, _Rep2>::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>,
463 duration<_Rep2, _Period2>>::type
464 operator%(
const duration<_Rep1, _Period1>& __lhs,
465 const duration<_Rep2, _Period2>& __rhs)
467 typedef duration<_Rep1, _Period1> __dur1;
468 typedef duration<_Rep2, _Period2> __dur2;
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>
477 operator==(
const duration<_Rep1, _Period1>& __lhs,
478 const duration<_Rep2, _Period2>& __rhs)
480 typedef duration<_Rep1, _Period1> __dur1;
481 typedef duration<_Rep2, _Period2> __dur2;
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,
490 const duration<_Rep2, _Period2>& __rhs)
492 typedef duration<_Rep1, _Period1> __dur1;
493 typedef duration<_Rep2, _Period2> __dur2;
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>
501 operator!=(
const duration<_Rep1, _Period1>& __lhs,
502 const duration<_Rep2, _Period2>& __rhs)
503 {
return !(__lhs == __rhs); }
505 template<
typename _Rep1,
typename _Period1,
506 typename _Rep2,
typename _Period2>
508 operator<=(const duration<_Rep1, _Period1>& __lhs,
509 const duration<_Rep2, _Period2>& __rhs)
510 {
return !(__rhs < __lhs); }
512 template<
typename _Rep1,
typename _Period1,
513 typename _Rep2,
typename _Period2>
515 operator>(
const duration<_Rep1, _Period1>& __lhs,
516 const duration<_Rep2, _Period2>& __rhs)
517 {
return __rhs < __lhs; }
519 template<
typename _Rep1,
typename _Period1,
520 typename _Rep2,
typename _Period2>
522 operator>=(
const duration<_Rep1, _Period1>& __lhs,
523 const duration<_Rep2, _Period2>& __rhs)
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
588 static constexpr time_point
592 static constexpr time_point
601 template<
typename _ToDur,
typename _Clock,
typename _Dur>
602 constexpr
typename enable_if<__is_duration<_ToDur>::value,
603 time_point<_Clock, _ToDur>>::type
607 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
610 template<
typename _Clock,
typename _Dur1,
611 typename _Rep2,
typename _Period2>
612 constexpr time_point<_Clock,
613 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
614 operator+(
const time_point<_Clock, _Dur1>& __lhs,
615 const duration<_Rep2, _Period2>& __rhs)
617 typedef duration<_Rep2, _Period2> __dur2;
618 typedef typename common_type<_Dur1,__dur2>::type __ct;
619 typedef time_point<_Clock, __ct> __time_point;
620 return __time_point(__lhs.time_since_epoch() + __rhs);
623 template<
typename _Rep1,
typename _Period1,
624 typename _Clock,
typename _Dur2>
625 constexpr time_point<_Clock,
626 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
627 operator+(
const duration<_Rep1, _Period1>& __lhs,
628 const time_point<_Clock, _Dur2>& __rhs)
630 typedef duration<_Rep1, _Period1> __dur1;
631 typedef typename common_type<__dur1,_Dur2>::type __ct;
632 typedef time_point<_Clock, __ct> __time_point;
633 return __time_point(__rhs.time_since_epoch() + __lhs);
636 template<
typename _Clock,
typename _Dur1,
637 typename _Rep2,
typename _Period2>
638 constexpr time_point<_Clock,
639 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
640 operator-(
const time_point<_Clock, _Dur1>& __lhs,
641 const duration<_Rep2, _Period2>& __rhs)
643 typedef duration<_Rep2, _Period2> __dur2;
644 typedef typename common_type<_Dur1,__dur2>::type __ct;
645 typedef time_point<_Clock, __ct> __time_point;
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
651 operator-(
const time_point<_Clock, _Dur1>& __lhs,
652 const time_point<_Clock, _Dur2>& __rhs)
653 {
return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
655 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
657 operator==(
const time_point<_Clock, _Dur1>& __lhs,
658 const time_point<_Clock, _Dur2>& __rhs)
659 {
return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
661 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
663 operator!=(
const time_point<_Clock, _Dur1>& __lhs,
664 const time_point<_Clock, _Dur2>& __rhs)
665 {
return !(__lhs == __rhs); }
667 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
669 operator<(const time_point<_Clock, _Dur1>& __lhs,
670 const time_point<_Clock, _Dur2>& __rhs)
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,
676 const time_point<_Clock, _Dur2>& __rhs)
677 {
return !(__rhs < __lhs); }
679 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
681 operator>(
const time_point<_Clock, _Dur1>& __lhs,
682 const time_point<_Clock, _Dur2>& __rhs)
683 {
return __rhs < __lhs; }
685 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
687 operator>=(
const time_point<_Clock, _Dur1>& __lhs,
688 const time_point<_Clock, _Dur2>& __rhs)
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;
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};
814 constexpr chrono::duration<long double, ratio<3600,1>>
815 operator""h(
long double __hours)
816 {
return chrono::duration<long double, ratio<3600,1>>{__hours}; }
818 template <
char... _Digits>
823 constexpr chrono::duration<long double, ratio<60,1>>
824 operator""min(
long double __mins)
825 {
return chrono::duration<long double, ratio<60,1>>{__mins}; }
827 template <
char... _Digits>
832 constexpr chrono::duration<long double>
833 operator""s(
long double __secs)
834 {
return chrono::duration<long double>{__secs}; }
836 template <
char... _Digits>
841 constexpr chrono::duration<long double, milli>
842 operator""ms(
long double __msecs)
843 {
return chrono::duration<long double, milli>{__msecs}; }
845 template <
char... _Digits>
850 constexpr chrono::duration<long double, micro>
851 operator""us(
long double __usecs)
852 {
return chrono::duration<long double, micro>{__usecs}; }
854 template <
char... _Digits>
859 constexpr chrono::duration<long double, nano>
860 operator""ns(
long double __nsecs)
861 {
return chrono::duration<long double, nano>{__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
typename __ratio_divide< _R1, _R2 >::type ratio_divide
ratio_divide
duration< int64_t, micro > microseconds
microseconds
constexpr enable_if< __is_duration< _ToDur >::value, _ToDur >::type duration_cast(const duration< _Rep, _Period > &__d)
duration_cast
duration< int64_t > seconds
seconds
duration< int64_t, nano > nanoseconds
nanoseconds
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
duration< int64_t, ratio< 3600 > > hours
hours
duration< int64_t, ratio< 60 > > minutes
minutes
complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
duration< int64_t, milli > milliseconds
milliseconds
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
static constexpr _Tp lowest() noexcept
static constexpr _Tp max() noexcept
constexpr enable_if< __is_duration< _ToDur >::value, time_point< _Clock, _ToDur > >::type time_point_cast(const time_point< _Clock, _Dur > &__t)
time_point_cast
Provides compile-time rational arithmetic.