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>
212 #if __cplusplus > 201402L 213 template <
typename _Rep>
214 constexpr
bool treat_as_floating_point_v =
218 #if __cplusplus > 201402L 219 # define __cpp_lib_chrono 201510 221 template<
typename _ToDur,
typename _Rep,
typename _Period>
222 constexpr enable_if_t<__is_duration<_ToDur>::value, _ToDur>
227 return __to - _ToDur{1};
231 template<
typename _ToDur,
typename _Rep,
typename _Period>
232 constexpr enable_if_t<__is_duration<_ToDur>::value, _ToDur>
237 return __to + _ToDur{1};
241 template <
typename _ToDur,
typename _Rep,
typename _Period>
242 constexpr enable_if_t<
243 __and_<__is_duration<_ToDur>,
244 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
248 _ToDur __t0 = chrono::floor<_ToDur>(__d);
249 _ToDur __t1 = __t0 + _ToDur{1};
250 auto __diff0 = __d - __t0;
251 auto __diff1 = __t1 - __d;
252 if (__diff0 == __diff1)
254 if (__t0.count() & 1)
258 else if (__diff0 < __diff1)
263 template<
typename _Rep,
typename _Period>
268 if (__d >= __d.zero())
275 template<
typename _Rep>
278 static constexpr _Rep
282 static constexpr _Rep
286 static constexpr _Rep
291 template<
typename _Tp>
296 template<
intmax_t _Num,
intmax_t _Den>
297 struct __is_ratio<ratio<_Num, _Den>>
302 template<
typename _Rep,
typename _Period>
306 typedef _Period period;
308 static_assert(!__is_duration<_Rep>::value,
"rep cannot be a duration");
309 static_assert(__is_ratio<_Period>::value,
310 "period must be a specialization of ratio");
311 static_assert(_Period::num > 0,
"period must be positive");
321 template<
typename _Rep2,
typename =
typename 322 enable_if<is_convertible<_Rep2, rep>::value
325 constexpr
explicit duration(
const _Rep2& __rep)
326 : __r(static_cast<rep>(__rep)) { }
328 template<
typename _Rep2,
typename _Period2,
typename =
typename 329 enable_if<treat_as_floating_point<rep>::value
333 : __r(duration_cast<duration>(__d).count()) { }
389 operator*=(
const rep& __rhs)
396 operator/=(
const rep& __rhs)
403 template<
typename _Rep2 = rep>
404 typename enable_if<!treat_as_floating_point<_Rep2>::value,
406 operator%=(
const rep& __rhs)
412 template<
typename _Rep2 = rep>
413 typename enable_if<!treat_as_floating_point<_Rep2>::value,
438 template<
typename _Rep1,
typename _Period1,
439 typename _Rep2,
typename _Period2>
440 constexpr
typename common_type<duration<_Rep1, _Period1>,
447 typedef typename common_type<__dur1,__dur2>::type __cd;
448 return __cd(__cd(__lhs).count() + __cd(__rhs).count());
451 template<
typename _Rep1,
typename _Period1,
452 typename _Rep2,
typename _Period2>
453 constexpr
typename common_type<duration<_Rep1, _Period1>,
460 typedef typename common_type<__dur1,__dur2>::type __cd;
461 return __cd(__cd(__lhs).count() - __cd(__rhs).count());
464 template<
typename _Rep1,
typename _Rep2,
bool =
465 is_convertible<_Rep2,
466 typename common_type<_Rep1, _Rep2>::type>::value>
467 struct __common_rep_type { };
469 template<
typename _Rep1,
typename _Rep2>
470 struct __common_rep_type<_Rep1, _Rep2, true>
471 {
typedef typename common_type<_Rep1, _Rep2>::type type; };
473 template<
typename _Rep1,
typename _Period,
typename _Rep2>
480 return __cd(__cd(__d).count() * __s);
483 template<
typename _Rep1,
typename _Rep2,
typename _Period>
487 {
return __d * __s; }
489 template<
typename _Rep1,
typename _Period,
typename _Rep2>
490 constexpr
duration<
typename __common_rep_type<_Rep1,
typename 491 enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period>
496 return __cd(__cd(__d).count() / __s);
499 template<
typename _Rep1,
typename _Period1,
500 typename _Rep2,
typename _Period2>
501 constexpr
typename common_type<_Rep1, _Rep2>::type
507 typedef typename common_type<__dur1,__dur2>::type __cd;
508 return __cd(__lhs).count() / __cd(__rhs).count();
512 template<
typename _Rep1,
typename _Period,
typename _Rep2>
513 constexpr
duration<
typename __common_rep_type<_Rep1,
typename 514 enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period>
519 return __cd(__cd(__d).count() % __s);
522 template<
typename _Rep1,
typename _Period1,
523 typename _Rep2,
typename _Period2>
524 constexpr
typename common_type<duration<_Rep1, _Period1>,
531 typedef typename common_type<__dur1,__dur2>::type __cd;
532 return __cd(__cd(__lhs).count() % __cd(__rhs).count());
536 template<
typename _Rep1,
typename _Period1,
537 typename _Rep2,
typename _Period2>
544 typedef typename common_type<__dur1,__dur2>::type __ct;
545 return __ct(__lhs).count() == __ct(__rhs).count();
548 template<
typename _Rep1,
typename _Period1,
549 typename _Rep2,
typename _Period2>
551 operator<(const duration<_Rep1, _Period1>& __lhs,
556 typedef typename common_type<__dur1,__dur2>::type __ct;
557 return __ct(__lhs).count() < __ct(__rhs).count();
560 template<
typename _Rep1,
typename _Period1,
561 typename _Rep2,
typename _Period2>
565 {
return !(__lhs == __rhs); }
567 template<
typename _Rep1,
typename _Period1,
568 typename _Rep2,
typename _Period2>
570 operator<=(const duration<_Rep1, _Period1>& __lhs,
572 {
return !(__rhs < __lhs); }
574 template<
typename _Rep1,
typename _Period1,
575 typename _Rep2,
typename _Period2>
579 {
return __rhs < __lhs; }
581 template<
typename _Rep1,
typename _Period1,
582 typename _Rep2,
typename _Period2>
586 {
return !(__lhs < __rhs); }
607 template<
typename _Clock,
typename _Dur>
610 typedef _Clock clock;
612 typedef typename duration::rep rep;
613 typedef typename duration::period period;
615 constexpr
time_point() : __d(duration::zero())
618 constexpr
explicit time_point(
const duration& __dur)
623 template<
typename _Dur2>
625 : __d(__t.time_since_epoch())
630 time_since_epoch()
const 635 operator+=(
const duration& __dur)
642 operator-=(
const duration& __dur)
649 static constexpr time_point
651 {
return time_point(duration::min()); }
653 static constexpr time_point
655 {
return time_point(duration::max()); }
662 template<
typename _ToDur,
typename _Clock,
typename _Dur>
663 constexpr
typename enable_if<__is_duration<_ToDur>::value,
668 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
671 #if __cplusplus > 201402L 672 template<
typename _ToDur,
typename _Clock,
typename _Dur>
678 chrono::floor<_ToDur>(__tp.time_since_epoch())};
681 template<
typename _ToDur,
typename _Clock,
typename _Dur>
687 chrono::ceil<_ToDur>(__tp.time_since_epoch())};
690 template<
typename _ToDur,
typename _Clock,
typename _Dur>
691 constexpr enable_if_t<
692 __and_<__is_duration<_ToDur>,
693 __not_<treat_as_floating_point<typename _ToDur::rep>>>::value,
698 chrono::round<_ToDur>(__tp.time_since_epoch())};
702 template<
typename _Clock,
typename _Dur1,
703 typename _Rep2,
typename _Period2>
705 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
710 typedef typename common_type<_Dur1,__dur2>::type __ct;
712 return __time_point(__lhs.time_since_epoch() + __rhs);
715 template<
typename _Rep1,
typename _Period1,
716 typename _Clock,
typename _Dur2>
718 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
723 typedef typename common_type<__dur1,_Dur2>::type __ct;
725 return __time_point(__rhs.time_since_epoch() + __lhs);
728 template<
typename _Clock,
typename _Dur1,
729 typename _Rep2,
typename _Period2>
731 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
736 typedef typename common_type<_Dur1,__dur2>::type __ct;
738 return __time_point(__lhs.time_since_epoch() -__rhs);
741 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
742 constexpr
typename common_type<_Dur1, _Dur2>::type
745 {
return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
747 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
751 {
return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
753 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
757 {
return !(__lhs == __rhs); }
759 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
761 operator<(const time_point<_Clock, _Dur1>& __lhs,
763 {
return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
765 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
767 operator<=(const time_point<_Clock, _Dur1>& __lhs,
769 {
return !(__rhs < __lhs); }
771 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
775 {
return __rhs < __lhs; }
777 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
781 {
return !(__lhs < __rhs); }
802 inline namespace _V2 {
812 typedef duration::rep rep;
813 typedef duration::period period;
817 < system_clock::duration::zero(),
818 "a clock's minimum duration cannot be less than its epoch");
820 static constexpr
bool is_steady =
false;
827 to_time_t(
const time_point& __t) noexcept
829 return std::time_t(duration_cast<chrono::seconds>
830 (__t.time_since_epoch()).count());
834 from_time_t(std::time_t __t) noexcept
851 typedef duration::rep rep;
852 typedef duration::period period;
855 static constexpr
bool is_steady =
true;
873 _GLIBCXX_END_NAMESPACE_VERSION
876 #if __cplusplus > 201103L 878 #define __cpp_lib_chrono_udls 201304 880 inline namespace literals
882 inline namespace chrono_literals
884 _GLIBCXX_BEGIN_NAMESPACE_VERSION
886 template<
typename _Rep,
unsigned long long _Val>
887 struct _Checked_integral_constant
890 static_assert(_Checked_integral_constant::value >= 0
891 && _Checked_integral_constant::value == _Val,
892 "literal value cannot be represented by duration type");
895 template<
typename _Dur,
char... _Digits>
896 constexpr _Dur __check_overflow()
898 using _Val = __parse_int::_Parse_int<_Digits...>;
899 using _Rep =
typename _Dur::rep;
902 using _CheckedVal = _Checked_integral_constant<_Rep, _Val::value>;
903 return _Dur{_CheckedVal::value};
907 operator""h(
long double __hours)
910 template <
char... _Digits>
916 operator""min(
long double __mins)
919 template <
char... _Digits>
925 operator""s(
long double __secs)
928 template <
char... _Digits>
934 operator""ms(
long double __msecs)
937 template <
char... _Digits>
943 operator""us(
long double __usecs)
946 template <
char... _Digits>
952 operator""ns(
long double __nsecs)
955 template <
char... _Digits>
960 _GLIBCXX_END_NAMESPACE_VERSION
966 _GLIBCXX_BEGIN_NAMESPACE_VERSION
968 using namespace literals::chrono_literals;
970 _GLIBCXX_END_NAMESPACE_VERSION
973 #endif // __cplusplus > 201103L 978 #endif //_GLIBCXX_USE_C99_STDINT_TR1 982 #endif //_GLIBCXX_CHRONO
duration< int64_t > seconds
seconds
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
Provides compile-time rational arithmetic.
duration< int64_t, nano > nanoseconds
nanoseconds
ISO C++ entities toplevel namespace is std.
static constexpr _Tp max() noexcept
duration< int64_t, milli > milliseconds
milliseconds
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
static constexpr _Tp lowest() noexcept
typename __ratio_divide< _R1, _R2 >::type ratio_divide
ratio_divide
constexpr enable_if< __is_duration< _ToDur >::value, _ToDur >::type duration_cast(const duration< _Rep, _Period > &__d)
duration_cast
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, micro > microseconds
microseconds
duration< int64_t, ratio< 3600 > > hours
hours
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
duration< int64_t, ratio< 60 > > minutes
minutes