29 #ifndef _GLIBCXX_CHRONO
30 #define _GLIBCXX_CHRONO 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
43 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
45 namespace std _GLIBCXX_VISIBILITY(default)
60 _GLIBCXX_BEGIN_NAMESPACE_VERSION
62 template<
typename _Rep,
typename _Period = ratio<1>>
65 template<
typename _Clock,
typename _Dur =
typename _Clock::duration>
68 _GLIBCXX_END_NAMESPACE_VERSION
71 _GLIBCXX_BEGIN_NAMESPACE_VERSION
75 template<
typename _CT,
typename _Period1,
typename _Period2>
76 struct __duration_common_type_wrapper
79 typedef __static_gcd<_Period1::num, _Period2::num> __gcd_num;
80 typedef __static_gcd<_Period1::den, _Period2::den> __gcd_den;
81 typedef typename _CT::type __cr;
82 typedef ratio<__gcd_num::value,
83 (_Period1::den / __gcd_den::value) * _Period2::den> __r;
85 typedef __success_type<chrono::duration<__cr, __r>> type;
88 template<
typename _Period1,
typename _Period2>
89 struct __duration_common_type_wrapper<__failure_type, _Period1, _Period2>
90 {
typedef __failure_type type; };
92 template<
typename _Rep1,
typename _Period1,
typename _Rep2,
typename _Period2>
93 struct common_type<chrono::duration<_Rep1, _Period1>,
94 chrono::duration<_Rep2, _Period2>>
95 :
public __duration_common_type_wrapper<typename __member_type_wrapper<
96 common_type<_Rep1, _Rep2>>::type, _Period1, _Period2>::type
101 template<
typename _CT,
typename _Clock>
102 struct __timepoint_common_type_wrapper
104 typedef __success_type<chrono::time_point<_Clock, typename _CT::type>>
108 template<
typename _Clock>
109 struct __timepoint_common_type_wrapper<__failure_type, _Clock>
110 {
typedef __failure_type type; };
112 template<
typename _Clock,
typename _Duration1,
typename _Duration2>
113 struct common_type<chrono::time_point<_Clock, _Duration1>,
114 chrono::time_point<_Clock, _Duration2>>
115 :
public __timepoint_common_type_wrapper<typename __member_type_wrapper<
116 common_type<_Duration1, _Duration2>>::type, _Clock>::type
119 _GLIBCXX_END_NAMESPACE_VERSION
123 _GLIBCXX_BEGIN_NAMESPACE_VERSION
126 template<
typename _ToDur,
typename _CF,
typename _CR,
127 bool _NumIsOne =
false,
bool _DenIsOne =
false>
128 struct __duration_cast_impl
130 template<
typename _Rep,
typename _Period>
131 static constexpr _ToDur
132 __cast(
const duration<_Rep, _Period>& __d)
134 typedef typename _ToDur::rep __to_rep;
135 return _ToDur(static_cast<__to_rep>(static_cast<_CR>(__d.count())
136 * static_cast<_CR>(_CF::num)
137 /
static_cast<_CR
>(_CF::den)));
141 template<
typename _ToDur,
typename _CF,
typename _CR>
142 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
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>(__d.count()));
153 template<
typename _ToDur,
typename _CF,
typename _CR>
154 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
156 template<
typename _Rep,
typename _Period>
157 static constexpr _ToDur
158 __cast(
const duration<_Rep, _Period>& __d)
160 typedef typename _ToDur::rep __to_rep;
161 return _ToDur(static_cast<__to_rep>(
162 static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den)));
166 template<
typename _ToDur,
typename _CF,
typename _CR>
167 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
169 template<
typename _Rep,
typename _Period>
170 static constexpr _ToDur
171 __cast(
const duration<_Rep, _Period>& __d)
173 typedef typename _ToDur::rep __to_rep;
174 return _ToDur(static_cast<__to_rep>(
175 static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num)));
179 template<
typename _Tp>
184 template<
typename _Rep,
typename _Period>
185 struct __is_duration<duration<_Rep, _Period>>
190 template<
typename _ToDur,
typename _Rep,
typename _Period>
191 constexpr
typename enable_if<__is_duration<_ToDur>::value,
195 typedef typename _ToDur::period __to_period;
196 typedef typename _ToDur::rep __to_rep;
200 typedef __duration_cast_impl<_ToDur, __cf, __cr,
201 __cf::num == 1, __cf::den == 1> __dc;
202 return __dc::__cast(__d);
206 template<
typename _Rep>
212 template<
typename _Rep>
215 static constexpr _Rep
219 static constexpr _Rep
223 static constexpr _Rep
228 template<
typename _Tp>
233 template<
intmax_t _Num,
intmax_t _Den>
234 struct __is_ratio<
ratio<_Num, _Den>>
239 template<
typename _Rep,
typename _Period>
243 typedef _Period period;
245 static_assert(!__is_duration<_Rep>::value,
"rep cannot be a duration");
246 static_assert(__is_ratio<_Period>::value,
247 "period must be a specialization of ratio");
248 static_assert(_Period::num > 0,
"period must be positive");
251 constexpr duration() =
default;
256 duration(
const duration&) =
default;
258 template<
typename _Rep2,
typename =
typename
259 enable_if<is_convertible<_Rep2, rep>::value
260 && (treat_as_floating_point<rep>::value
261 || !treat_as_floating_point<_Rep2>::value)>::type>
262 constexpr
explicit duration(
const _Rep2& __rep)
263 : __r(static_cast<rep>(__rep)) { }
265 template<
typename _Rep2,
typename _Period2,
typename =
typename
266 enable_if<treat_as_floating_point<rep>::value
267 || (ratio_divide<_Period2, period>::den == 1
268 && !treat_as_floating_point<_Rep2>::value)>::type>
269 constexpr duration(
const duration<_Rep2, _Period2>& __d)
270 : __r(duration_cast<duration>(__d).
count()) { }
272 ~duration() =
default;
273 duration& operator=(
const duration&) =
default;
287 {
return duration(-__r); }
298 {
return duration(__r++); }
309 {
return duration(__r--); }
312 operator+=(
const duration& __d)
319 operator-=(
const duration& __d)
326 operator*=(
const rep& __rhs)
333 operator/=(
const rep& __rhs)
340 template<
typename _Rep2 = rep>
341 typename enable_if<!treat_as_floating_point<_Rep2>::value,
343 operator%=(
const rep& __rhs)
349 template<
typename _Rep2 = rep>
350 typename enable_if<!treat_as_floating_point<_Rep2>::value,
352 operator%=(
const duration& __d)
359 static constexpr duration
361 {
return duration(duration_values<rep>::zero()); }
363 static constexpr duration
367 static constexpr duration
375 template<
typename _Rep1,
typename _Period1,
376 typename _Rep2,
typename _Period2>
377 constexpr
typename common_type<duration<_Rep1, _Period1>,
378 duration<_Rep2, _Period2>>::type
379 operator+(
const duration<_Rep1, _Period1>& __lhs,
380 const duration<_Rep2, _Period2>& __rhs)
382 typedef duration<_Rep1, _Period1> __dur1;
383 typedef duration<_Rep2, _Period2> __dur2;
384 typedef typename common_type<__dur1,__dur2>::type __cd;
385 return __cd(__cd(__lhs).
count() + __cd(__rhs).
count());
388 template<
typename _Rep1,
typename _Period1,
389 typename _Rep2,
typename _Period2>
390 constexpr
typename common_type<duration<_Rep1, _Period1>,
391 duration<_Rep2, _Period2>>::type
392 operator-(
const duration<_Rep1, _Period1>& __lhs,
393 const duration<_Rep2, _Period2>& __rhs)
395 typedef duration<_Rep1, _Period1> __dur1;
396 typedef duration<_Rep2, _Period2> __dur2;
397 typedef typename common_type<__dur1,__dur2>::type __cd;
398 return __cd(__cd(__lhs).
count() - __cd(__rhs).
count());
401 template<
typename _Rep1,
typename _Rep2,
bool =
402 is_convertible<_Rep2,
403 typename common_type<_Rep1, _Rep2>::type>::value>
404 struct __common_rep_type { };
406 template<
typename _Rep1,
typename _Rep2>
407 struct __common_rep_type<_Rep1, _Rep2, true>
408 {
typedef typename common_type<_Rep1, _Rep2>::type type; };
410 template<
typename _Rep1,
typename _Period,
typename _Rep2>
412 duration<typename __common_rep_type<_Rep1, _Rep2>::type, _Period>
413 operator*(
const duration<_Rep1, _Period>& __d,
const _Rep2& __s)
415 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
417 return __cd(__cd(__d).
count() * __s);
420 template<
typename _Rep1,
typename _Rep2,
typename _Period>
422 duration<typename __common_rep_type<_Rep2, _Rep1>::type, _Period>
423 operator*(
const _Rep1& __s,
const duration<_Rep2, _Period>& __d)
424 {
return __d * __s; }
426 template<
typename _Rep1,
typename _Period,
typename _Rep2>
427 constexpr duration<
typename __common_rep_type<_Rep1,
typename
428 enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period>
429 operator/(
const duration<_Rep1, _Period>& __d,
const _Rep2& __s)
431 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
433 return __cd(__cd(__d).
count() / __s);
436 template<
typename _Rep1,
typename _Period1,
437 typename _Rep2,
typename _Period2>
438 constexpr
typename common_type<_Rep1, _Rep2>::type
439 operator/(
const duration<_Rep1, _Period1>& __lhs,
440 const duration<_Rep2, _Period2>& __rhs)
442 typedef duration<_Rep1, _Period1> __dur1;
443 typedef duration<_Rep2, _Period2> __dur2;
444 typedef typename common_type<__dur1,__dur2>::type __cd;
445 return __cd(__lhs).count() / __cd(__rhs).count();
449 template<
typename _Rep1,
typename _Period,
typename _Rep2>
450 constexpr duration<
typename __common_rep_type<_Rep1,
typename
451 enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period>
452 operator%(
const duration<_Rep1, _Period>& __d,
const _Rep2& __s)
454 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
456 return __cd(__cd(__d).
count() % __s);
459 template<
typename _Rep1,
typename _Period1,
460 typename _Rep2,
typename _Period2>
461 constexpr
typename common_type<duration<_Rep1, _Period1>,
462 duration<_Rep2, _Period2>>::type
463 operator%(
const duration<_Rep1, _Period1>& __lhs,
464 const duration<_Rep2, _Period2>& __rhs)
466 typedef duration<_Rep1, _Period1> __dur1;
467 typedef duration<_Rep2, _Period2> __dur2;
468 typedef typename common_type<__dur1,__dur2>::type __cd;
469 return __cd(__cd(__lhs).
count() % __cd(__rhs).
count());
473 template<
typename _Rep1,
typename _Period1,
474 typename _Rep2,
typename _Period2>
476 operator==(
const duration<_Rep1, _Period1>& __lhs,
477 const duration<_Rep2, _Period2>& __rhs)
479 typedef duration<_Rep1, _Period1> __dur1;
480 typedef duration<_Rep2, _Period2> __dur2;
481 typedef typename common_type<__dur1,__dur2>::type __ct;
482 return __ct(__lhs).count() == __ct(__rhs).count();
485 template<
typename _Rep1,
typename _Period1,
486 typename _Rep2,
typename _Period2>
488 operator<(const duration<_Rep1, _Period1>& __lhs,
489 const duration<_Rep2, _Period2>& __rhs)
491 typedef duration<_Rep1, _Period1> __dur1;
492 typedef duration<_Rep2, _Period2> __dur2;
493 typedef typename common_type<__dur1,__dur2>::type __ct;
494 return __ct(__lhs).count() < __ct(__rhs).count();
497 template<
typename _Rep1,
typename _Period1,
498 typename _Rep2,
typename _Period2>
500 operator!=(
const duration<_Rep1, _Period1>& __lhs,
501 const duration<_Rep2, _Period2>& __rhs)
502 {
return !(__lhs == __rhs); }
504 template<
typename _Rep1,
typename _Period1,
505 typename _Rep2,
typename _Period2>
507 operator<=(const duration<_Rep1, _Period1>& __lhs,
508 const duration<_Rep2, _Period2>& __rhs)
509 {
return !(__rhs < __lhs); }
511 template<
typename _Rep1,
typename _Period1,
512 typename _Rep2,
typename _Period2>
514 operator>(
const duration<_Rep1, _Period1>& __lhs,
515 const duration<_Rep2, _Period2>& __rhs)
516 {
return __rhs < __lhs; }
518 template<
typename _Rep1,
typename _Period1,
519 typename _Rep2,
typename _Period2>
521 operator>=(
const duration<_Rep1, _Period1>& __lhs,
522 const duration<_Rep2, _Period2>& __rhs)
523 {
return !(__lhs < __rhs); }
544 template<
typename _Clock,
typename _Dur>
547 typedef _Clock clock;
549 typedef typename duration::rep rep;
550 typedef typename duration::period period;
552 constexpr
time_point() : __d(duration::zero())
555 constexpr
explicit time_point(
const duration& __dur)
560 template<
typename _Dur2>
562 : __d(__t.time_since_epoch())
567 time_since_epoch()
const
586 static constexpr time_point
590 static constexpr time_point
599 template<
typename _ToDur,
typename _Clock,
typename _Dur>
601 time_point<_Clock, _ToDur>>::type
605 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
608 template<
typename _Clock,
typename _Dur1,
609 typename _Rep2,
typename _Period2>
610 constexpr time_point<_Clock,
612 operator+(
const time_point<_Clock, _Dur1>& __lhs,
613 const duration<_Rep2, _Period2>& __rhs)
615 typedef duration<_Rep2, _Period2> __dur2;
617 typedef time_point<_Clock, __ct> __time_point;
618 return __time_point(__lhs.time_since_epoch() + __rhs);
621 template<
typename _Rep1,
typename _Period1,
622 typename _Clock,
typename _Dur2>
623 constexpr time_point<_Clock,
624 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
625 operator+(
const duration<_Rep1, _Period1>& __lhs,
626 const time_point<_Clock, _Dur2>& __rhs)
628 typedef duration<_Rep1, _Period1> __dur1;
629 typedef typename common_type<__dur1,_Dur2>::type __ct;
630 typedef time_point<_Clock, __ct> __time_point;
631 return __time_point(__rhs.time_since_epoch() + __lhs);
634 template<
typename _Clock,
typename _Dur1,
635 typename _Rep2,
typename _Period2>
636 constexpr time_point<_Clock,
637 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
638 operator-(
const time_point<_Clock, _Dur1>& __lhs,
639 const duration<_Rep2, _Period2>& __rhs)
641 typedef duration<_Rep2, _Period2> __dur2;
642 typedef typename common_type<_Dur1,__dur2>::type __ct;
643 typedef time_point<_Clock, __ct> __time_point;
644 return __time_point(__lhs.time_since_epoch() -__rhs);
647 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
648 constexpr
typename common_type<_Dur1, _Dur2>::type
649 operator-(
const time_point<_Clock, _Dur1>& __lhs,
650 const time_point<_Clock, _Dur2>& __rhs)
651 {
return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
653 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
655 operator==(
const time_point<_Clock, _Dur1>& __lhs,
656 const time_point<_Clock, _Dur2>& __rhs)
657 {
return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
659 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
661 operator!=(
const time_point<_Clock, _Dur1>& __lhs,
662 const time_point<_Clock, _Dur2>& __rhs)
663 {
return !(__lhs == __rhs); }
665 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
667 operator<(const time_point<_Clock, _Dur1>& __lhs,
668 const time_point<_Clock, _Dur2>& __rhs)
669 {
return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
671 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
673 operator<=(const time_point<_Clock, _Dur1>& __lhs,
674 const time_point<_Clock, _Dur2>& __rhs)
675 {
return !(__rhs < __lhs); }
677 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
679 operator>(
const time_point<_Clock, _Dur1>& __lhs,
680 const time_point<_Clock, _Dur2>& __rhs)
681 {
return __rhs < __lhs; }
683 template<
typename _Clock,
typename _Dur1,
typename _Dur2>
685 operator>=(
const time_point<_Clock, _Dur1>& __lhs,
686 const time_point<_Clock, _Dur2>& __rhs)
687 {
return !(__lhs < __rhs); }
708 inline namespace _V2 {
718 typedef duration::rep rep;
719 typedef duration::period period;
723 < system_clock::duration::zero(),
724 "a clock's minimum duration cannot be less than its epoch");
726 static constexpr
bool is_steady =
false;
735 return std::time_t(duration_cast<chrono::seconds>
736 (__t.time_since_epoch()).
count());
740 from_time_t(std::time_t __t) noexcept
757 typedef duration::rep rep;
758 typedef duration::period period;
761 static constexpr
bool is_steady =
true;
779 _GLIBCXX_END_NAMESPACE_VERSION
785 #endif //_GLIBCXX_USE_C99_STDINT_TR1
789 #endif //_GLIBCXX_CHRONO
complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
Define a member typedef type only if a boolean constant is true.
duration< int64_t > seconds
seconds
constexpr enable_if< __is_duration< _ToDur >::value, time_point< _Clock, _ToDur > >::type time_point_cast(const time_point< _Clock, _Dur > &__t)
time_point_cast
complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
typename __ratio_divide< _R1, _R2 >::type ratio_divide
ratio_divide
size_t count() const noexcept
Returns the number of bits which are set.
Provides compile-time rational arithmetic.
complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
duration< int64_t, milli > milliseconds
milliseconds
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
static constexpr _Tp lowest() noexcept
duration< int64_t, nano > nanoseconds
nanoseconds
const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr enable_if< __is_duration< _ToDur >::value, _ToDur >::type duration_cast(const duration< _Rep, _Period > &__d)
duration_cast
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
duration< int, ratio< 60 > > minutes
minutes
duration< int, ratio< 3600 > > hours
hours
duration< int64_t, micro > microseconds
microseconds
static constexpr _Tp max() noexcept