2 //===---------------------------- chrono ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_CHRONO
12 #define _LIBCPP_CHRONO
22 template <class ToDuration, class Rep, class Period>
25 duration_cast(const duration<Rep, Period>& fd);
27 template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
30 struct duration_values
33 static constexpr Rep zero();
34 static constexpr Rep max();
35 static constexpr Rep min();
40 template <class Rep, class Period = ratio<1>>
43 static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
44 static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
45 static_assert(Period::num > 0, "duration period must be positive");
48 typedef Period period;
50 constexpr duration() = default;
52 constexpr explicit duration(const Rep2& r,
55 is_convertible<Rep2, rep>::value &&
56 (treat_as_floating_point<rep>::value ||
57 !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
61 template <class Rep2, class Period2>
62 constexpr duration(const duration<Rep2, Period2>& d,
65 treat_as_floating_point<rep>::value ||
66 ratio_divide<Period2, period>::type::den == 1
71 constexpr rep count() const;
75 constexpr duration operator+() const;
76 constexpr duration operator-() const;
77 duration& operator++();
78 duration operator++(int);
79 duration& operator--();
80 duration operator--(int);
82 duration& operator+=(const duration& d);
83 duration& operator-=(const duration& d);
85 duration& operator*=(const rep& rhs);
86 duration& operator/=(const rep& rhs);
90 static constexpr duration zero();
91 static constexpr duration min();
92 static constexpr duration max();
95 typedef duration<long long, nano> nanoseconds;
96 typedef duration<long long, micro> microseconds;
97 typedef duration<long long, milli> milliseconds;
98 typedef duration<long long > seconds;
99 typedef duration< long, ratio< 60> > minutes;
100 typedef duration< long, ratio<3600> > hours;
102 template <class Clock, class Duration = typename Clock::duration>
107 typedef Duration duration;
108 typedef typename duration::rep rep;
109 typedef typename duration::period period;
111 duration d_; // exposition only
114 time_point(); // has value "epoch" // constexpr in C++14
115 explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14
118 template <class Duration2>
119 time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
123 duration time_since_epoch() const; // constexpr in C++14
127 time_point& operator+=(const duration& d);
128 time_point& operator-=(const duration& d);
132 static constexpr time_point min();
133 static constexpr time_point max();
138 // common_type traits
139 template <class Rep1, class Period1, class Rep2, class Period2>
140 struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
142 template <class Clock, class Duration1, class Duration2>
143 struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
147 // duration arithmetic
148 template <class Rep1, class Period1, class Rep2, class Period2>
150 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
151 operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
152 template <class Rep1, class Period1, class Rep2, class Period2>
154 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
155 operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
156 template <class Rep1, class Period, class Rep2>
158 duration<typename common_type<Rep1, Rep2>::type, Period>
159 operator*(const duration<Rep1, Period>& d, const Rep2& s);
160 template <class Rep1, class Period, class Rep2>
162 duration<typename common_type<Rep1, Rep2>::type, Period>
163 operator*(const Rep1& s, const duration<Rep2, Period>& d);
164 template <class Rep1, class Period, class Rep2>
166 duration<typename common_type<Rep1, Rep2>::type, Period>
167 operator/(const duration<Rep1, Period>& d, const Rep2& s);
168 template <class Rep1, class Period1, class Rep2, class Period2>
170 typename common_type<Rep1, Rep2>::type
171 operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
173 // duration comparisons
174 template <class Rep1, class Period1, class Rep2, class Period2>
176 bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
177 template <class Rep1, class Period1, class Rep2, class Period2>
179 bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
180 template <class Rep1, class Period1, class Rep2, class Period2>
182 bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
183 template <class Rep1, class Period1, class Rep2, class Period2>
185 bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
186 template <class Rep1, class Period1, class Rep2, class Period2>
188 bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
189 template <class Rep1, class Period1, class Rep2, class Period2>
191 bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
194 template <class ToDuration, class Rep, class Period>
195 ToDuration duration_cast(const duration<Rep, Period>& d);
197 template <class ToDuration, class Rep, class Period>
198 constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17
199 template <class ToDuration, class Rep, class Period>
200 constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17
201 template <class ToDuration, class Rep, class Period>
202 constexpr ToDuration round(const duration<Rep, Period>& d); // C++17
204 // time_point arithmetic (all constexpr in C++14)
205 template <class Clock, class Duration1, class Rep2, class Period2>
206 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
207 operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
208 template <class Rep1, class Period1, class Clock, class Duration2>
209 time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
210 operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
211 template <class Clock, class Duration1, class Rep2, class Period2>
212 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
213 operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
214 template <class Clock, class Duration1, class Duration2>
215 typename common_type<Duration1, Duration2>::type
216 operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
218 // time_point comparisons (all constexpr in C++14)
219 template <class Clock, class Duration1, class Duration2>
220 bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
221 template <class Clock, class Duration1, class Duration2>
222 bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
223 template <class Clock, class Duration1, class Duration2>
224 bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
225 template <class Clock, class Duration1, class Duration2>
226 bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
227 template <class Clock, class Duration1, class Duration2>
228 bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
229 template <class Clock, class Duration1, class Duration2>
230 bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
232 // time_point_cast (constexpr in C++14)
234 template <class ToDuration, class Clock, class Duration>
235 time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
237 template <class ToDuration, class Clock, class Duration>
238 constexpr time_point<Clock, ToDuration>
239 floor(const time_point<Clock, Duration>& tp); // C++17
241 template <class ToDuration, class Clock, class Duration>
242 constexpr time_point<Clock, ToDuration>
243 ceil(const time_point<Clock, Duration>& tp); // C++17
245 template <class ToDuration, class Clock, class Duration>
246 constexpr time_point<Clock, ToDuration>
247 round(const time_point<Clock, Duration>& tp); // C++17
249 template <class Rep, class Period>
250 constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17
256 typedef microseconds duration;
257 typedef duration::rep rep;
258 typedef duration::period period;
259 typedef chrono::time_point<system_clock> time_point;
260 static const bool is_steady = false; // constexpr in C++14
262 static time_point now() noexcept;
263 static time_t to_time_t (const time_point& __t) noexcept;
264 static time_point from_time_t(time_t __t) noexcept;
270 typedef nanoseconds duration;
271 typedef duration::rep rep;
272 typedef duration::period period;
273 typedef chrono::time_point<steady_clock, duration> time_point;
274 static const bool is_steady = true; // constexpr in C++14
276 static time_point now() noexcept;
279 typedef steady_clock high_resolution_clock;
283 constexpr chrono::hours operator "" h(unsigned long long); // C++14
284 constexpr chrono::duration<unspecified , ratio<3600,1>> operator "" h(long double); // C++14
285 constexpr chrono::minutes operator "" min(unsigned long long); // C++14
286 constexpr chrono::duration<unspecified , ratio<60,1>> operator "" min(long double); // C++14
287 constexpr chrono::seconds operator "" s(unsigned long long); // C++14
288 constexpr chrono::duration<unspecified > operator "" s(long double); // C++14
289 constexpr chrono::milliseconds operator "" ms(unsigned long long); // C++14
290 constexpr chrono::duration<unspecified , milli> operator "" ms(long double); // C++14
291 constexpr chrono::microseconds operator "" us(unsigned long long); // C++14
292 constexpr chrono::duration<unspecified , micro> operator "" us(long double); // C++14
293 constexpr chrono::nanoseconds operator "" ns(unsigned long long); // C++14
294 constexpr chrono::duration<unspecified , nano> operator "" ns(long double); // C++14
301 #include <type_traits>
305 #include <__undef_min_max>
307 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
308 #pragma GCC system_header
311 _LIBCPP_BEGIN_NAMESPACE_STD
316 template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS_ONLY duration;
319 struct __is_duration : false_type {};
321 template <class _Rep, class _Period>
322 struct __is_duration<duration<_Rep, _Period> > : true_type {};
324 template <class _Rep, class _Period>
325 struct __is_duration<const duration<_Rep, _Period> > : true_type {};
327 template <class _Rep, class _Period>
328 struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
330 template <class _Rep, class _Period>
331 struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
335 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
336 struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::duration<_Rep1, _Period1>,
337 chrono::duration<_Rep2, _Period2> >
339 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
340 typename __ratio_gcd<_Period1, _Period2>::type> type;
347 template <class _FromDuration, class _ToDuration,
348 class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
349 bool = _Period::num == 1,
350 bool = _Period::den == 1>
351 struct __duration_cast;
353 template <class _FromDuration, class _ToDuration, class _Period>
354 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
356 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
357 _ToDuration operator()(const _FromDuration& __fd) const
359 return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
363 template <class _FromDuration, class _ToDuration, class _Period>
364 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
366 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
367 _ToDuration operator()(const _FromDuration& __fd) const
369 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
370 return _ToDuration(static_cast<typename _ToDuration::rep>(
371 static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
375 template <class _FromDuration, class _ToDuration, class _Period>
376 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
378 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
379 _ToDuration operator()(const _FromDuration& __fd) const
381 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
382 return _ToDuration(static_cast<typename _ToDuration::rep>(
383 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
387 template <class _FromDuration, class _ToDuration, class _Period>
388 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
390 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
391 _ToDuration operator()(const _FromDuration& __fd) const
393 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
394 return _ToDuration(static_cast<typename _ToDuration::rep>(
395 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
396 / static_cast<_Ct>(_Period::den)));
400 template <class _ToDuration, class _Rep, class _Period>
401 inline _LIBCPP_INLINE_VISIBILITY
405 __is_duration<_ToDuration>::value,
408 duration_cast(const duration<_Rep, _Period>& __fd)
410 return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
413 template <class _Rep>
414 struct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {};
416 template <class _Rep>
417 struct _LIBCPP_TYPE_VIS_ONLY duration_values
420 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);}
421 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() {return numeric_limits<_Rep>::max();}
422 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();}
425 #if _LIBCPP_STD_VER > 14
426 template <class _ToDuration, class _Rep, class _Period>
427 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
430 __is_duration<_ToDuration>::value,
433 floor(const duration<_Rep, _Period>& __d)
435 _ToDuration __t = duration_cast<_ToDuration>(__d);
437 __t = __t - _ToDuration{1};
441 template <class _ToDuration, class _Rep, class _Period>
442 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
445 __is_duration<_ToDuration>::value,
448 ceil(const duration<_Rep, _Period>& __d)
450 _ToDuration __t = duration_cast<_ToDuration>(__d);
452 __t = __t + _ToDuration{1};
456 template <class _ToDuration, class _Rep, class _Period>
457 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
460 __is_duration<_ToDuration>::value,
463 round(const duration<_Rep, _Period>& __d)
465 _ToDuration __lower = floor<_ToDuration>(__d);
466 _ToDuration __upper = __lower + _ToDuration{1};
467 auto __lowerDiff = __d - __lower;
468 auto __upperDiff = __upper - __d;
469 if (__lowerDiff < __upperDiff)
471 if (__lowerDiff > __upperDiff)
473 return __lower.count() & 1 ? __upper : __lower;
479 template <class _Rep, class _Period>
480 class _LIBCPP_TYPE_VIS_ONLY duration
482 static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
483 static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
484 static_assert(_Period::num > 0, "duration period must be positive");
486 template <class _R1, class _R2>
490 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
491 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
492 static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
493 static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
494 static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
495 static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
496 static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
498 template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
499 struct __mul // __overflow == false
501 static const intmax_t value = _Xp * _Yp;
504 template <intmax_t _Xp, intmax_t _Yp>
505 struct __mul<_Xp, _Yp, true>
507 static const intmax_t value = 1;
511 static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
512 typedef ratio<__mul<__n1, __d2, !value>::value,
513 __mul<__n2, __d1, !value>::value> type;
518 typedef _Period period;
523 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
524 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
525 duration() = default;
530 template <class _Rep2>
531 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
532 explicit duration(const _Rep2& __r,
535 is_convertible<_Rep2, rep>::value &&
536 (treat_as_floating_point<rep>::value ||
537 !treat_as_floating_point<_Rep2>::value)
542 template <class _Rep2, class _Period2>
543 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
544 duration(const duration<_Rep2, _Period2>& __d,
547 __no_overflow<_Period2, period>::value && (
548 treat_as_floating_point<rep>::value ||
549 (__no_overflow<_Period2, period>::type::den == 1 &&
550 !treat_as_floating_point<_Rep2>::value))
552 : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
556 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
560 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;}
561 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);}
562 _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;}
563 _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);}
564 _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;}
565 _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);}
567 _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
568 _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
570 _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
571 _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
572 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
573 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
577 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
578 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values<rep>::min());}
579 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values<rep>::max());}
582 typedef duration<long long, nano> nanoseconds;
583 typedef duration<long long, micro> microseconds;
584 typedef duration<long long, milli> milliseconds;
585 typedef duration<long long > seconds;
586 typedef duration< long, ratio< 60> > minutes;
587 typedef duration< long, ratio<3600> > hours;
591 template <class _LhsDuration, class _RhsDuration>
594 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
595 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
597 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
598 return _Ct(__lhs).count() == _Ct(__rhs).count();
602 template <class _LhsDuration>
603 struct __duration_eq<_LhsDuration, _LhsDuration>
605 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
606 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
607 {return __lhs.count() == __rhs.count();}
610 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
611 inline _LIBCPP_INLINE_VISIBILITY
614 operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
616 return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
621 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
622 inline _LIBCPP_INLINE_VISIBILITY
625 operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
627 return !(__lhs == __rhs);
632 template <class _LhsDuration, class _RhsDuration>
635 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
636 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
638 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
639 return _Ct(__lhs).count() < _Ct(__rhs).count();
643 template <class _LhsDuration>
644 struct __duration_lt<_LhsDuration, _LhsDuration>
646 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
647 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
648 {return __lhs.count() < __rhs.count();}
651 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
652 inline _LIBCPP_INLINE_VISIBILITY
655 operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
657 return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
662 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
663 inline _LIBCPP_INLINE_VISIBILITY
666 operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
668 return __rhs < __lhs;
673 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
674 inline _LIBCPP_INLINE_VISIBILITY
677 operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
679 return !(__rhs < __lhs);
684 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
685 inline _LIBCPP_INLINE_VISIBILITY
688 operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
690 return !(__lhs < __rhs);
695 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
696 inline _LIBCPP_INLINE_VISIBILITY
698 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
699 operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
701 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
702 return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
707 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
708 inline _LIBCPP_INLINE_VISIBILITY
710 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
711 operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
713 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
714 return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
719 template <class _Rep1, class _Period, class _Rep2>
720 inline _LIBCPP_INLINE_VISIBILITY
724 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
725 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
727 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
729 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
730 typedef duration<_Cr, _Period> _Cd;
731 return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
734 template <class _Rep1, class _Period, class _Rep2>
735 inline _LIBCPP_INLINE_VISIBILITY
739 is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
740 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
742 operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
749 template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
750 struct __duration_divide_result
754 template <class _Duration, class _Rep2,
755 bool = is_convertible<_Rep2,
756 typename common_type<typename _Duration::rep, _Rep2>::type>::value>
757 struct __duration_divide_imp
761 template <class _Rep1, class _Period, class _Rep2>
762 struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
764 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
767 template <class _Rep1, class _Period, class _Rep2>
768 struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
769 : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
773 template <class _Rep1, class _Period, class _Rep2>
774 inline _LIBCPP_INLINE_VISIBILITY
776 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
777 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
779 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
780 typedef duration<_Cr, _Period> _Cd;
781 return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
784 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
785 inline _LIBCPP_INLINE_VISIBILITY
787 typename common_type<_Rep1, _Rep2>::type
788 operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
790 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
791 return _Ct(__lhs).count() / _Ct(__rhs).count();
796 template <class _Rep1, class _Period, class _Rep2>
797 inline _LIBCPP_INLINE_VISIBILITY
799 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
800 operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
802 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
803 typedef duration<_Cr, _Period> _Cd;
804 return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
807 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
808 inline _LIBCPP_INLINE_VISIBILITY
810 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
811 operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
813 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
814 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
815 return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
818 //////////////////////////////////////////////////////////
819 ///////////////////// time_point /////////////////////////
820 //////////////////////////////////////////////////////////
822 template <class _Clock, class _Duration = typename _Clock::duration>
823 class _LIBCPP_TYPE_VIS_ONLY time_point
825 static_assert(__is_duration<_Duration>::value,
826 "Second template parameter of time_point must be a std::chrono::duration");
828 typedef _Clock clock;
829 typedef _Duration duration;
830 typedef typename duration::rep rep;
831 typedef typename duration::period period;
836 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
837 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
840 template <class _Duration2>
841 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
842 time_point(const time_point<clock, _Duration2>& t,
845 is_convertible<_Duration2, duration>::value
847 : __d_(t.time_since_epoch()) {}
851 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
855 _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
856 _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
860 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());}
861 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());}
866 template <class _Clock, class _Duration1, class _Duration2>
867 struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::time_point<_Clock, _Duration1>,
868 chrono::time_point<_Clock, _Duration2> >
870 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
875 template <class _ToDuration, class _Clock, class _Duration>
876 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
877 time_point<_Clock, _ToDuration>
878 time_point_cast(const time_point<_Clock, _Duration>& __t)
880 return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
883 #if _LIBCPP_STD_VER > 14
884 template <class _ToDuration, class _Clock, class _Duration>
885 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
888 __is_duration<_ToDuration>::value,
889 time_point<_Clock, _ToDuration>
891 floor(const time_point<_Clock, _Duration>& __t)
893 return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
896 template <class _ToDuration, class _Clock, class _Duration>
897 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
900 __is_duration<_ToDuration>::value,
901 time_point<_Clock, _ToDuration>
903 ceil(const time_point<_Clock, _Duration>& __t)
905 return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
908 template <class _ToDuration, class _Clock, class _Duration>
909 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
912 __is_duration<_ToDuration>::value,
913 time_point<_Clock, _ToDuration>
915 round(const time_point<_Clock, _Duration>& __t)
917 return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
920 template <class _Rep, class _Period>
921 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
924 numeric_limits<_Rep>::is_signed,
925 duration<_Rep, _Period>
927 abs(duration<_Rep, _Period> __d)
929 return __d >= __d.zero() ? __d : -__d;
935 template <class _Clock, class _Duration1, class _Duration2>
936 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
938 operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
940 return __lhs.time_since_epoch() == __rhs.time_since_epoch();
945 template <class _Clock, class _Duration1, class _Duration2>
946 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
948 operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
950 return !(__lhs == __rhs);
955 template <class _Clock, class _Duration1, class _Duration2>
956 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
958 operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
960 return __lhs.time_since_epoch() < __rhs.time_since_epoch();
965 template <class _Clock, class _Duration1, class _Duration2>
966 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
968 operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
970 return __rhs < __lhs;
975 template <class _Clock, class _Duration1, class _Duration2>
976 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
978 operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
980 return !(__rhs < __lhs);
985 template <class _Clock, class _Duration1, class _Duration2>
986 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
988 operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
990 return !(__lhs < __rhs);
993 // time_point operator+(time_point x, duration y);
995 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
996 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
997 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
998 operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1000 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
1001 return _Tr (__lhs.time_since_epoch() + __rhs);
1004 // time_point operator+(duration x, time_point y);
1006 template <class _Rep1, class _Period1, class _Clock, class _Duration2>
1007 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1008 time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
1009 operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1011 return __rhs + __lhs;
1014 // time_point operator-(time_point x, duration y);
1016 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
1017 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1018 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
1019 operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1021 return __lhs + (-__rhs);
1024 // duration operator-(time_point x, time_point y);
1026 template <class _Clock, class _Duration1, class _Duration2>
1027 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1028 typename common_type<_Duration1, _Duration2>::type
1029 operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1031 return __lhs.time_since_epoch() - __rhs.time_since_epoch();
1034 //////////////////////////////////////////////////////////
1035 /////////////////////// clocks ///////////////////////////
1036 //////////////////////////////////////////////////////////
1038 class _LIBCPP_TYPE_VIS system_clock
1041 typedef microseconds duration;
1042 typedef duration::rep rep;
1043 typedef duration::period period;
1044 typedef chrono::time_point<system_clock> time_point;
1045 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
1047 static time_point now() _NOEXCEPT;
1048 static time_t to_time_t (const time_point& __t) _NOEXCEPT;
1049 static time_point from_time_t(time_t __t) _NOEXCEPT;
1052 #ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
1053 class _LIBCPP_TYPE_VIS steady_clock
1056 typedef nanoseconds duration;
1057 typedef duration::rep rep;
1058 typedef duration::period period;
1059 typedef chrono::time_point<steady_clock, duration> time_point;
1060 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
1062 static time_point now() _NOEXCEPT;
1065 typedef steady_clock high_resolution_clock;
1067 typedef system_clock high_resolution_clock;
1072 #if _LIBCPP_STD_VER > 11
1073 // Suffixes for duration literals [time.duration.literals]
1074 inline namespace literals
1076 inline namespace chrono_literals
1079 constexpr chrono::hours operator"" h(unsigned long long __h)
1081 return chrono::hours(static_cast<chrono::hours::rep>(__h));
1084 constexpr chrono::duration<long double, ratio<3600,1>> operator"" h(long double __h)
1086 return chrono::duration<long double, ratio<3600,1>>(__h);
1090 constexpr chrono::minutes operator"" min(unsigned long long __m)
1092 return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
1095 constexpr chrono::duration<long double, ratio<60,1>> operator"" min(long double __m)
1097 return chrono::duration<long double, ratio<60,1>> (__m);
1101 constexpr chrono::seconds operator"" s(unsigned long long __s)
1103 return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
1106 constexpr chrono::duration<long double> operator"" s(long double __s)
1108 return chrono::duration<long double> (__s);
1112 constexpr chrono::milliseconds operator"" ms(unsigned long long __ms)
1114 return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
1117 constexpr chrono::duration<long double, milli> operator"" ms(long double __ms)
1119 return chrono::duration<long double, milli>(__ms);
1123 constexpr chrono::microseconds operator"" us(unsigned long long __us)
1125 return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
1128 constexpr chrono::duration<long double, micro> operator"" us(long double __us)
1130 return chrono::duration<long double, micro> (__us);
1134 constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns)
1136 return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
1139 constexpr chrono::duration<long double, nano> operator"" ns(long double __ns)
1141 return chrono::duration<long double, nano> (__ns);
1146 namespace chrono { // hoist the literals into namespace std::chrono
1147 using namespace literals::chrono_literals;
1152 _LIBCPP_END_NAMESPACE_STD
1154 #endif // _LIBCPP_CHRONO