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 // time_point arithmetic (all constexpr in C++14)
198 template <class Clock, class Duration1, class Rep2, class Period2>
199 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
200 operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
201 template <class Rep1, class Period1, class Clock, class Duration2>
202 time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
203 operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
204 template <class Clock, class Duration1, class Rep2, class Period2>
205 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
206 operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
207 template <class Clock, class Duration1, class Duration2>
208 typename common_type<Duration1, Duration2>::type
209 operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
211 // time_point comparisons (all constexpr in C++14)
212 template <class Clock, class Duration1, class Duration2>
213 bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
214 template <class Clock, class Duration1, class Duration2>
215 bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
216 template <class Clock, class Duration1, class Duration2>
217 bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
218 template <class Clock, class Duration1, class Duration2>
219 bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
220 template <class Clock, class Duration1, class Duration2>
221 bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
222 template <class Clock, class Duration1, class Duration2>
223 bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
225 // time_point_cast (constexpr in C++14)
227 template <class ToDuration, class Clock, class Duration>
228 time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
235 typedef microseconds duration;
236 typedef duration::rep rep;
237 typedef duration::period period;
238 typedef chrono::time_point<system_clock> time_point;
239 static const bool is_steady = false; // constexpr in C++14
241 static time_point now() noexcept;
242 static time_t to_time_t (const time_point& __t) noexcept;
243 static time_point from_time_t(time_t __t) noexcept;
249 typedef nanoseconds duration;
250 typedef duration::rep rep;
251 typedef duration::period period;
252 typedef chrono::time_point<steady_clock, duration> time_point;
253 static const bool is_steady = true; // constexpr in C++14
255 static time_point now() noexcept;
258 typedef steady_clock high_resolution_clock;
262 constexpr chrono::hours operator "" h(unsigned long long); // C++14
263 constexpr chrono::duration<unspecified , ratio<3600,1>> operator "" h(long double); // C++14
264 constexpr chrono::minutes operator "" min(unsigned long long); // C++14
265 constexpr chrono::duration<unspecified , ratio<60,1>> operator "" min(long double); // C++14
266 constexpr chrono::seconds operator "" s(unsigned long long); // C++14
267 constexpr chrono::duration<unspecified > operator "" s(long double); // C++14
268 constexpr chrono::milliseconds operator "" ms(unsigned long long); // C++14
269 constexpr chrono::duration<unspecified , milli> operator "" ms(long double); // C++14
270 constexpr chrono::microseconds operator "" us(unsigned long long); // C++14
271 constexpr chrono::duration<unspecified , micro> operator "" us(long double); // C++14
272 constexpr chrono::nanoseconds operator "" ns(unsigned long long); // C++14
273 constexpr chrono::duration<unspecified , nano> operator "" ns(long double); // C++14
280 #include <type_traits>
284 #include <__undef_min_max>
286 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
287 #pragma GCC system_header
290 _LIBCPP_BEGIN_NAMESPACE_STD
295 template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS_ONLY duration;
298 struct __is_duration : false_type {};
300 template <class _Rep, class _Period>
301 struct __is_duration<duration<_Rep, _Period> > : true_type {};
303 template <class _Rep, class _Period>
304 struct __is_duration<const duration<_Rep, _Period> > : true_type {};
306 template <class _Rep, class _Period>
307 struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
309 template <class _Rep, class _Period>
310 struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
314 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
315 struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::duration<_Rep1, _Period1>,
316 chrono::duration<_Rep2, _Period2> >
318 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
319 typename __ratio_gcd<_Period1, _Period2>::type> type;
326 template <class _FromDuration, class _ToDuration,
327 class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
328 bool = _Period::num == 1,
329 bool = _Period::den == 1>
330 struct __duration_cast;
332 template <class _FromDuration, class _ToDuration, class _Period>
333 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
335 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
336 _ToDuration operator()(const _FromDuration& __fd) const
338 return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
342 template <class _FromDuration, class _ToDuration, class _Period>
343 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
345 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
346 _ToDuration operator()(const _FromDuration& __fd) const
348 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
349 return _ToDuration(static_cast<typename _ToDuration::rep>(
350 static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
354 template <class _FromDuration, class _ToDuration, class _Period>
355 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
357 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
358 _ToDuration operator()(const _FromDuration& __fd) const
360 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
361 return _ToDuration(static_cast<typename _ToDuration::rep>(
362 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
366 template <class _FromDuration, class _ToDuration, class _Period>
367 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
369 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
370 _ToDuration operator()(const _FromDuration& __fd) const
372 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
373 return _ToDuration(static_cast<typename _ToDuration::rep>(
374 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
375 / static_cast<_Ct>(_Period::den)));
379 template <class _ToDuration, class _Rep, class _Period>
380 inline _LIBCPP_INLINE_VISIBILITY
384 __is_duration<_ToDuration>::value,
387 duration_cast(const duration<_Rep, _Period>& __fd)
389 return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
392 template <class _Rep>
393 struct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {};
395 template <class _Rep>
396 struct _LIBCPP_TYPE_VIS_ONLY duration_values
399 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);}
400 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() {return numeric_limits<_Rep>::max();}
401 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();}
406 template <class _Rep, class _Period>
407 class _LIBCPP_TYPE_VIS_ONLY duration
409 static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
410 static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
411 static_assert(_Period::num > 0, "duration period must be positive");
413 template <class _R1, class _R2>
417 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
418 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
419 static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
420 static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
421 static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
422 static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
423 static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
425 template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
426 struct __mul // __overflow == false
428 static const intmax_t value = _Xp * _Yp;
431 template <intmax_t _Xp, intmax_t _Yp>
432 struct __mul<_Xp, _Yp, true>
434 static const intmax_t value = 1;
438 static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
439 typedef ratio<__mul<__n1, __d2, !value>::value,
440 __mul<__n2, __d1, !value>::value> type;
445 typedef _Period period;
450 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
451 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
452 duration() = default;
457 template <class _Rep2>
458 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
459 explicit duration(const _Rep2& __r,
462 is_convertible<_Rep2, rep>::value &&
463 (treat_as_floating_point<rep>::value ||
464 !treat_as_floating_point<_Rep2>::value)
469 template <class _Rep2, class _Period2>
470 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
471 duration(const duration<_Rep2, _Period2>& __d,
474 __no_overflow<_Period2, period>::value && (
475 treat_as_floating_point<rep>::value ||
476 (__no_overflow<_Period2, period>::type::den == 1 &&
477 !treat_as_floating_point<_Rep2>::value))
479 : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
483 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
487 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;}
488 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);}
489 _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;}
490 _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);}
491 _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;}
492 _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);}
494 _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
495 _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
497 _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
498 _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
499 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
500 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
504 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
505 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values<rep>::min());}
506 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values<rep>::max());}
509 typedef duration<long long, nano> nanoseconds;
510 typedef duration<long long, micro> microseconds;
511 typedef duration<long long, milli> milliseconds;
512 typedef duration<long long > seconds;
513 typedef duration< long, ratio< 60> > minutes;
514 typedef duration< long, ratio<3600> > hours;
518 template <class _LhsDuration, class _RhsDuration>
521 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
522 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
524 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
525 return _Ct(__lhs).count() == _Ct(__rhs).count();
529 template <class _LhsDuration>
530 struct __duration_eq<_LhsDuration, _LhsDuration>
532 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
533 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
534 {return __lhs.count() == __rhs.count();}
537 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
538 inline _LIBCPP_INLINE_VISIBILITY
541 operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
543 return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
548 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
549 inline _LIBCPP_INLINE_VISIBILITY
552 operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
554 return !(__lhs == __rhs);
559 template <class _LhsDuration, class _RhsDuration>
562 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
563 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
565 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
566 return _Ct(__lhs).count() < _Ct(__rhs).count();
570 template <class _LhsDuration>
571 struct __duration_lt<_LhsDuration, _LhsDuration>
573 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
574 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
575 {return __lhs.count() < __rhs.count();}
578 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
579 inline _LIBCPP_INLINE_VISIBILITY
582 operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
584 return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
589 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
590 inline _LIBCPP_INLINE_VISIBILITY
593 operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
595 return __rhs < __lhs;
600 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
601 inline _LIBCPP_INLINE_VISIBILITY
604 operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
606 return !(__rhs < __lhs);
611 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
612 inline _LIBCPP_INLINE_VISIBILITY
615 operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
617 return !(__lhs < __rhs);
622 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
623 inline _LIBCPP_INLINE_VISIBILITY
625 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
626 operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
628 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
629 return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
634 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
635 inline _LIBCPP_INLINE_VISIBILITY
637 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
638 operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
640 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
641 return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
646 template <class _Rep1, class _Period, class _Rep2>
647 inline _LIBCPP_INLINE_VISIBILITY
651 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
652 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
654 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
656 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
657 typedef duration<_Cr, _Period> _Cd;
658 return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
661 template <class _Rep1, class _Period, class _Rep2>
662 inline _LIBCPP_INLINE_VISIBILITY
666 is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
667 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
669 operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
676 template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
677 struct __duration_divide_result
681 template <class _Duration, class _Rep2,
682 bool = is_convertible<_Rep2,
683 typename common_type<typename _Duration::rep, _Rep2>::type>::value>
684 struct __duration_divide_imp
688 template <class _Rep1, class _Period, class _Rep2>
689 struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
691 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
694 template <class _Rep1, class _Period, class _Rep2>
695 struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
696 : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
700 template <class _Rep1, class _Period, class _Rep2>
701 inline _LIBCPP_INLINE_VISIBILITY
703 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
704 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
706 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
707 typedef duration<_Cr, _Period> _Cd;
708 return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
711 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
712 inline _LIBCPP_INLINE_VISIBILITY
714 typename common_type<_Rep1, _Rep2>::type
715 operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
717 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
718 return _Ct(__lhs).count() / _Ct(__rhs).count();
723 template <class _Rep1, class _Period, class _Rep2>
724 inline _LIBCPP_INLINE_VISIBILITY
726 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
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 _Period1, class _Rep2, class _Period2>
735 inline _LIBCPP_INLINE_VISIBILITY
737 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
738 operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
740 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
741 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
742 return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
745 //////////////////////////////////////////////////////////
746 ///////////////////// time_point /////////////////////////
747 //////////////////////////////////////////////////////////
749 template <class _Clock, class _Duration = typename _Clock::duration>
750 class _LIBCPP_TYPE_VIS_ONLY time_point
752 static_assert(__is_duration<_Duration>::value,
753 "Second template parameter of time_point must be a std::chrono::duration");
755 typedef _Clock clock;
756 typedef _Duration duration;
757 typedef typename duration::rep rep;
758 typedef typename duration::period period;
763 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
764 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
767 template <class _Duration2>
768 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
769 time_point(const time_point<clock, _Duration2>& t,
772 is_convertible<_Duration2, duration>::value
774 : __d_(t.time_since_epoch()) {}
778 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
782 _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
783 _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
787 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());}
788 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());}
793 template <class _Clock, class _Duration1, class _Duration2>
794 struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::time_point<_Clock, _Duration1>,
795 chrono::time_point<_Clock, _Duration2> >
797 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
802 template <class _ToDuration, class _Clock, class _Duration>
803 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
804 time_point<_Clock, _ToDuration>
805 time_point_cast(const time_point<_Clock, _Duration>& __t)
807 return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
812 template <class _Clock, class _Duration1, class _Duration2>
813 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
815 operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
817 return __lhs.time_since_epoch() == __rhs.time_since_epoch();
822 template <class _Clock, class _Duration1, class _Duration2>
823 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
825 operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
827 return !(__lhs == __rhs);
832 template <class _Clock, class _Duration1, class _Duration2>
833 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
835 operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
837 return __lhs.time_since_epoch() < __rhs.time_since_epoch();
842 template <class _Clock, class _Duration1, class _Duration2>
843 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
845 operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
847 return __rhs < __lhs;
852 template <class _Clock, class _Duration1, class _Duration2>
853 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
855 operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
857 return !(__rhs < __lhs);
862 template <class _Clock, class _Duration1, class _Duration2>
863 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
865 operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
867 return !(__lhs < __rhs);
870 // time_point operator+(time_point x, duration y);
872 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
873 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
874 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
875 operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
877 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
878 return _Tr (__lhs.time_since_epoch() + __rhs);
881 // time_point operator+(duration x, time_point y);
883 template <class _Rep1, class _Period1, class _Clock, class _Duration2>
884 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
885 time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
886 operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
888 return __rhs + __lhs;
891 // time_point operator-(time_point x, duration y);
893 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
894 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
895 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
896 operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
898 return __lhs + (-__rhs);
901 // duration operator-(time_point x, time_point y);
903 template <class _Clock, class _Duration1, class _Duration2>
904 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
905 typename common_type<_Duration1, _Duration2>::type
906 operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
908 return __lhs.time_since_epoch() - __rhs.time_since_epoch();
911 //////////////////////////////////////////////////////////
912 /////////////////////// clocks ///////////////////////////
913 //////////////////////////////////////////////////////////
915 class _LIBCPP_TYPE_VIS system_clock
918 typedef microseconds duration;
919 typedef duration::rep rep;
920 typedef duration::period period;
921 typedef chrono::time_point<system_clock> time_point;
922 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
924 static time_point now() _NOEXCEPT;
925 static time_t to_time_t (const time_point& __t) _NOEXCEPT;
926 static time_point from_time_t(time_t __t) _NOEXCEPT;
929 #ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
930 class _LIBCPP_TYPE_VIS steady_clock
933 typedef nanoseconds duration;
934 typedef duration::rep rep;
935 typedef duration::period period;
936 typedef chrono::time_point<steady_clock, duration> time_point;
937 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
939 static time_point now() _NOEXCEPT;
942 typedef steady_clock high_resolution_clock;
944 typedef system_clock high_resolution_clock;
949 #if _LIBCPP_STD_VER > 11
950 // Suffixes for duration literals [time.duration.literals]
951 inline namespace literals
953 inline namespace chrono_literals
956 constexpr chrono::hours operator"" h(unsigned long long __h)
958 return chrono::hours(static_cast<chrono::hours::rep>(__h));
961 constexpr chrono::duration<long double, ratio<3600,1>> operator"" h(long double __h)
963 return chrono::duration<long double, ratio<3600,1>>(__h);
967 constexpr chrono::minutes operator"" min(unsigned long long __m)
969 return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
972 constexpr chrono::duration<long double, ratio<60,1>> operator"" min(long double __m)
974 return chrono::duration<long double, ratio<60,1>> (__m);
978 constexpr chrono::seconds operator"" s(unsigned long long __s)
980 return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
983 constexpr chrono::duration<long double> operator"" s(long double __s)
985 return chrono::duration<long double> (__s);
989 constexpr chrono::milliseconds operator"" ms(unsigned long long __ms)
991 return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
994 constexpr chrono::duration<long double, milli> operator"" ms(long double __ms)
996 return chrono::duration<long double, milli>(__ms);
1000 constexpr chrono::microseconds operator"" us(unsigned long long __us)
1002 return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
1005 constexpr chrono::duration<long double, micro> operator"" us(long double __us)
1007 return chrono::duration<long double, micro> (__us);
1011 constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns)
1013 return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
1016 constexpr chrono::duration<long double, nano> operator"" ns(long double __ns)
1018 return chrono::duration<long double, nano> (__ns);
1023 namespace chrono { // hoist the literals into namespace std::chrono
1024 using namespace literals::chrono_literals;
1029 _LIBCPP_END_NAMESPACE_STD
1031 #endif // _LIBCPP_CHRONO