1227825Stheraven// -*- C++ -*- 2227825Stheraven//===---------------------------- chrono ----------------------------------===// 3227825Stheraven// 4227825Stheraven// The LLVM Compiler Infrastructure 5227825Stheraven// 6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open 7227825Stheraven// Source Licenses. See LICENSE.TXT for details. 8227825Stheraven// 9227825Stheraven//===----------------------------------------------------------------------===// 10227825Stheraven 11227825Stheraven#ifndef _LIBCPP_CHRONO 12227825Stheraven#define _LIBCPP_CHRONO 13227825Stheraven 14227825Stheraven/* 15227825Stheraven chrono synopsis 16227825Stheraven 17227825Stheravennamespace std 18227825Stheraven{ 19227825Stheravennamespace chrono 20227825Stheraven{ 21227825Stheraven 22227825Stheraventemplate <class ToDuration, class Rep, class Period> 23241903Sdimconstexpr 24227825StheravenToDuration 25227825Stheravenduration_cast(const duration<Rep, Period>& fd); 26227825Stheraven 27227825Stheraventemplate <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {}; 28227825Stheraven 29227825Stheraventemplate <class Rep> 30227825Stheravenstruct duration_values 31227825Stheraven{ 32227825Stheravenpublic: 33241903Sdim static constexpr Rep zero(); 34241903Sdim static constexpr Rep max(); 35241903Sdim static constexpr Rep min(); 36227825Stheraven}; 37227825Stheraven 38227825Stheraven// duration 39227825Stheraven 40227825Stheraventemplate <class Rep, class Period = ratio<1>> 41227825Stheravenclass duration 42227825Stheraven{ 43227825Stheraven static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration"); 44227825Stheraven static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio"); 45227825Stheraven static_assert(Period::num > 0, "duration period must be positive"); 46227825Stheravenpublic: 47227825Stheraven typedef Rep rep; 48227825Stheraven typedef Period period; 49227825Stheraven 50241903Sdim constexpr duration() = default; 51227825Stheraven template <class Rep2> 52241903Sdim constexpr explicit duration(const Rep2& r, 53227825Stheraven typename enable_if 54227825Stheraven < 55227825Stheraven is_convertible<Rep2, rep>::value && 56227825Stheraven (treat_as_floating_point<rep>::value || 57227825Stheraven !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value) 58227825Stheraven >::type* = 0); 59227825Stheraven 60227825Stheraven // conversions 61227825Stheraven template <class Rep2, class Period2> 62241903Sdim constexpr duration(const duration<Rep2, Period2>& d, 63227825Stheraven typename enable_if 64227825Stheraven < 65227825Stheraven treat_as_floating_point<rep>::value || 66227825Stheraven ratio_divide<Period2, period>::type::den == 1 67227825Stheraven >::type* = 0); 68227825Stheraven 69227825Stheraven // observer 70227825Stheraven 71241903Sdim constexpr rep count() const; 72227825Stheraven 73227825Stheraven // arithmetic 74227825Stheraven 75241903Sdim constexpr duration operator+() const; 76241903Sdim constexpr duration operator-() const; 77227825Stheraven duration& operator++(); 78227825Stheraven duration operator++(int); 79227825Stheraven duration& operator--(); 80227825Stheraven duration operator--(int); 81227825Stheraven 82227825Stheraven duration& operator+=(const duration& d); 83227825Stheraven duration& operator-=(const duration& d); 84227825Stheraven 85227825Stheraven duration& operator*=(const rep& rhs); 86227825Stheraven duration& operator/=(const rep& rhs); 87227825Stheraven 88227825Stheraven // special values 89227825Stheraven 90241903Sdim static constexpr duration zero(); 91241903Sdim static constexpr duration min(); 92241903Sdim static constexpr duration max(); 93227825Stheraven}; 94227825Stheraven 95227825Stheraventypedef duration<long long, nano> nanoseconds; 96227825Stheraventypedef duration<long long, micro> microseconds; 97227825Stheraventypedef duration<long long, milli> milliseconds; 98227825Stheraventypedef duration<long long > seconds; 99227825Stheraventypedef duration< long, ratio< 60> > minutes; 100227825Stheraventypedef duration< long, ratio<3600> > hours; 101227825Stheraven 102227825Stheraventemplate <class Clock, class Duration = typename Clock::duration> 103227825Stheravenclass time_point 104227825Stheraven{ 105227825Stheravenpublic: 106227825Stheraven typedef Clock clock; 107227825Stheraven typedef Duration duration; 108227825Stheraven typedef typename duration::rep rep; 109227825Stheraven typedef typename duration::period period; 110227825Stheravenprivate: 111227825Stheraven duration d_; // exposition only 112227825Stheraven 113227825Stheravenpublic: 114262801Sdim time_point(); // has value "epoch" // constexpr in C++14 115262801Sdim explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14 116227825Stheraven 117227825Stheraven // conversions 118227825Stheraven template <class Duration2> 119262801Sdim time_point(const time_point<clock, Duration2>& t); // constexpr in C++14 120227825Stheraven 121227825Stheraven // observer 122227825Stheraven 123262801Sdim duration time_since_epoch() const; // constexpr in C++14 124227825Stheraven 125227825Stheraven // arithmetic 126227825Stheraven 127227825Stheraven time_point& operator+=(const duration& d); 128227825Stheraven time_point& operator-=(const duration& d); 129227825Stheraven 130227825Stheraven // special values 131227825Stheraven 132227825Stheraven static constexpr time_point min(); 133227825Stheraven static constexpr time_point max(); 134227825Stheraven}; 135227825Stheraven 136227825Stheraven} // chrono 137227825Stheraven 138227825Stheraven// common_type traits 139227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 140227825Stheraven struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>; 141227825Stheraven 142227825Stheraventemplate <class Clock, class Duration1, class Duration2> 143227825Stheraven struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>; 144227825Stheraven 145227825Stheravennamespace chrono { 146227825Stheraven 147227825Stheraven// duration arithmetic 148227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 149241903Sdim constexpr 150227825Stheraven typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type 151227825Stheraven operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 152227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 153241903Sdim constexpr 154227825Stheraven typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type 155227825Stheraven operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 156227825Stheraventemplate <class Rep1, class Period, class Rep2> 157241903Sdim constexpr 158227825Stheraven duration<typename common_type<Rep1, Rep2>::type, Period> 159227825Stheraven operator*(const duration<Rep1, Period>& d, const Rep2& s); 160227825Stheraventemplate <class Rep1, class Period, class Rep2> 161241903Sdim constexpr 162227825Stheraven duration<typename common_type<Rep1, Rep2>::type, Period> 163227825Stheraven operator*(const Rep1& s, const duration<Rep2, Period>& d); 164227825Stheraventemplate <class Rep1, class Period, class Rep2> 165241903Sdim constexpr 166227825Stheraven duration<typename common_type<Rep1, Rep2>::type, Period> 167227825Stheraven operator/(const duration<Rep1, Period>& d, const Rep2& s); 168227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 169241903Sdim constexpr 170227825Stheraven typename common_type<Rep1, Rep2>::type 171227825Stheraven operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 172227825Stheraven 173227825Stheraven// duration comparisons 174227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 175241903Sdim constexpr 176227825Stheraven bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 177227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 178241903Sdim constexpr 179227825Stheraven bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 180227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 181241903Sdim constexpr 182227825Stheraven bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 183227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 184241903Sdim constexpr 185227825Stheraven bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 186227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 187241903Sdim constexpr 188227825Stheraven bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 189227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 190241903Sdim constexpr 191227825Stheraven bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 192227825Stheraven 193227825Stheraven// duration_cast 194227825Stheraventemplate <class ToDuration, class Rep, class Period> 195227825Stheraven ToDuration duration_cast(const duration<Rep, Period>& d); 196227825Stheraven 197262801Sdim// time_point arithmetic (all constexpr in C++14) 198227825Stheraventemplate <class Clock, class Duration1, class Rep2, class Period2> 199227825Stheraven time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> 200227825Stheraven operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); 201227825Stheraventemplate <class Rep1, class Period1, class Clock, class Duration2> 202227825Stheraven time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> 203227825Stheraven operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs); 204227825Stheraventemplate <class Clock, class Duration1, class Rep2, class Period2> 205227825Stheraven time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> 206227825Stheraven operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); 207227825Stheraventemplate <class Clock, class Duration1, class Duration2> 208227825Stheraven typename common_type<Duration1, Duration2>::type 209227825Stheraven operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 210227825Stheraven 211262801Sdim// time_point comparisons (all constexpr in C++14) 212227825Stheraventemplate <class Clock, class Duration1, class Duration2> 213227825Stheraven bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 214227825Stheraventemplate <class Clock, class Duration1, class Duration2> 215227825Stheraven bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 216227825Stheraventemplate <class Clock, class Duration1, class Duration2> 217227825Stheraven bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 218227825Stheraventemplate <class Clock, class Duration1, class Duration2> 219227825Stheraven bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 220227825Stheraventemplate <class Clock, class Duration1, class Duration2> 221227825Stheraven bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 222227825Stheraventemplate <class Clock, class Duration1, class Duration2> 223227825Stheraven bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 224227825Stheraven 225262801Sdim// time_point_cast (constexpr in C++14) 226227825Stheraven 227227825Stheraventemplate <class ToDuration, class Clock, class Duration> 228227825Stheraven time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t); 229227825Stheraven 230227825Stheraven// Clocks 231227825Stheraven 232227825Stheravenclass system_clock 233227825Stheraven{ 234227825Stheravenpublic: 235227825Stheraven typedef microseconds duration; 236227825Stheraven typedef duration::rep rep; 237227825Stheraven typedef duration::period period; 238227825Stheraven typedef chrono::time_point<system_clock> time_point; 239262801Sdim static const bool is_steady = false; // constexpr in C++14 240227825Stheraven 241227825Stheraven static time_point now() noexcept; 242227825Stheraven static time_t to_time_t (const time_point& __t) noexcept; 243227825Stheraven static time_point from_time_t(time_t __t) noexcept; 244227825Stheraven}; 245227825Stheraven 246227825Stheravenclass steady_clock 247227825Stheraven{ 248227825Stheravenpublic: 249227825Stheraven typedef nanoseconds duration; 250227825Stheraven typedef duration::rep rep; 251227825Stheraven typedef duration::period period; 252227825Stheraven typedef chrono::time_point<steady_clock, duration> time_point; 253262801Sdim static const bool is_steady = true; // constexpr in C++14 254227825Stheraven 255227825Stheraven static time_point now() noexcept; 256227825Stheraven}; 257227825Stheraven 258227825Stheraventypedef steady_clock high_resolution_clock; 259227825Stheraven 260227825Stheraven} // chrono 261227825Stheraven 262262801Sdimconstexpr chrono::hours operator "" h(unsigned long long); // C++14 263262801Sdimconstexpr chrono::duration<unspecified , ratio<3600,1>> operator "" h(long double); // C++14 264262801Sdimconstexpr chrono::minutes operator "" min(unsigned long long); // C++14 265262801Sdimconstexpr chrono::duration<unspecified , ratio<60,1>> operator "" min(long double); // C++14 266262801Sdimconstexpr chrono::seconds operator "" s(unsigned long long); // C++14 267262801Sdimconstexpr chrono::duration<unspecified > operator "" s(long double); // C++14 268262801Sdimconstexpr chrono::milliseconds operator "" ms(unsigned long long); // C++14 269262801Sdimconstexpr chrono::duration<unspecified , milli> operator "" ms(long double); // C++14 270262801Sdimconstexpr chrono::microseconds operator "" us(unsigned long long); // C++14 271262801Sdimconstexpr chrono::duration<unspecified , micro> operator "" us(long double); // C++14 272262801Sdimconstexpr chrono::nanoseconds operator "" ns(unsigned long long); // C++14 273262801Sdimconstexpr chrono::duration<unspecified , nano> operator "" ns(long double); // C++14 274262801Sdim 275227825Stheraven} // std 276227825Stheraven*/ 277227825Stheraven 278227825Stheraven#include <__config> 279227825Stheraven#include <ctime> 280227825Stheraven#include <type_traits> 281227825Stheraven#include <ratio> 282227825Stheraven#include <limits> 283227825Stheraven 284232950Stheraven#include <__undef_min_max> 285232950Stheraven 286227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 287227825Stheraven#pragma GCC system_header 288227825Stheraven#endif 289227825Stheraven 290227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 291227825Stheraven 292227825Stheravennamespace chrono 293227825Stheraven{ 294227825Stheraven 295262801Sdimtemplate <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS_ONLY duration; 296227825Stheraven 297227825Stheraventemplate <class _Tp> 298227825Stheravenstruct __is_duration : false_type {}; 299227825Stheraven 300227825Stheraventemplate <class _Rep, class _Period> 301227825Stheravenstruct __is_duration<duration<_Rep, _Period> > : true_type {}; 302227825Stheraven 303227825Stheraventemplate <class _Rep, class _Period> 304227825Stheravenstruct __is_duration<const duration<_Rep, _Period> > : true_type {}; 305227825Stheraven 306227825Stheraventemplate <class _Rep, class _Period> 307227825Stheravenstruct __is_duration<volatile duration<_Rep, _Period> > : true_type {}; 308227825Stheraven 309227825Stheraventemplate <class _Rep, class _Period> 310227825Stheravenstruct __is_duration<const volatile duration<_Rep, _Period> > : true_type {}; 311227825Stheraven 312227825Stheraven} // chrono 313227825Stheraven 314227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 315262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::duration<_Rep1, _Period1>, 316262801Sdim chrono::duration<_Rep2, _Period2> > 317227825Stheraven{ 318227825Stheraven typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, 319227825Stheraven typename __ratio_gcd<_Period1, _Period2>::type> type; 320227825Stheraven}; 321227825Stheraven 322227825Stheravennamespace chrono { 323227825Stheraven 324227825Stheraven// duration_cast 325227825Stheraven 326227825Stheraventemplate <class _FromDuration, class _ToDuration, 327227825Stheraven class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type, 328227825Stheraven bool = _Period::num == 1, 329227825Stheraven bool = _Period::den == 1> 330227825Stheravenstruct __duration_cast; 331227825Stheraven 332227825Stheraventemplate <class _FromDuration, class _ToDuration, class _Period> 333227825Stheravenstruct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> 334227825Stheraven{ 335241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 336227825Stheraven _ToDuration operator()(const _FromDuration& __fd) const 337227825Stheraven { 338227825Stheraven return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count())); 339227825Stheraven } 340227825Stheraven}; 341227825Stheraven 342227825Stheraventemplate <class _FromDuration, class _ToDuration, class _Period> 343227825Stheravenstruct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> 344227825Stheraven{ 345241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 346227825Stheraven _ToDuration operator()(const _FromDuration& __fd) const 347227825Stheraven { 348227825Stheraven typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 349227825Stheraven return _ToDuration(static_cast<typename _ToDuration::rep>( 350227825Stheraven static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); 351227825Stheraven } 352227825Stheraven}; 353227825Stheraven 354227825Stheraventemplate <class _FromDuration, class _ToDuration, class _Period> 355227825Stheravenstruct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> 356227825Stheraven{ 357241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 358227825Stheraven _ToDuration operator()(const _FromDuration& __fd) const 359227825Stheraven { 360227825Stheraven typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 361227825Stheraven return _ToDuration(static_cast<typename _ToDuration::rep>( 362227825Stheraven static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); 363227825Stheraven } 364227825Stheraven}; 365227825Stheraven 366227825Stheraventemplate <class _FromDuration, class _ToDuration, class _Period> 367227825Stheravenstruct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> 368227825Stheraven{ 369241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 370227825Stheraven _ToDuration operator()(const _FromDuration& __fd) const 371227825Stheraven { 372227825Stheraven typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 373227825Stheraven return _ToDuration(static_cast<typename _ToDuration::rep>( 374227825Stheraven static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) 375227825Stheraven / static_cast<_Ct>(_Period::den))); 376227825Stheraven } 377227825Stheraven}; 378227825Stheraven 379227825Stheraventemplate <class _ToDuration, class _Rep, class _Period> 380227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 381241903Sdim_LIBCPP_CONSTEXPR 382227825Stheraventypename enable_if 383227825Stheraven< 384227825Stheraven __is_duration<_ToDuration>::value, 385227825Stheraven _ToDuration 386227825Stheraven>::type 387227825Stheravenduration_cast(const duration<_Rep, _Period>& __fd) 388227825Stheraven{ 389227825Stheraven return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd); 390227825Stheraven} 391227825Stheraven 392227825Stheraventemplate <class _Rep> 393262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {}; 394227825Stheraven 395227825Stheraventemplate <class _Rep> 396262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY duration_values 397227825Stheraven{ 398227825Stheravenpublic: 399241903Sdim _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);} 400241903Sdim _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() {return numeric_limits<_Rep>::max();} 401241903Sdim _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();} 402227825Stheraven}; 403227825Stheraven 404227825Stheraven// duration 405227825Stheraven 406227825Stheraventemplate <class _Rep, class _Period> 407262801Sdimclass _LIBCPP_TYPE_VIS_ONLY duration 408227825Stheraven{ 409227825Stheraven static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); 410227825Stheraven static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); 411227825Stheraven static_assert(_Period::num > 0, "duration period must be positive"); 412262801Sdim 413262801Sdim template <class _R1, class _R2> 414262801Sdim struct __no_overflow 415262801Sdim { 416262801Sdim private: 417262801Sdim static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; 418262801Sdim static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; 419262801Sdim static const intmax_t __n1 = _R1::num / __gcd_n1_n2; 420262801Sdim static const intmax_t __d1 = _R1::den / __gcd_d1_d2; 421262801Sdim static const intmax_t __n2 = _R2::num / __gcd_n1_n2; 422262801Sdim static const intmax_t __d2 = _R2::den / __gcd_d1_d2; 423262801Sdim static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1); 424262801Sdim 425262801Sdim template <intmax_t _Xp, intmax_t _Yp, bool __overflow> 426262801Sdim struct __mul // __overflow == false 427262801Sdim { 428262801Sdim static const intmax_t value = _Xp * _Yp; 429262801Sdim }; 430262801Sdim 431262801Sdim template <intmax_t _Xp, intmax_t _Yp> 432262801Sdim struct __mul<_Xp, _Yp, true> 433262801Sdim { 434262801Sdim static const intmax_t value = 1; 435262801Sdim }; 436262801Sdim 437262801Sdim public: 438262801Sdim static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1); 439262801Sdim typedef ratio<__mul<__n1, __d2, !value>::value, 440262801Sdim __mul<__n2, __d1, !value>::value> type; 441262801Sdim }; 442262801Sdim 443227825Stheravenpublic: 444227825Stheraven typedef _Rep rep; 445227825Stheraven typedef _Period period; 446227825Stheravenprivate: 447227825Stheraven rep __rep_; 448227825Stheravenpublic: 449227825Stheraven 450262801Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 451262801Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 452262801Sdim duration() = default; 453262801Sdim#else 454262801Sdim duration() {} 455262801Sdim#endif 456262801Sdim 457227825Stheraven template <class _Rep2> 458241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 459227825Stheraven explicit duration(const _Rep2& __r, 460227825Stheraven typename enable_if 461227825Stheraven < 462227825Stheraven is_convertible<_Rep2, rep>::value && 463227825Stheraven (treat_as_floating_point<rep>::value || 464227825Stheraven !treat_as_floating_point<_Rep2>::value) 465227825Stheraven >::type* = 0) 466227825Stheraven : __rep_(__r) {} 467227825Stheraven 468227825Stheraven // conversions 469227825Stheraven template <class _Rep2, class _Period2> 470241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 471227825Stheraven duration(const duration<_Rep2, _Period2>& __d, 472227825Stheraven typename enable_if 473227825Stheraven < 474262801Sdim __no_overflow<_Period2, period>::value && ( 475227825Stheraven treat_as_floating_point<rep>::value || 476262801Sdim (__no_overflow<_Period2, period>::type::den == 1 && 477262801Sdim !treat_as_floating_point<_Rep2>::value)) 478227825Stheraven >::type* = 0) 479227825Stheraven : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {} 480227825Stheraven 481227825Stheraven // observer 482227825Stheraven 483241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;} 484227825Stheraven 485227825Stheraven // arithmetic 486227825Stheraven 487241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;} 488241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);} 489227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;} 490227825Stheraven _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);} 491227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;} 492227825Stheraven _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);} 493227825Stheraven 494227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} 495227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} 496227825Stheraven 497227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} 498227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} 499227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} 500227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;} 501227825Stheraven 502227825Stheraven // special values 503227825Stheraven 504241903Sdim _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());} 505241903Sdim _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values<rep>::min());} 506241903Sdim _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values<rep>::max());} 507227825Stheraven}; 508227825Stheraven 509227825Stheraventypedef duration<long long, nano> nanoseconds; 510227825Stheraventypedef duration<long long, micro> microseconds; 511227825Stheraventypedef duration<long long, milli> milliseconds; 512227825Stheraventypedef duration<long long > seconds; 513227825Stheraventypedef duration< long, ratio< 60> > minutes; 514227825Stheraventypedef duration< long, ratio<3600> > hours; 515227825Stheraven 516227825Stheraven// Duration == 517227825Stheraven 518227825Stheraventemplate <class _LhsDuration, class _RhsDuration> 519227825Stheravenstruct __duration_eq 520227825Stheraven{ 521241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 522251066Sdim bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const 523227825Stheraven { 524227825Stheraven typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; 525227825Stheraven return _Ct(__lhs).count() == _Ct(__rhs).count(); 526227825Stheraven } 527227825Stheraven}; 528227825Stheraven 529227825Stheraventemplate <class _LhsDuration> 530227825Stheravenstruct __duration_eq<_LhsDuration, _LhsDuration> 531227825Stheraven{ 532241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 533251066Sdim bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const 534227825Stheraven {return __lhs.count() == __rhs.count();} 535227825Stheraven}; 536227825Stheraven 537227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 538227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 539241903Sdim_LIBCPP_CONSTEXPR 540227825Stheravenbool 541227825Stheravenoperator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 542227825Stheraven{ 543227825Stheraven return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); 544227825Stheraven} 545227825Stheraven 546227825Stheraven// Duration != 547227825Stheraven 548227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 549227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 550241903Sdim_LIBCPP_CONSTEXPR 551227825Stheravenbool 552227825Stheravenoperator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 553227825Stheraven{ 554227825Stheraven return !(__lhs == __rhs); 555227825Stheraven} 556227825Stheraven 557227825Stheraven// Duration < 558227825Stheraven 559227825Stheraventemplate <class _LhsDuration, class _RhsDuration> 560227825Stheravenstruct __duration_lt 561227825Stheraven{ 562241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 563251066Sdim bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const 564227825Stheraven { 565227825Stheraven typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; 566227825Stheraven return _Ct(__lhs).count() < _Ct(__rhs).count(); 567227825Stheraven } 568227825Stheraven}; 569227825Stheraven 570227825Stheraventemplate <class _LhsDuration> 571227825Stheravenstruct __duration_lt<_LhsDuration, _LhsDuration> 572227825Stheraven{ 573241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 574251066Sdim bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const 575227825Stheraven {return __lhs.count() < __rhs.count();} 576227825Stheraven}; 577227825Stheraven 578227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 579227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 580241903Sdim_LIBCPP_CONSTEXPR 581227825Stheravenbool 582227825Stheravenoperator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 583227825Stheraven{ 584227825Stheraven return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); 585227825Stheraven} 586227825Stheraven 587227825Stheraven// Duration > 588227825Stheraven 589227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 590227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 591241903Sdim_LIBCPP_CONSTEXPR 592227825Stheravenbool 593227825Stheravenoperator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 594227825Stheraven{ 595227825Stheraven return __rhs < __lhs; 596227825Stheraven} 597227825Stheraven 598227825Stheraven// Duration <= 599227825Stheraven 600227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 601227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 602241903Sdim_LIBCPP_CONSTEXPR 603227825Stheravenbool 604227825Stheravenoperator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 605227825Stheraven{ 606227825Stheraven return !(__rhs < __lhs); 607227825Stheraven} 608227825Stheraven 609227825Stheraven// Duration >= 610227825Stheraven 611227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 612227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 613241903Sdim_LIBCPP_CONSTEXPR 614227825Stheravenbool 615227825Stheravenoperator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 616227825Stheraven{ 617227825Stheraven return !(__lhs < __rhs); 618227825Stheraven} 619227825Stheraven 620227825Stheraven// Duration + 621227825Stheraven 622227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 623227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 624241903Sdim_LIBCPP_CONSTEXPR 625227825Stheraventypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 626227825Stheravenoperator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 627227825Stheraven{ 628241903Sdim typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; 629241903Sdim return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); 630227825Stheraven} 631227825Stheraven 632227825Stheraven// Duration - 633227825Stheraven 634227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 635227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 636241903Sdim_LIBCPP_CONSTEXPR 637227825Stheraventypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 638227825Stheravenoperator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 639227825Stheraven{ 640241903Sdim typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; 641241903Sdim return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); 642227825Stheraven} 643227825Stheraven 644227825Stheraven// Duration * 645227825Stheraven 646227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 647227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 648241903Sdim_LIBCPP_CONSTEXPR 649227825Stheraventypename enable_if 650227825Stheraven< 651227825Stheraven is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, 652227825Stheraven duration<typename common_type<_Rep1, _Rep2>::type, _Period> 653227825Stheraven>::type 654227825Stheravenoperator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 655227825Stheraven{ 656227825Stheraven typedef typename common_type<_Rep1, _Rep2>::type _Cr; 657241903Sdim typedef duration<_Cr, _Period> _Cd; 658241903Sdim return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); 659227825Stheraven} 660227825Stheraven 661227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 662227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 663241903Sdim_LIBCPP_CONSTEXPR 664227825Stheraventypename enable_if 665227825Stheraven< 666227825Stheraven is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, 667227825Stheraven duration<typename common_type<_Rep1, _Rep2>::type, _Period> 668227825Stheraven>::type 669227825Stheravenoperator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) 670227825Stheraven{ 671227825Stheraven return __d * __s; 672227825Stheraven} 673227825Stheraven 674227825Stheraven// Duration / 675227825Stheraven 676227825Stheraventemplate <class _Duration, class _Rep, bool = __is_duration<_Rep>::value> 677227825Stheravenstruct __duration_divide_result 678227825Stheraven{ 679227825Stheraven}; 680227825Stheraven 681227825Stheraventemplate <class _Duration, class _Rep2, 682227825Stheraven bool = is_convertible<_Rep2, 683227825Stheraven typename common_type<typename _Duration::rep, _Rep2>::type>::value> 684227825Stheravenstruct __duration_divide_imp 685227825Stheraven{ 686227825Stheraven}; 687227825Stheraven 688227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 689227825Stheravenstruct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true> 690227825Stheraven{ 691227825Stheraven typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type; 692227825Stheraven}; 693227825Stheraven 694227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 695227825Stheravenstruct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false> 696227825Stheraven : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2> 697227825Stheraven{ 698227825Stheraven}; 699227825Stheraven 700227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 701227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 702241903Sdim_LIBCPP_CONSTEXPR 703227825Stheraventypename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type 704227825Stheravenoperator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 705227825Stheraven{ 706227825Stheraven typedef typename common_type<_Rep1, _Rep2>::type _Cr; 707241903Sdim typedef duration<_Cr, _Period> _Cd; 708241903Sdim return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); 709227825Stheraven} 710227825Stheraven 711227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 712227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 713241903Sdim_LIBCPP_CONSTEXPR 714227825Stheraventypename common_type<_Rep1, _Rep2>::type 715227825Stheravenoperator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 716227825Stheraven{ 717227825Stheraven typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct; 718227825Stheraven return _Ct(__lhs).count() / _Ct(__rhs).count(); 719227825Stheraven} 720227825Stheraven 721227825Stheraven// Duration % 722227825Stheraven 723227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 724227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 725241903Sdim_LIBCPP_CONSTEXPR 726227825Stheraventypename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type 727227825Stheravenoperator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 728227825Stheraven{ 729227825Stheraven typedef typename common_type<_Rep1, _Rep2>::type _Cr; 730241903Sdim typedef duration<_Cr, _Period> _Cd; 731241903Sdim return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); 732227825Stheraven} 733227825Stheraven 734227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 735227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 736241903Sdim_LIBCPP_CONSTEXPR 737227825Stheraventypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 738227825Stheravenoperator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 739227825Stheraven{ 740241903Sdim typedef typename common_type<_Rep1, _Rep2>::type _Cr; 741241903Sdim typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; 742241903Sdim return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count())); 743227825Stheraven} 744227825Stheraven 745227825Stheraven////////////////////////////////////////////////////////// 746227825Stheraven///////////////////// time_point ///////////////////////// 747227825Stheraven////////////////////////////////////////////////////////// 748227825Stheraven 749227825Stheraventemplate <class _Clock, class _Duration = typename _Clock::duration> 750262801Sdimclass _LIBCPP_TYPE_VIS_ONLY time_point 751227825Stheraven{ 752227825Stheraven static_assert(__is_duration<_Duration>::value, 753227825Stheraven "Second template parameter of time_point must be a std::chrono::duration"); 754227825Stheravenpublic: 755227825Stheraven typedef _Clock clock; 756227825Stheraven typedef _Duration duration; 757227825Stheraven typedef typename duration::rep rep; 758227825Stheraven typedef typename duration::period period; 759227825Stheravenprivate: 760227825Stheraven duration __d_; 761227825Stheraven 762227825Stheravenpublic: 763262801Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {} 764262801Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {} 765227825Stheraven 766227825Stheraven // conversions 767227825Stheraven template <class _Duration2> 768262801Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 769227825Stheraven time_point(const time_point<clock, _Duration2>& t, 770227825Stheraven typename enable_if 771227825Stheraven < 772227825Stheraven is_convertible<_Duration2, duration>::value 773227825Stheraven >::type* = 0) 774227825Stheraven : __d_(t.time_since_epoch()) {} 775227825Stheraven 776227825Stheraven // observer 777227825Stheraven 778262801Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;} 779227825Stheraven 780227825Stheraven // arithmetic 781227825Stheraven 782262801Sdim _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} 783262801Sdim _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;} 784227825Stheraven 785227825Stheraven // special values 786227825Stheraven 787241903Sdim _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());} 788241903Sdim _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());} 789227825Stheraven}; 790227825Stheraven 791227825Stheraven} // chrono 792227825Stheraven 793227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 794262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::time_point<_Clock, _Duration1>, 795262801Sdim chrono::time_point<_Clock, _Duration2> > 796227825Stheraven{ 797227825Stheraven typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; 798227825Stheraven}; 799227825Stheraven 800227825Stheravennamespace chrono { 801227825Stheraven 802227825Stheraventemplate <class _ToDuration, class _Clock, class _Duration> 803262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 804227825Stheraventime_point<_Clock, _ToDuration> 805227825Stheraventime_point_cast(const time_point<_Clock, _Duration>& __t) 806227825Stheraven{ 807227825Stheraven return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); 808227825Stheraven} 809227825Stheraven 810227825Stheraven// time_point == 811227825Stheraven 812227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 813262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 814227825Stheravenbool 815227825Stheravenoperator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 816227825Stheraven{ 817227825Stheraven return __lhs.time_since_epoch() == __rhs.time_since_epoch(); 818227825Stheraven} 819227825Stheraven 820227825Stheraven// time_point != 821227825Stheraven 822227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 823262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 824227825Stheravenbool 825227825Stheravenoperator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 826227825Stheraven{ 827227825Stheraven return !(__lhs == __rhs); 828227825Stheraven} 829227825Stheraven 830227825Stheraven// time_point < 831227825Stheraven 832227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 833262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 834227825Stheravenbool 835227825Stheravenoperator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 836227825Stheraven{ 837227825Stheraven return __lhs.time_since_epoch() < __rhs.time_since_epoch(); 838227825Stheraven} 839227825Stheraven 840227825Stheraven// time_point > 841227825Stheraven 842227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 843262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 844227825Stheravenbool 845227825Stheravenoperator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 846227825Stheraven{ 847227825Stheraven return __rhs < __lhs; 848227825Stheraven} 849227825Stheraven 850227825Stheraven// time_point <= 851227825Stheraven 852227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 853262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 854227825Stheravenbool 855227825Stheravenoperator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 856227825Stheraven{ 857227825Stheraven return !(__rhs < __lhs); 858227825Stheraven} 859227825Stheraven 860227825Stheraven// time_point >= 861227825Stheraven 862227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 863262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 864227825Stheravenbool 865227825Stheravenoperator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 866227825Stheraven{ 867227825Stheraven return !(__lhs < __rhs); 868227825Stheraven} 869227825Stheraven 870227825Stheraven// time_point operator+(time_point x, duration y); 871227825Stheraven 872227825Stheraventemplate <class _Clock, class _Duration1, class _Rep2, class _Period2> 873262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 874227825Stheraventime_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> 875227825Stheravenoperator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 876227825Stheraven{ 877227825Stheraven typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; 878262801Sdim return _Tr (__lhs.time_since_epoch() + __rhs); 879227825Stheraven} 880227825Stheraven 881227825Stheraven// time_point operator+(duration x, time_point y); 882227825Stheraven 883227825Stheraventemplate <class _Rep1, class _Period1, class _Clock, class _Duration2> 884262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 885227825Stheraventime_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type> 886227825Stheravenoperator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 887227825Stheraven{ 888227825Stheraven return __rhs + __lhs; 889227825Stheraven} 890227825Stheraven 891227825Stheraven// time_point operator-(time_point x, duration y); 892227825Stheraven 893227825Stheraventemplate <class _Clock, class _Duration1, class _Rep2, class _Period2> 894262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 895227825Stheraventime_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> 896227825Stheravenoperator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 897227825Stheraven{ 898227825Stheraven return __lhs + (-__rhs); 899227825Stheraven} 900227825Stheraven 901227825Stheraven// duration operator-(time_point x, time_point y); 902227825Stheraven 903227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 904262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 905227825Stheraventypename common_type<_Duration1, _Duration2>::type 906227825Stheravenoperator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 907227825Stheraven{ 908227825Stheraven return __lhs.time_since_epoch() - __rhs.time_since_epoch(); 909227825Stheraven} 910227825Stheraven 911227825Stheraven////////////////////////////////////////////////////////// 912227825Stheraven/////////////////////// clocks /////////////////////////// 913227825Stheraven////////////////////////////////////////////////////////// 914227825Stheraven 915249998Sdimclass _LIBCPP_TYPE_VIS system_clock 916227825Stheraven{ 917227825Stheravenpublic: 918227825Stheraven typedef microseconds duration; 919227825Stheraven typedef duration::rep rep; 920227825Stheraven typedef duration::period period; 921227825Stheraven typedef chrono::time_point<system_clock> time_point; 922262801Sdim static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; 923227825Stheraven 924227825Stheraven static time_point now() _NOEXCEPT; 925227825Stheraven static time_t to_time_t (const time_point& __t) _NOEXCEPT; 926227825Stheraven static time_point from_time_t(time_t __t) _NOEXCEPT; 927227825Stheraven}; 928227825Stheraven 929278724Sdim#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK 930249998Sdimclass _LIBCPP_TYPE_VIS steady_clock 931227825Stheraven{ 932227825Stheravenpublic: 933227825Stheraven typedef nanoseconds duration; 934227825Stheraven typedef duration::rep rep; 935227825Stheraven typedef duration::period period; 936227825Stheraven typedef chrono::time_point<steady_clock, duration> time_point; 937262801Sdim static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true; 938227825Stheraven 939227825Stheraven static time_point now() _NOEXCEPT; 940227825Stheraven}; 941227825Stheraven 942227825Stheraventypedef steady_clock high_resolution_clock; 943278724Sdim#else 944278724Sdimtypedef system_clock high_resolution_clock; 945278724Sdim#endif 946227825Stheraven 947227825Stheraven} // chrono 948227825Stheraven 949262801Sdim#if _LIBCPP_STD_VER > 11 950262801Sdim// Suffixes for duration literals [time.duration.literals] 951262801Sdiminline namespace literals 952262801Sdim{ 953262801Sdim inline namespace chrono_literals 954262801Sdim { 955262801Sdim 956262801Sdim constexpr chrono::hours operator"" h(unsigned long long __h) 957262801Sdim { 958262801Sdim return chrono::hours(static_cast<chrono::hours::rep>(__h)); 959262801Sdim } 960262801Sdim 961262801Sdim constexpr chrono::duration<long double, ratio<3600,1>> operator"" h(long double __h) 962262801Sdim { 963262801Sdim return chrono::duration<long double, ratio<3600,1>>(__h); 964262801Sdim } 965262801Sdim 966262801Sdim 967262801Sdim constexpr chrono::minutes operator"" min(unsigned long long __m) 968262801Sdim { 969262801Sdim return chrono::minutes(static_cast<chrono::minutes::rep>(__m)); 970262801Sdim } 971262801Sdim 972262801Sdim constexpr chrono::duration<long double, ratio<60,1>> operator"" min(long double __m) 973262801Sdim { 974262801Sdim return chrono::duration<long double, ratio<60,1>> (__m); 975262801Sdim } 976262801Sdim 977262801Sdim 978262801Sdim constexpr chrono::seconds operator"" s(unsigned long long __s) 979262801Sdim { 980262801Sdim return chrono::seconds(static_cast<chrono::seconds::rep>(__s)); 981262801Sdim } 982262801Sdim 983262801Sdim constexpr chrono::duration<long double> operator"" s(long double __s) 984262801Sdim { 985262801Sdim return chrono::duration<long double> (__s); 986262801Sdim } 987262801Sdim 988262801Sdim 989262801Sdim constexpr chrono::milliseconds operator"" ms(unsigned long long __ms) 990262801Sdim { 991262801Sdim return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms)); 992262801Sdim } 993262801Sdim 994262801Sdim constexpr chrono::duration<long double, milli> operator"" ms(long double __ms) 995262801Sdim { 996262801Sdim return chrono::duration<long double, milli>(__ms); 997262801Sdim } 998262801Sdim 999262801Sdim 1000262801Sdim constexpr chrono::microseconds operator"" us(unsigned long long __us) 1001262801Sdim { 1002262801Sdim return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us)); 1003262801Sdim } 1004262801Sdim 1005262801Sdim constexpr chrono::duration<long double, micro> operator"" us(long double __us) 1006262801Sdim { 1007262801Sdim return chrono::duration<long double, micro> (__us); 1008262801Sdim } 1009262801Sdim 1010262801Sdim 1011262801Sdim constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns) 1012262801Sdim { 1013262801Sdim return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns)); 1014262801Sdim } 1015262801Sdim 1016262801Sdim constexpr chrono::duration<long double, nano> operator"" ns(long double __ns) 1017262801Sdim { 1018262801Sdim return chrono::duration<long double, nano> (__ns); 1019262801Sdim } 1020262801Sdim 1021262801Sdim}} 1022262801Sdim 1023262801Sdimnamespace chrono { // hoist the literals into namespace std::chrono 1024262801Sdim using namespace literals::chrono_literals; 1025262801Sdim} 1026262801Sdim 1027262801Sdim#endif 1028262801Sdim 1029227825Stheraven_LIBCPP_END_NAMESPACE_STD 1030227825Stheraven 1031227825Stheraven#endif // _LIBCPP_CHRONO 1032