12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166 |
- // -*- C++ -*-
- //===---------------------------- chrono ----------------------------------===//
- //
- // The LLVM Compiler Infrastructure
- //
- // This file is dual licensed under the MIT and the University of Illinois Open
- // Source Licenses. See LICENSE.TXT for details.
- //
- //===----------------------------------------------------------------------===//
- #ifndef _LIBCPP_CHRONO
- #define _LIBCPP_CHRONO
- /*
- chrono synopsis
- namespace std
- {
- namespace chrono
- {
- template <class ToDuration, class Rep, class Period>
- constexpr
- ToDuration
- duration_cast(const duration<Rep, Period>& fd);
- template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
- template <class Rep> constexpr bool treat_as_floating_point_v
- = treat_as_floating_point<Rep>::value; // C++17
- template <class Rep>
- struct duration_values
- {
- public:
- static constexpr Rep zero();
- static constexpr Rep max();
- static constexpr Rep min();
- };
- // duration
- template <class Rep, class Period = ratio<1>>
- class duration
- {
- static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
- static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
- static_assert(Period::num > 0, "duration period must be positive");
- public:
- typedef Rep rep;
- typedef Period period;
- constexpr duration() = default;
- template <class Rep2>
- constexpr explicit duration(const Rep2& r,
- typename enable_if
- <
- is_convertible<Rep2, rep>::value &&
- (treat_as_floating_point<rep>::value ||
- !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
- >::type* = 0);
- // conversions
- template <class Rep2, class Period2>
- constexpr duration(const duration<Rep2, Period2>& d,
- typename enable_if
- <
- treat_as_floating_point<rep>::value ||
- ratio_divide<Period2, period>::type::den == 1
- >::type* = 0);
- // observer
- constexpr rep count() const;
- // arithmetic
- constexpr duration operator+() const;
- constexpr duration operator-() const;
- duration& operator++();
- duration operator++(int);
- duration& operator--();
- duration operator--(int);
- duration& operator+=(const duration& d);
- duration& operator-=(const duration& d);
- duration& operator*=(const rep& rhs);
- duration& operator/=(const rep& rhs);
- // special values
- static constexpr duration zero();
- static constexpr duration min();
- static constexpr duration max();
- };
- typedef duration<long long, nano> nanoseconds;
- typedef duration<long long, micro> microseconds;
- typedef duration<long long, milli> milliseconds;
- typedef duration<long long > seconds;
- typedef duration< long, ratio< 60> > minutes;
- typedef duration< long, ratio<3600> > hours;
- template <class Clock, class Duration = typename Clock::duration>
- class time_point
- {
- public:
- typedef Clock clock;
- typedef Duration duration;
- typedef typename duration::rep rep;
- typedef typename duration::period period;
- private:
- duration d_; // exposition only
- public:
- time_point(); // has value "epoch" // constexpr in C++14
- explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14
- // conversions
- template <class Duration2>
- time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
- // observer
- duration time_since_epoch() const; // constexpr in C++14
- // arithmetic
- time_point& operator+=(const duration& d);
- time_point& operator-=(const duration& d);
- // special values
- static constexpr time_point min();
- static constexpr time_point max();
- };
- } // chrono
- // common_type traits
- template <class Rep1, class Period1, class Rep2, class Period2>
- struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
- template <class Clock, class Duration1, class Duration2>
- struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
- namespace chrono {
- // duration arithmetic
- template <class Rep1, class Period1, class Rep2, class Period2>
- constexpr
- typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
- operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Rep1, class Period1, class Rep2, class Period2>
- constexpr
- typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
- operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Rep1, class Period, class Rep2>
- constexpr
- duration<typename common_type<Rep1, Rep2>::type, Period>
- operator*(const duration<Rep1, Period>& d, const Rep2& s);
- template <class Rep1, class Period, class Rep2>
- constexpr
- duration<typename common_type<Rep1, Rep2>::type, Period>
- operator*(const Rep1& s, const duration<Rep2, Period>& d);
- template <class Rep1, class Period, class Rep2>
- constexpr
- duration<typename common_type<Rep1, Rep2>::type, Period>
- operator/(const duration<Rep1, Period>& d, const Rep2& s);
- template <class Rep1, class Period1, class Rep2, class Period2>
- constexpr
- typename common_type<Rep1, Rep2>::type
- operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- // duration comparisons
- template <class Rep1, class Period1, class Rep2, class Period2>
- constexpr
- bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Rep1, class Period1, class Rep2, class Period2>
- constexpr
- bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Rep1, class Period1, class Rep2, class Period2>
- constexpr
- bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Rep1, class Period1, class Rep2, class Period2>
- constexpr
- bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Rep1, class Period1, class Rep2, class Period2>
- constexpr
- bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Rep1, class Period1, class Rep2, class Period2>
- constexpr
- bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- // duration_cast
- template <class ToDuration, class Rep, class Period>
- ToDuration duration_cast(const duration<Rep, Period>& d);
- template <class ToDuration, class Rep, class Period>
- constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17
- template <class ToDuration, class Rep, class Period>
- constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17
- template <class ToDuration, class Rep, class Period>
- constexpr ToDuration round(const duration<Rep, Period>& d); // C++17
- // time_point arithmetic (all constexpr in C++14)
- template <class Clock, class Duration1, class Rep2, class Period2>
- time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
- operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Rep1, class Period1, class Clock, class Duration2>
- time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
- operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
- template <class Clock, class Duration1, class Rep2, class Period2>
- time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
- operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- typename common_type<Duration1, Duration2>::type
- operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
- // time_point comparisons (all constexpr in C++14)
- template <class Clock, class Duration1, class Duration2>
- bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
- // time_point_cast (constexpr in C++14)
- template <class ToDuration, class Clock, class Duration>
- time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
- template <class ToDuration, class Clock, class Duration>
- constexpr time_point<Clock, ToDuration>
- floor(const time_point<Clock, Duration>& tp); // C++17
- template <class ToDuration, class Clock, class Duration>
- constexpr time_point<Clock, ToDuration>
- ceil(const time_point<Clock, Duration>& tp); // C++17
- template <class ToDuration, class Clock, class Duration>
- constexpr time_point<Clock, ToDuration>
- round(const time_point<Clock, Duration>& tp); // C++17
- template <class Rep, class Period>
- constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17
- // Clocks
- class system_clock
- {
- public:
- typedef microseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<system_clock> time_point;
- static const bool is_steady = false; // constexpr in C++14
- static time_point now() noexcept;
- static time_t to_time_t (const time_point& __t) noexcept;
- static time_point from_time_t(time_t __t) noexcept;
- };
- class steady_clock
- {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<steady_clock, duration> time_point;
- static const bool is_steady = true; // constexpr in C++14
- static time_point now() noexcept;
- };
- typedef steady_clock high_resolution_clock;
- } // chrono
- constexpr chrono::hours operator "" h(unsigned long long); // C++14
- constexpr chrono::duration<unspecified , ratio<3600,1>> operator "" h(long double); // C++14
- constexpr chrono::minutes operator "" min(unsigned long long); // C++14
- constexpr chrono::duration<unspecified , ratio<60,1>> operator "" min(long double); // C++14
- constexpr chrono::seconds operator "" s(unsigned long long); // C++14
- constexpr chrono::duration<unspecified > operator "" s(long double); // C++14
- constexpr chrono::milliseconds operator "" ms(unsigned long long); // C++14
- constexpr chrono::duration<unspecified , milli> operator "" ms(long double); // C++14
- constexpr chrono::microseconds operator "" us(unsigned long long); // C++14
- constexpr chrono::duration<unspecified , micro> operator "" us(long double); // C++14
- constexpr chrono::nanoseconds operator "" ns(unsigned long long); // C++14
- constexpr chrono::duration<unspecified , nano> operator "" ns(long double); // C++14
- } // std
- */
- // Not supported in SGX.
- #include <__config>
- #if !defined(_LIBCPP_SGX_CONFIG)
- #include <ctime>
- #include <type_traits>
- #include <ratio>
- #include <limits>
- #include <__undef_min_max>
- #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
- #pragma GCC system_header
- #endif
- _LIBCPP_BEGIN_NAMESPACE_STD
- namespace chrono
- {
- template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS_ONLY duration;
- template <class _Tp>
- struct __is_duration : false_type {};
- template <class _Rep, class _Period>
- struct __is_duration<duration<_Rep, _Period> > : true_type {};
- template <class _Rep, class _Period>
- struct __is_duration<const duration<_Rep, _Period> > : true_type {};
- template <class _Rep, class _Period>
- struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
- template <class _Rep, class _Period>
- struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
- } // chrono
- template <class _Rep1, class _Period1, class _Rep2, class _Period2>
- struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::duration<_Rep1, _Period1>,
- chrono::duration<_Rep2, _Period2> >
- {
- typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
- typename __ratio_gcd<_Period1, _Period2>::type> type;
- };
- namespace chrono {
- // duration_cast
- template <class _FromDuration, class _ToDuration,
- class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
- bool = _Period::num == 1,
- bool = _Period::den == 1>
- struct __duration_cast;
- template <class _FromDuration, class _ToDuration, class _Period>
- struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
- {
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- _ToDuration operator()(const _FromDuration& __fd) const
- {
- return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
- }
- };
- template <class _FromDuration, class _ToDuration, class _Period>
- struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
- {
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- _ToDuration operator()(const _FromDuration& __fd) const
- {
- typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
- return _ToDuration(static_cast<typename _ToDuration::rep>(
- static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
- }
- };
- template <class _FromDuration, class _ToDuration, class _Period>
- struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
- {
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- _ToDuration operator()(const _FromDuration& __fd) const
- {
- typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
- return _ToDuration(static_cast<typename _ToDuration::rep>(
- static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
- }
- };
- template <class _FromDuration, class _ToDuration, class _Period>
- struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
- {
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- _ToDuration operator()(const _FromDuration& __fd) const
- {
- typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
- return _ToDuration(static_cast<typename _ToDuration::rep>(
- static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
- / static_cast<_Ct>(_Period::den)));
- }
- };
- template <class _ToDuration, class _Rep, class _Period>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- typename enable_if
- <
- __is_duration<_ToDuration>::value,
- _ToDuration
- >::type
- duration_cast(const duration<_Rep, _Period>& __fd)
- {
- return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
- }
- template <class _Rep>
- struct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {};
- #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
- template <class _Rep> _LIBCPP_CONSTEXPR bool treat_as_floating_point_v
- = treat_as_floating_point<_Rep>::value;
- #endif
- template <class _Rep>
- struct _LIBCPP_TYPE_VIS_ONLY duration_values
- {
- public:
- _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);}
- _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() {return numeric_limits<_Rep>::max();}
- _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();}
- };
- #if _LIBCPP_STD_VER > 14
- template <class _ToDuration, class _Rep, class _Period>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- typename enable_if
- <
- __is_duration<_ToDuration>::value,
- _ToDuration
- >::type
- floor(const duration<_Rep, _Period>& __d)
- {
- _ToDuration __t = duration_cast<_ToDuration>(__d);
- if (__t > __d)
- __t = __t - _ToDuration{1};
- return __t;
- }
- template <class _ToDuration, class _Rep, class _Period>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- typename enable_if
- <
- __is_duration<_ToDuration>::value,
- _ToDuration
- >::type
- ceil(const duration<_Rep, _Period>& __d)
- {
- _ToDuration __t = duration_cast<_ToDuration>(__d);
- if (__t < __d)
- __t = __t + _ToDuration{1};
- return __t;
- }
- template <class _ToDuration, class _Rep, class _Period>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- typename enable_if
- <
- __is_duration<_ToDuration>::value,
- _ToDuration
- >::type
- round(const duration<_Rep, _Period>& __d)
- {
- _ToDuration __lower = floor<_ToDuration>(__d);
- _ToDuration __upper = __lower + _ToDuration{1};
- auto __lowerDiff = __d - __lower;
- auto __upperDiff = __upper - __d;
- if (__lowerDiff < __upperDiff)
- return __lower;
- if (__lowerDiff > __upperDiff)
- return __upper;
- return __lower.count() & 1 ? __upper : __lower;
- }
- #endif
- // duration
- template <class _Rep, class _Period>
- class _LIBCPP_TYPE_VIS_ONLY duration
- {
- static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
- static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
- static_assert(_Period::num > 0, "duration period must be positive");
- template <class _R1, class _R2>
- struct __no_overflow
- {
- private:
- static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
- static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
- static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
- static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
- static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
- static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
- static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
- template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
- struct __mul // __overflow == false
- {
- static const intmax_t value = _Xp * _Yp;
- };
- template <intmax_t _Xp, intmax_t _Yp>
- struct __mul<_Xp, _Yp, true>
- {
- static const intmax_t value = 1;
- };
- public:
- static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
- typedef ratio<__mul<__n1, __d2, !value>::value,
- __mul<__n2, __d1, !value>::value> type;
- };
-
- public:
- typedef _Rep rep;
- typedef _Period period;
- private:
- rep __rep_;
- public:
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
- duration() = default;
- #else
- duration() {}
- #endif
- template <class _Rep2>
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- explicit duration(const _Rep2& __r,
- typename enable_if
- <
- is_convertible<_Rep2, rep>::value &&
- (treat_as_floating_point<rep>::value ||
- !treat_as_floating_point<_Rep2>::value)
- >::type* = 0)
- : __rep_(__r) {}
- // conversions
- template <class _Rep2, class _Period2>
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- duration(const duration<_Rep2, _Period2>& __d,
- typename enable_if
- <
- __no_overflow<_Period2, period>::value && (
- treat_as_floating_point<rep>::value ||
- (__no_overflow<_Period2, period>::type::den == 1 &&
- !treat_as_floating_point<_Rep2>::value))
- >::type* = 0)
- : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
- // observer
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
- // arithmetic
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;}
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);}
- _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;}
- _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);}
- _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;}
- _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);}
- _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
- _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
- _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
- _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
- _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
- _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
- // special values
- _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
- _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values<rep>::min());}
- _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values<rep>::max());}
- };
- typedef duration<long long, nano> nanoseconds;
- typedef duration<long long, micro> microseconds;
- typedef duration<long long, milli> milliseconds;
- typedef duration<long long > seconds;
- typedef duration< long, ratio< 60> > minutes;
- typedef duration< long, ratio<3600> > hours;
- // Duration ==
- template <class _LhsDuration, class _RhsDuration>
- struct __duration_eq
- {
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
- {
- typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
- return _Ct(__lhs).count() == _Ct(__rhs).count();
- }
- };
- template <class _LhsDuration>
- struct __duration_eq<_LhsDuration, _LhsDuration>
- {
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
- {return __lhs.count() == __rhs.count();}
- };
- template <class _Rep1, class _Period1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- bool
- operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
- }
- // Duration !=
- template <class _Rep1, class _Period1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- bool
- operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- return !(__lhs == __rhs);
- }
- // Duration <
- template <class _LhsDuration, class _RhsDuration>
- struct __duration_lt
- {
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
- {
- typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
- return _Ct(__lhs).count() < _Ct(__rhs).count();
- }
- };
- template <class _LhsDuration>
- struct __duration_lt<_LhsDuration, _LhsDuration>
- {
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
- {return __lhs.count() < __rhs.count();}
- };
- template <class _Rep1, class _Period1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- bool
- operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
- }
- // Duration >
- template <class _Rep1, class _Period1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- bool
- operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- return __rhs < __lhs;
- }
- // Duration <=
- template <class _Rep1, class _Period1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- bool
- operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- return !(__rhs < __lhs);
- }
- // Duration >=
- template <class _Rep1, class _Period1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- bool
- operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- return !(__lhs < __rhs);
- }
- // Duration +
- template <class _Rep1, class _Period1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
- operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
- return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
- }
- // Duration -
- template <class _Rep1, class _Period1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
- operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
- return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
- }
- // Duration *
- template <class _Rep1, class _Period, class _Rep2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- typename enable_if
- <
- is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
- duration<typename common_type<_Rep1, _Rep2>::type, _Period>
- >::type
- operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
- {
- typedef typename common_type<_Rep1, _Rep2>::type _Cr;
- typedef duration<_Cr, _Period> _Cd;
- return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
- }
- template <class _Rep1, class _Period, class _Rep2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- typename enable_if
- <
- is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
- duration<typename common_type<_Rep1, _Rep2>::type, _Period>
- >::type
- operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
- {
- return __d * __s;
- }
- // Duration /
- template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
- struct __duration_divide_result
- {
- };
- template <class _Duration, class _Rep2,
- bool = is_convertible<_Rep2,
- typename common_type<typename _Duration::rep, _Rep2>::type>::value>
- struct __duration_divide_imp
- {
- };
- template <class _Rep1, class _Period, class _Rep2>
- struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
- {
- typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
- };
- template <class _Rep1, class _Period, class _Rep2>
- struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
- : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
- {
- };
- template <class _Rep1, class _Period, class _Rep2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
- operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
- {
- typedef typename common_type<_Rep1, _Rep2>::type _Cr;
- typedef duration<_Cr, _Period> _Cd;
- return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
- }
- template <class _Rep1, class _Period1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- typename common_type<_Rep1, _Rep2>::type
- operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
- return _Ct(__lhs).count() / _Ct(__rhs).count();
- }
- // Duration %
- template <class _Rep1, class _Period, class _Rep2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
- operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
- {
- typedef typename common_type<_Rep1, _Rep2>::type _Cr;
- typedef duration<_Cr, _Period> _Cd;
- return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
- }
- template <class _Rep1, class _Period1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR
- typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
- operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- typedef typename common_type<_Rep1, _Rep2>::type _Cr;
- typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
- return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
- }
- //////////////////////////////////////////////////////////
- ///////////////////// time_point /////////////////////////
- //////////////////////////////////////////////////////////
- template <class _Clock, class _Duration = typename _Clock::duration>
- class _LIBCPP_TYPE_VIS_ONLY time_point
- {
- static_assert(__is_duration<_Duration>::value,
- "Second template parameter of time_point must be a std::chrono::duration");
- public:
- typedef _Clock clock;
- typedef _Duration duration;
- typedef typename duration::rep rep;
- typedef typename duration::period period;
- private:
- duration __d_;
- public:
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
- // conversions
- template <class _Duration2>
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- time_point(const time_point<clock, _Duration2>& t,
- typename enable_if
- <
- is_convertible<_Duration2, duration>::value
- >::type* = 0)
- : __d_(t.time_since_epoch()) {}
- // observer
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
- // arithmetic
- _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
- _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
- // special values
- _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());}
- _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());}
- };
- } // chrono
- template <class _Clock, class _Duration1, class _Duration2>
- struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::time_point<_Clock, _Duration1>,
- chrono::time_point<_Clock, _Duration2> >
- {
- typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
- };
- namespace chrono {
- template <class _ToDuration, class _Clock, class _Duration>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- time_point<_Clock, _ToDuration>
- time_point_cast(const time_point<_Clock, _Duration>& __t)
- {
- return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
- }
- #if _LIBCPP_STD_VER > 14
- template <class _ToDuration, class _Clock, class _Duration>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- typename enable_if
- <
- __is_duration<_ToDuration>::value,
- time_point<_Clock, _ToDuration>
- >::type
- floor(const time_point<_Clock, _Duration>& __t)
- {
- return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
- }
- template <class _ToDuration, class _Clock, class _Duration>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- typename enable_if
- <
- __is_duration<_ToDuration>::value,
- time_point<_Clock, _ToDuration>
- >::type
- ceil(const time_point<_Clock, _Duration>& __t)
- {
- return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
- }
- template <class _ToDuration, class _Clock, class _Duration>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- typename enable_if
- <
- __is_duration<_ToDuration>::value,
- time_point<_Clock, _ToDuration>
- >::type
- round(const time_point<_Clock, _Duration>& __t)
- {
- return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
- }
- template <class _Rep, class _Period>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- typename enable_if
- <
- numeric_limits<_Rep>::is_signed,
- duration<_Rep, _Period>
- >::type
- abs(duration<_Rep, _Period> __d)
- {
- return __d >= __d.zero() ? __d : -__d;
- }
- #endif
- // time_point ==
- template <class _Clock, class _Duration1, class _Duration2>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- bool
- operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
- {
- return __lhs.time_since_epoch() == __rhs.time_since_epoch();
- }
- // time_point !=
- template <class _Clock, class _Duration1, class _Duration2>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- bool
- operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
- {
- return !(__lhs == __rhs);
- }
- // time_point <
- template <class _Clock, class _Duration1, class _Duration2>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- bool
- operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
- {
- return __lhs.time_since_epoch() < __rhs.time_since_epoch();
- }
- // time_point >
- template <class _Clock, class _Duration1, class _Duration2>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- bool
- operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
- {
- return __rhs < __lhs;
- }
- // time_point <=
- template <class _Clock, class _Duration1, class _Duration2>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- bool
- operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
- {
- return !(__rhs < __lhs);
- }
- // time_point >=
- template <class _Clock, class _Duration1, class _Duration2>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- bool
- operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
- {
- return !(__lhs < __rhs);
- }
- // time_point operator+(time_point x, duration y);
- template <class _Clock, class _Duration1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
- operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
- return _Tr (__lhs.time_since_epoch() + __rhs);
- }
- // time_point operator+(duration x, time_point y);
- template <class _Rep1, class _Period1, class _Clock, class _Duration2>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
- operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
- {
- return __rhs + __lhs;
- }
- // time_point operator-(time_point x, duration y);
- template <class _Clock, class _Duration1, class _Rep2, class _Period2>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
- operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
- {
- return __lhs + (-__rhs);
- }
- // duration operator-(time_point x, time_point y);
- template <class _Clock, class _Duration1, class _Duration2>
- inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
- typename common_type<_Duration1, _Duration2>::type
- operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
- {
- return __lhs.time_since_epoch() - __rhs.time_since_epoch();
- }
- //////////////////////////////////////////////////////////
- /////////////////////// clocks ///////////////////////////
- //////////////////////////////////////////////////////////
- class _LIBCPP_TYPE_VIS system_clock
- {
- public:
- typedef microseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<system_clock> time_point;
- static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
- static time_point now() _NOEXCEPT;
- static time_t to_time_t (const time_point& __t) _NOEXCEPT;
- static time_point from_time_t(time_t __t) _NOEXCEPT;
- };
- #ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
- class _LIBCPP_TYPE_VIS steady_clock
- {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<steady_clock, duration> time_point;
- static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
- static time_point now() _NOEXCEPT;
- };
- typedef steady_clock high_resolution_clock;
- #else
- typedef system_clock high_resolution_clock;
- #endif
- } // chrono
- #if _LIBCPP_STD_VER > 11
- // Suffixes for duration literals [time.duration.literals]
- inline namespace literals
- {
- inline namespace chrono_literals
- {
- constexpr chrono::hours operator"" h(unsigned long long __h)
- {
- return chrono::hours(static_cast<chrono::hours::rep>(__h));
- }
- constexpr chrono::duration<long double, ratio<3600,1>> operator"" h(long double __h)
- {
- return chrono::duration<long double, ratio<3600,1>>(__h);
- }
- constexpr chrono::minutes operator"" min(unsigned long long __m)
- {
- return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
- }
- constexpr chrono::duration<long double, ratio<60,1>> operator"" min(long double __m)
- {
- return chrono::duration<long double, ratio<60,1>> (__m);
- }
- constexpr chrono::seconds operator"" s(unsigned long long __s)
- {
- return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
- }
- constexpr chrono::duration<long double> operator"" s(long double __s)
- {
- return chrono::duration<long double> (__s);
- }
- constexpr chrono::milliseconds operator"" ms(unsigned long long __ms)
- {
- return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
- }
- constexpr chrono::duration<long double, milli> operator"" ms(long double __ms)
- {
- return chrono::duration<long double, milli>(__ms);
- }
- constexpr chrono::microseconds operator"" us(unsigned long long __us)
- {
- return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
- }
- constexpr chrono::duration<long double, micro> operator"" us(long double __us)
- {
- return chrono::duration<long double, micro> (__us);
- }
-
- constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns)
- {
- return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
- }
- constexpr chrono::duration<long double, nano> operator"" ns(long double __ns)
- {
- return chrono::duration<long double, nano> (__ns);
- }
- }}
- namespace chrono { // hoist the literals into namespace std::chrono
- using namespace literals::chrono_literals;
- }
- #endif
- _LIBCPP_END_NAMESPACE_STD
- #endif // !defined(_LIBCPP_SGX_CONFIG)
- #endif // _LIBCPP_CHRONO
|