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"
115 explicit time_point(const duration& d); // same as time_point() + d
118 template <class Duration2>
119 time_point(const time_point<clock, Duration2>& t);
123 duration time_since_epoch() const;
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
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
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);
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;
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;
255 static time_point now() noexcept;
258 typedef steady_clock high_resolution_clock;
267 #include <type_traits>
271 #include <__undef_min_max>
273 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
274 #pragma GCC system_header
277 _LIBCPP_BEGIN_NAMESPACE_STD
282 template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS duration;
285 struct __is_duration : false_type {};
287 template <class _Rep, class _Period>
288 struct __is_duration<duration<_Rep, _Period> > : true_type {};
290 template <class _Rep, class _Period>
291 struct __is_duration<const duration<_Rep, _Period> > : true_type {};
293 template <class _Rep, class _Period>
294 struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
296 template <class _Rep, class _Period>
297 struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
301 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
302 struct _LIBCPP_TYPE_VIS common_type<chrono::duration<_Rep1, _Period1>,
303 chrono::duration<_Rep2, _Period2> >
305 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
306 typename __ratio_gcd<_Period1, _Period2>::type> type;
313 template <class _FromDuration, class _ToDuration,
314 class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
315 bool = _Period::num == 1,
316 bool = _Period::den == 1>
317 struct __duration_cast;
319 template <class _FromDuration, class _ToDuration, class _Period>
320 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
322 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
323 _ToDuration operator()(const _FromDuration& __fd) const
325 return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
329 template <class _FromDuration, class _ToDuration, class _Period>
330 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
332 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
333 _ToDuration operator()(const _FromDuration& __fd) const
335 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
336 return _ToDuration(static_cast<typename _ToDuration::rep>(
337 static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
341 template <class _FromDuration, class _ToDuration, class _Period>
342 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
344 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
345 _ToDuration operator()(const _FromDuration& __fd) const
347 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
348 return _ToDuration(static_cast<typename _ToDuration::rep>(
349 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
353 template <class _FromDuration, class _ToDuration, class _Period>
354 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
356 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
357 _ToDuration operator()(const _FromDuration& __fd) const
359 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
360 return _ToDuration(static_cast<typename _ToDuration::rep>(
361 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
362 / static_cast<_Ct>(_Period::den)));
366 template <class _ToDuration, class _Rep, class _Period>
367 inline _LIBCPP_INLINE_VISIBILITY
371 __is_duration<_ToDuration>::value,
374 duration_cast(const duration<_Rep, _Period>& __fd)
376 return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
379 template <class _Rep>
380 struct _LIBCPP_TYPE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
382 template <class _Rep>
383 struct _LIBCPP_TYPE_VIS duration_values
386 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);}
387 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() {return numeric_limits<_Rep>::max();}
388 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();}
393 template <class _Rep, class _Period>
394 class _LIBCPP_TYPE_VIS duration
396 static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
397 static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
398 static_assert(_Period::num > 0, "duration period must be positive");
401 typedef _Period period;
406 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration() {} // = default;
407 template <class _Rep2>
408 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
409 explicit duration(const _Rep2& __r,
412 is_convertible<_Rep2, rep>::value &&
413 (treat_as_floating_point<rep>::value ||
414 !treat_as_floating_point<_Rep2>::value)
419 template <class _Rep2, class _Period2>
420 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
421 duration(const duration<_Rep2, _Period2>& __d,
424 treat_as_floating_point<rep>::value ||
425 (ratio_divide<_Period2, period>::type::den == 1 &&
426 !treat_as_floating_point<_Rep2>::value)
428 : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
432 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
436 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;}
437 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);}
438 _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;}
439 _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);}
440 _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;}
441 _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);}
443 _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
444 _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
446 _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
447 _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
448 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
449 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
453 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
454 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values<rep>::min());}
455 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values<rep>::max());}
458 typedef duration<long long, nano> nanoseconds;
459 typedef duration<long long, micro> microseconds;
460 typedef duration<long long, milli> milliseconds;
461 typedef duration<long long > seconds;
462 typedef duration< long, ratio< 60> > minutes;
463 typedef duration< long, ratio<3600> > hours;
467 template <class _LhsDuration, class _RhsDuration>
470 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
471 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
473 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
474 return _Ct(__lhs).count() == _Ct(__rhs).count();
478 template <class _LhsDuration>
479 struct __duration_eq<_LhsDuration, _LhsDuration>
481 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
482 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
483 {return __lhs.count() == __rhs.count();}
486 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
487 inline _LIBCPP_INLINE_VISIBILITY
490 operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
492 return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
497 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
498 inline _LIBCPP_INLINE_VISIBILITY
501 operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
503 return !(__lhs == __rhs);
508 template <class _LhsDuration, class _RhsDuration>
511 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
512 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
514 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
515 return _Ct(__lhs).count() < _Ct(__rhs).count();
519 template <class _LhsDuration>
520 struct __duration_lt<_LhsDuration, _LhsDuration>
522 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
523 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
524 {return __lhs.count() < __rhs.count();}
527 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
528 inline _LIBCPP_INLINE_VISIBILITY
531 operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
533 return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
538 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
539 inline _LIBCPP_INLINE_VISIBILITY
542 operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
544 return __rhs < __lhs;
549 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
550 inline _LIBCPP_INLINE_VISIBILITY
553 operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
555 return !(__rhs < __lhs);
560 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
561 inline _LIBCPP_INLINE_VISIBILITY
564 operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
566 return !(__lhs < __rhs);
571 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
572 inline _LIBCPP_INLINE_VISIBILITY
574 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
575 operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
577 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
578 return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
583 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
584 inline _LIBCPP_INLINE_VISIBILITY
586 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
587 operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
589 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
590 return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
595 template <class _Rep1, class _Period, class _Rep2>
596 inline _LIBCPP_INLINE_VISIBILITY
600 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
601 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
603 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
605 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
606 typedef duration<_Cr, _Period> _Cd;
607 return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
610 template <class _Rep1, class _Period, class _Rep2>
611 inline _LIBCPP_INLINE_VISIBILITY
615 is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
616 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
618 operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
625 template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
626 struct __duration_divide_result
630 template <class _Duration, class _Rep2,
631 bool = is_convertible<_Rep2,
632 typename common_type<typename _Duration::rep, _Rep2>::type>::value>
633 struct __duration_divide_imp
637 template <class _Rep1, class _Period, class _Rep2>
638 struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
640 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
643 template <class _Rep1, class _Period, class _Rep2>
644 struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
645 : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
649 template <class _Rep1, class _Period, class _Rep2>
650 inline _LIBCPP_INLINE_VISIBILITY
652 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
653 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
655 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
656 typedef duration<_Cr, _Period> _Cd;
657 return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
660 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
661 inline _LIBCPP_INLINE_VISIBILITY
663 typename common_type<_Rep1, _Rep2>::type
664 operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
666 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
667 return _Ct(__lhs).count() / _Ct(__rhs).count();
672 template <class _Rep1, class _Period, class _Rep2>
673 inline _LIBCPP_INLINE_VISIBILITY
675 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
676 operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
678 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
679 typedef duration<_Cr, _Period> _Cd;
680 return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
683 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
684 inline _LIBCPP_INLINE_VISIBILITY
686 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
687 operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
689 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
690 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
691 return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
694 //////////////////////////////////////////////////////////
695 ///////////////////// time_point /////////////////////////
696 //////////////////////////////////////////////////////////
698 template <class _Clock, class _Duration = typename _Clock::duration>
699 class _LIBCPP_TYPE_VIS time_point
701 static_assert(__is_duration<_Duration>::value,
702 "Second template parameter of time_point must be a std::chrono::duration");
704 typedef _Clock clock;
705 typedef _Duration duration;
706 typedef typename duration::rep rep;
707 typedef typename duration::period period;
712 _LIBCPP_INLINE_VISIBILITY time_point() : __d_(duration::zero()) {}
713 _LIBCPP_INLINE_VISIBILITY explicit time_point(const duration& __d) : __d_(__d) {}
716 template <class _Duration2>
717 _LIBCPP_INLINE_VISIBILITY
718 time_point(const time_point<clock, _Duration2>& t,
721 is_convertible<_Duration2, duration>::value
723 : __d_(t.time_since_epoch()) {}
727 _LIBCPP_INLINE_VISIBILITY duration time_since_epoch() const {return __d_;}
731 _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
732 _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
736 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());}
737 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());}
742 template <class _Clock, class _Duration1, class _Duration2>
743 struct _LIBCPP_TYPE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
744 chrono::time_point<_Clock, _Duration2> >
746 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
751 template <class _ToDuration, class _Clock, class _Duration>
752 inline _LIBCPP_INLINE_VISIBILITY
753 time_point<_Clock, _ToDuration>
754 time_point_cast(const time_point<_Clock, _Duration>& __t)
756 return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
761 template <class _Clock, class _Duration1, class _Duration2>
762 inline _LIBCPP_INLINE_VISIBILITY
764 operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
766 return __lhs.time_since_epoch() == __rhs.time_since_epoch();
771 template <class _Clock, class _Duration1, class _Duration2>
772 inline _LIBCPP_INLINE_VISIBILITY
774 operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
776 return !(__lhs == __rhs);
781 template <class _Clock, class _Duration1, class _Duration2>
782 inline _LIBCPP_INLINE_VISIBILITY
784 operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
786 return __lhs.time_since_epoch() < __rhs.time_since_epoch();
791 template <class _Clock, class _Duration1, class _Duration2>
792 inline _LIBCPP_INLINE_VISIBILITY
794 operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
796 return __rhs < __lhs;
801 template <class _Clock, class _Duration1, class _Duration2>
802 inline _LIBCPP_INLINE_VISIBILITY
804 operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
806 return !(__rhs < __lhs);
811 template <class _Clock, class _Duration1, class _Duration2>
812 inline _LIBCPP_INLINE_VISIBILITY
814 operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
816 return !(__lhs < __rhs);
819 // time_point operator+(time_point x, duration y);
821 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
822 inline _LIBCPP_INLINE_VISIBILITY
823 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
824 operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
826 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
827 _Tr __r(__lhs.time_since_epoch());
832 // time_point operator+(duration x, time_point y);
834 template <class _Rep1, class _Period1, class _Clock, class _Duration2>
835 inline _LIBCPP_INLINE_VISIBILITY
836 time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
837 operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
839 return __rhs + __lhs;
842 // time_point operator-(time_point x, duration y);
844 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
845 inline _LIBCPP_INLINE_VISIBILITY
846 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
847 operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
849 return __lhs + (-__rhs);
852 // duration operator-(time_point x, time_point y);
854 template <class _Clock, class _Duration1, class _Duration2>
855 inline _LIBCPP_INLINE_VISIBILITY
856 typename common_type<_Duration1, _Duration2>::type
857 operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
859 return __lhs.time_since_epoch() - __rhs.time_since_epoch();
862 //////////////////////////////////////////////////////////
863 /////////////////////// clocks ///////////////////////////
864 //////////////////////////////////////////////////////////
866 class _LIBCPP_TYPE_VIS system_clock
869 typedef microseconds duration;
870 typedef duration::rep rep;
871 typedef duration::period period;
872 typedef chrono::time_point<system_clock> time_point;
873 static const bool is_steady = false;
875 static time_point now() _NOEXCEPT;
876 static time_t to_time_t (const time_point& __t) _NOEXCEPT;
877 static time_point from_time_t(time_t __t) _NOEXCEPT;
880 class _LIBCPP_TYPE_VIS steady_clock
883 typedef nanoseconds duration;
884 typedef duration::rep rep;
885 typedef duration::period period;
886 typedef chrono::time_point<steady_clock, duration> time_point;
887 static const bool is_steady = true;
889 static time_point now() _NOEXCEPT;
892 typedef steady_clock high_resolution_clock;
896 _LIBCPP_END_NAMESPACE_STD
898 #endif // _LIBCPP_CHRONO