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>
24 duration_cast(const duration<Rep, Period>& fd);
26 template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
29 struct duration_values
39 template <class Rep, class Period = ratio<1>>
42 static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
43 static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
44 static_assert(Period::num > 0, "duration period must be positive");
47 typedef Period period;
51 explicit duration(const Rep2& r,
54 is_convertible<Rep2, rep>::value &&
55 (treat_as_floating_point<rep>::value ||
56 !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
60 template <class Rep2, class Period2>
61 duration(const duration<Rep2, Period2>& d,
64 treat_as_floating_point<rep>::value ||
65 ratio_divide<Period2, period>::type::den == 1
74 duration operator+() const;
75 duration operator-() const;
76 duration& operator++();
77 duration operator++(int);
78 duration& operator--();
79 duration operator--(int);
81 duration& operator+=(const duration& d);
82 duration& operator-=(const duration& d);
84 duration& operator*=(const rep& rhs);
85 duration& operator/=(const rep& rhs);
89 static duration zero();
90 static duration min();
91 static duration max();
94 typedef duration<long long, nano> nanoseconds;
95 typedef duration<long long, micro> microseconds;
96 typedef duration<long long, milli> milliseconds;
97 typedef duration<long long > seconds;
98 typedef duration< long, ratio< 60> > minutes;
99 typedef duration< long, ratio<3600> > hours;
101 template <class Clock, class Duration = typename Clock::duration>
106 typedef Duration duration;
107 typedef typename duration::rep rep;
108 typedef typename duration::period period;
110 duration d_; // exposition only
113 time_point(); // has value "epoch"
114 explicit time_point(const duration& d); // same as time_point() + d
117 template <class Duration2>
118 time_point(const time_point<clock, Duration2>& t);
122 duration time_since_epoch() const;
126 time_point& operator+=(const duration& d);
127 time_point& operator-=(const duration& d);
131 static constexpr time_point min();
132 static constexpr time_point max();
137 // common_type traits
138 template <class Rep1, class Period1, class Rep2, class Period2>
139 struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
141 template <class Clock, class Duration1, class Duration2>
142 struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
146 // duration arithmetic
147 template <class Rep1, class Period1, class Rep2, class Period2>
148 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
149 operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
150 template <class Rep1, class Period1, class Rep2, class Period2>
151 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
152 operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
153 template <class Rep1, class Period, class Rep2>
154 duration<typename common_type<Rep1, Rep2>::type, Period>
155 operator*(const duration<Rep1, Period>& d, const Rep2& s);
156 template <class Rep1, class Period, class Rep2>
157 duration<typename common_type<Rep1, Rep2>::type, Period>
158 operator*(const Rep1& s, const duration<Rep2, Period>& d);
159 template <class Rep1, class Period, class Rep2>
160 duration<typename common_type<Rep1, Rep2>::type, Period>
161 operator/(const duration<Rep1, Period>& d, const Rep2& s);
162 template <class Rep1, class Period1, class Rep2, class Period2>
163 typename common_type<Rep1, Rep2>::type
164 operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
166 // duration comparisons
167 template <class Rep1, class Period1, class Rep2, class Period2>
168 bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
169 template <class Rep1, class Period1, class Rep2, class Period2>
170 bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
171 template <class Rep1, class Period1, class Rep2, class Period2>
172 bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
173 template <class Rep1, class Period1, class Rep2, class Period2>
174 bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
175 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>
178 bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
181 template <class ToDuration, class Rep, class Period>
182 ToDuration duration_cast(const duration<Rep, Period>& d);
184 // time_point arithmetic
185 template <class Clock, class Duration1, class Rep2, class Period2>
186 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
187 operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
188 template <class Rep1, class Period1, class Clock, class Duration2>
189 time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
190 operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
191 template <class Clock, class Duration1, class Rep2, class Period2>
192 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
193 operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
194 template <class Clock, class Duration1, class Duration2>
195 typename common_type<Duration1, Duration2>::type
196 operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
198 // time_point comparisons
199 template <class Clock, class Duration1, class Duration2>
200 bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
201 template <class Clock, class Duration1, class Duration2>
202 bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
203 template <class Clock, class Duration1, class Duration2>
204 bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
205 template <class Clock, class Duration1, class Duration2>
206 bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
207 template <class Clock, class Duration1, class Duration2>
208 bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
209 template <class Clock, class Duration1, class Duration2>
210 bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
214 template <class ToDuration, class Clock, class Duration>
215 time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
222 typedef microseconds duration;
223 typedef duration::rep rep;
224 typedef duration::period period;
225 typedef chrono::time_point<system_clock> time_point;
226 static const bool is_steady = false;
228 static time_point now() noexcept;
229 static time_t to_time_t (const time_point& __t) noexcept;
230 static time_point from_time_t(time_t __t) noexcept;
236 typedef nanoseconds duration;
237 typedef duration::rep rep;
238 typedef duration::period period;
239 typedef chrono::time_point<steady_clock, duration> time_point;
240 static const bool is_steady = true;
242 static time_point now() noexcept;
245 typedef steady_clock high_resolution_clock;
254 #include <type_traits>
258 #include <__undef_min_max>
260 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
261 #pragma GCC system_header
264 _LIBCPP_BEGIN_NAMESPACE_STD
269 template <class _Rep, class _Period = ratio<1> > class _LIBCPP_VISIBLE duration;
272 struct __is_duration : false_type {};
274 template <class _Rep, class _Period>
275 struct __is_duration<duration<_Rep, _Period> > : true_type {};
277 template <class _Rep, class _Period>
278 struct __is_duration<const duration<_Rep, _Period> > : true_type {};
280 template <class _Rep, class _Period>
281 struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
283 template <class _Rep, class _Period>
284 struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
288 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
289 struct _LIBCPP_VISIBLE common_type<chrono::duration<_Rep1, _Period1>,
290 chrono::duration<_Rep2, _Period2> >
292 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
293 typename __ratio_gcd<_Period1, _Period2>::type> type;
300 template <class _FromDuration, class _ToDuration,
301 class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
302 bool = _Period::num == 1,
303 bool = _Period::den == 1>
304 struct __duration_cast;
306 template <class _FromDuration, class _ToDuration, class _Period>
307 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
309 _LIBCPP_INLINE_VISIBILITY
310 _ToDuration operator()(const _FromDuration& __fd) const
312 return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
316 template <class _FromDuration, class _ToDuration, class _Period>
317 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
319 _LIBCPP_INLINE_VISIBILITY
320 _ToDuration operator()(const _FromDuration& __fd) const
322 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
323 return _ToDuration(static_cast<typename _ToDuration::rep>(
324 static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
328 template <class _FromDuration, class _ToDuration, class _Period>
329 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
331 _LIBCPP_INLINE_VISIBILITY
332 _ToDuration operator()(const _FromDuration& __fd) const
334 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
335 return _ToDuration(static_cast<typename _ToDuration::rep>(
336 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
340 template <class _FromDuration, class _ToDuration, class _Period>
341 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
343 _LIBCPP_INLINE_VISIBILITY
344 _ToDuration operator()(const _FromDuration& __fd) const
346 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
347 return _ToDuration(static_cast<typename _ToDuration::rep>(
348 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
349 / static_cast<_Ct>(_Period::den)));
353 template <class _ToDuration, class _Rep, class _Period>
354 inline _LIBCPP_INLINE_VISIBILITY
357 __is_duration<_ToDuration>::value,
360 duration_cast(const duration<_Rep, _Period>& __fd)
362 return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
365 template <class _Rep>
366 struct _LIBCPP_VISIBLE treat_as_floating_point : is_floating_point<_Rep> {};
368 template <class _Rep>
369 struct _LIBCPP_VISIBLE duration_values
372 _LIBCPP_INLINE_VISIBILITY static _Rep zero() {return _Rep(0);}
373 _LIBCPP_INLINE_VISIBILITY static _Rep max() {return numeric_limits<_Rep>::max();}
374 _LIBCPP_INLINE_VISIBILITY static _Rep min() {return numeric_limits<_Rep>::lowest();}
379 template <class _Rep, class _Period>
380 class _LIBCPP_VISIBLE duration
382 static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
383 static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
384 static_assert(_Period::num > 0, "duration period must be positive");
387 typedef _Period period;
392 _LIBCPP_INLINE_VISIBILITY duration() {} // = default;
393 template <class _Rep2>
394 _LIBCPP_INLINE_VISIBILITY
395 explicit duration(const _Rep2& __r,
398 is_convertible<_Rep2, rep>::value &&
399 (treat_as_floating_point<rep>::value ||
400 !treat_as_floating_point<_Rep2>::value)
405 template <class _Rep2, class _Period2>
406 _LIBCPP_INLINE_VISIBILITY
407 duration(const duration<_Rep2, _Period2>& __d,
410 treat_as_floating_point<rep>::value ||
411 (ratio_divide<_Period2, period>::type::den == 1 &&
412 !treat_as_floating_point<_Rep2>::value)
414 : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
418 _LIBCPP_INLINE_VISIBILITY rep count() const {return __rep_;}
422 _LIBCPP_INLINE_VISIBILITY duration operator+() const {return *this;}
423 _LIBCPP_INLINE_VISIBILITY duration operator-() const {return duration(-__rep_);}
424 _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;}
425 _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);}
426 _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;}
427 _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);}
429 _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
430 _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
432 _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
433 _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
434 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
435 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
439 _LIBCPP_INLINE_VISIBILITY static duration zero() {return duration(duration_values<rep>::zero());}
440 _LIBCPP_INLINE_VISIBILITY static duration min() {return duration(duration_values<rep>::min());}
441 _LIBCPP_INLINE_VISIBILITY static duration max() {return duration(duration_values<rep>::max());}
444 typedef duration<long long, nano> nanoseconds;
445 typedef duration<long long, micro> microseconds;
446 typedef duration<long long, milli> milliseconds;
447 typedef duration<long long > seconds;
448 typedef duration< long, ratio< 60> > minutes;
449 typedef duration< long, ratio<3600> > hours;
453 template <class _LhsDuration, class _RhsDuration>
456 _LIBCPP_INLINE_VISIBILITY
457 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs)
459 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
460 return _Ct(__lhs).count() == _Ct(__rhs).count();
464 template <class _LhsDuration>
465 struct __duration_eq<_LhsDuration, _LhsDuration>
467 _LIBCPP_INLINE_VISIBILITY
468 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs)
469 {return __lhs.count() == __rhs.count();}
472 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
473 inline _LIBCPP_INLINE_VISIBILITY
475 operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
477 return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
482 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
483 inline _LIBCPP_INLINE_VISIBILITY
485 operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
487 return !(__lhs == __rhs);
492 template <class _LhsDuration, class _RhsDuration>
495 _LIBCPP_INLINE_VISIBILITY
496 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs)
498 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
499 return _Ct(__lhs).count() < _Ct(__rhs).count();
503 template <class _LhsDuration>
504 struct __duration_lt<_LhsDuration, _LhsDuration>
506 _LIBCPP_INLINE_VISIBILITY
507 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs)
508 {return __lhs.count() < __rhs.count();}
511 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
512 inline _LIBCPP_INLINE_VISIBILITY
514 operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
516 return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
521 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
522 inline _LIBCPP_INLINE_VISIBILITY
524 operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
526 return __rhs < __lhs;
531 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
532 inline _LIBCPP_INLINE_VISIBILITY
534 operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
536 return !(__rhs < __lhs);
541 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
542 inline _LIBCPP_INLINE_VISIBILITY
544 operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
546 return !(__lhs < __rhs);
551 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
552 inline _LIBCPP_INLINE_VISIBILITY
553 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
554 operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
556 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs;
563 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
564 inline _LIBCPP_INLINE_VISIBILITY
565 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
566 operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
568 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs;
575 template <class _Rep1, class _Period, class _Rep2>
576 inline _LIBCPP_INLINE_VISIBILITY
579 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
580 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
582 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
584 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
585 duration<_Cr, _Period> __r = __d;
586 __r *= static_cast<_Cr>(__s);
590 template <class _Rep1, class _Period, class _Rep2>
591 inline _LIBCPP_INLINE_VISIBILITY
594 is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
595 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
597 operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
604 template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
605 struct __duration_divide_result
609 template <class _Duration, class _Rep2,
610 bool = is_convertible<_Rep2,
611 typename common_type<typename _Duration::rep, _Rep2>::type>::value>
612 struct __duration_divide_imp
616 template <class _Rep1, class _Period, class _Rep2>
617 struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
619 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
622 template <class _Rep1, class _Period, class _Rep2>
623 struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
624 : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
628 template <class _Rep1, class _Period, class _Rep2>
629 inline _LIBCPP_INLINE_VISIBILITY
630 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
631 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
633 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
634 duration<_Cr, _Period> __r = __d;
635 __r /= static_cast<_Cr>(__s);
639 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
640 inline _LIBCPP_INLINE_VISIBILITY
641 typename common_type<_Rep1, _Rep2>::type
642 operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
644 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
645 return _Ct(__lhs).count() / _Ct(__rhs).count();
650 template <class _Rep1, class _Period, class _Rep2>
651 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 duration<_Cr, _Period> __r = __d;
657 __r %= static_cast<_Cr>(__s);
661 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
662 inline _LIBCPP_INLINE_VISIBILITY
663 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
664 operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
666 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs;
671 //////////////////////////////////////////////////////////
672 ///////////////////// time_point /////////////////////////
673 //////////////////////////////////////////////////////////
675 template <class _Clock, class _Duration = typename _Clock::duration>
676 class _LIBCPP_VISIBLE time_point
678 static_assert(__is_duration<_Duration>::value,
679 "Second template parameter of time_point must be a std::chrono::duration");
681 typedef _Clock clock;
682 typedef _Duration duration;
683 typedef typename duration::rep rep;
684 typedef typename duration::period period;
689 _LIBCPP_INLINE_VISIBILITY time_point() : __d_(duration::zero()) {}
690 _LIBCPP_INLINE_VISIBILITY explicit time_point(const duration& __d) : __d_(__d) {}
693 template <class _Duration2>
694 _LIBCPP_INLINE_VISIBILITY
695 time_point(const time_point<clock, _Duration2>& t,
698 is_convertible<_Duration2, duration>::value
700 : __d_(t.time_since_epoch()) {}
704 _LIBCPP_INLINE_VISIBILITY duration time_since_epoch() const {return __d_;}
708 _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d;}
709 _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d;}
713 _LIBCPP_INLINE_VISIBILITY static time_point min() {return time_point(duration::min());}
714 _LIBCPP_INLINE_VISIBILITY static time_point max() {return time_point(duration::max());}
719 template <class _Clock, class _Duration1, class _Duration2>
720 struct _LIBCPP_VISIBLE common_type<chrono::time_point<_Clock, _Duration1>,
721 chrono::time_point<_Clock, _Duration2> >
723 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
728 template <class _ToDuration, class _Clock, class _Duration>
729 inline _LIBCPP_INLINE_VISIBILITY
730 time_point<_Clock, _ToDuration>
731 time_point_cast(const time_point<_Clock, _Duration>& __t)
733 return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
738 template <class _Clock, class _Duration1, class _Duration2>
739 inline _LIBCPP_INLINE_VISIBILITY
741 operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
743 return __lhs.time_since_epoch() == __rhs.time_since_epoch();
748 template <class _Clock, class _Duration1, class _Duration2>
749 inline _LIBCPP_INLINE_VISIBILITY
751 operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
753 return !(__lhs == __rhs);
758 template <class _Clock, class _Duration1, class _Duration2>
759 inline _LIBCPP_INLINE_VISIBILITY
761 operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
763 return __lhs.time_since_epoch() < __rhs.time_since_epoch();
768 template <class _Clock, class _Duration1, class _Duration2>
769 inline _LIBCPP_INLINE_VISIBILITY
771 operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
773 return __rhs < __lhs;
778 template <class _Clock, class _Duration1, class _Duration2>
779 inline _LIBCPP_INLINE_VISIBILITY
781 operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
783 return !(__rhs < __lhs);
788 template <class _Clock, class _Duration1, class _Duration2>
789 inline _LIBCPP_INLINE_VISIBILITY
791 operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
793 return !(__lhs < __rhs);
796 // time_point operator+(time_point x, duration y);
798 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
799 inline _LIBCPP_INLINE_VISIBILITY
800 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
801 operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
803 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
804 _Tr __r(__lhs.time_since_epoch());
809 // time_point operator+(duration x, time_point y);
811 template <class _Rep1, class _Period1, class _Clock, class _Duration2>
812 inline _LIBCPP_INLINE_VISIBILITY
813 time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
814 operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
816 return __rhs + __lhs;
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 return __lhs + (-__rhs);
829 // duration operator-(time_point x, time_point y);
831 template <class _Clock, class _Duration1, class _Duration2>
832 inline _LIBCPP_INLINE_VISIBILITY
833 typename common_type<_Duration1, _Duration2>::type
834 operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
836 return __lhs.time_since_epoch() - __rhs.time_since_epoch();
839 //////////////////////////////////////////////////////////
840 /////////////////////// clocks ///////////////////////////
841 //////////////////////////////////////////////////////////
843 class _LIBCPP_VISIBLE system_clock
846 typedef microseconds duration;
847 typedef duration::rep rep;
848 typedef duration::period period;
849 typedef chrono::time_point<system_clock> time_point;
850 static const bool is_steady = false;
852 static time_point now() _NOEXCEPT;
853 static time_t to_time_t (const time_point& __t) _NOEXCEPT;
854 static time_point from_time_t(time_t __t) _NOEXCEPT;
857 class _LIBCPP_VISIBLE steady_clock
860 typedef nanoseconds duration;
861 typedef duration::rep rep;
862 typedef duration::period period;
863 typedef chrono::time_point<steady_clock, duration> time_point;
864 static const bool is_steady = true;
866 static time_point now() _NOEXCEPT;
869 typedef steady_clock high_resolution_clock;
873 _LIBCPP_END_NAMESPACE_STD
875 #endif // _LIBCPP_CHRONO