chrono revision 232950
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> 23227825StheravenToDuration 24227825Stheravenduration_cast(const duration<Rep, Period>& fd); 25227825Stheraven 26227825Stheraventemplate <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {}; 27227825Stheraven 28227825Stheraventemplate <class Rep> 29227825Stheravenstruct duration_values 30227825Stheraven{ 31227825Stheravenpublic: 32227825Stheraven static Rep zero(); 33227825Stheraven static Rep max(); 34227825Stheraven static Rep min(); 35227825Stheraven}; 36227825Stheraven 37227825Stheraven// duration 38227825Stheraven 39227825Stheraventemplate <class Rep, class Period = ratio<1>> 40227825Stheravenclass duration 41227825Stheraven{ 42227825Stheraven static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration"); 43227825Stheraven static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio"); 44227825Stheraven static_assert(Period::num > 0, "duration period must be positive"); 45227825Stheravenpublic: 46227825Stheraven typedef Rep rep; 47227825Stheraven typedef Period period; 48227825Stheraven 49227825Stheraven duration() = default; 50227825Stheraven template <class Rep2> 51227825Stheraven explicit duration(const Rep2& r, 52227825Stheraven typename enable_if 53227825Stheraven < 54227825Stheraven is_convertible<Rep2, rep>::value && 55227825Stheraven (treat_as_floating_point<rep>::value || 56227825Stheraven !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value) 57227825Stheraven >::type* = 0); 58227825Stheraven 59227825Stheraven // conversions 60227825Stheraven template <class Rep2, class Period2> 61227825Stheraven duration(const duration<Rep2, Period2>& d, 62227825Stheraven typename enable_if 63227825Stheraven < 64227825Stheraven treat_as_floating_point<rep>::value || 65227825Stheraven ratio_divide<Period2, period>::type::den == 1 66227825Stheraven >::type* = 0); 67227825Stheraven 68227825Stheraven // observer 69227825Stheraven 70227825Stheraven rep count() const; 71227825Stheraven 72227825Stheraven // arithmetic 73227825Stheraven 74227825Stheraven duration operator+() const; 75227825Stheraven duration operator-() const; 76227825Stheraven duration& operator++(); 77227825Stheraven duration operator++(int); 78227825Stheraven duration& operator--(); 79227825Stheraven duration operator--(int); 80227825Stheraven 81227825Stheraven duration& operator+=(const duration& d); 82227825Stheraven duration& operator-=(const duration& d); 83227825Stheraven 84227825Stheraven duration& operator*=(const rep& rhs); 85227825Stheraven duration& operator/=(const rep& rhs); 86227825Stheraven 87227825Stheraven // special values 88227825Stheraven 89227825Stheraven static duration zero(); 90227825Stheraven static duration min(); 91227825Stheraven static duration max(); 92227825Stheraven}; 93227825Stheraven 94227825Stheraventypedef duration<long long, nano> nanoseconds; 95227825Stheraventypedef duration<long long, micro> microseconds; 96227825Stheraventypedef duration<long long, milli> milliseconds; 97227825Stheraventypedef duration<long long > seconds; 98227825Stheraventypedef duration< long, ratio< 60> > minutes; 99227825Stheraventypedef duration< long, ratio<3600> > hours; 100227825Stheraven 101227825Stheraventemplate <class Clock, class Duration = typename Clock::duration> 102227825Stheravenclass time_point 103227825Stheraven{ 104227825Stheravenpublic: 105227825Stheraven typedef Clock clock; 106227825Stheraven typedef Duration duration; 107227825Stheraven typedef typename duration::rep rep; 108227825Stheraven typedef typename duration::period period; 109227825Stheravenprivate: 110227825Stheraven duration d_; // exposition only 111227825Stheraven 112227825Stheravenpublic: 113227825Stheraven time_point(); // has value "epoch" 114227825Stheraven explicit time_point(const duration& d); // same as time_point() + d 115227825Stheraven 116227825Stheraven // conversions 117227825Stheraven template <class Duration2> 118227825Stheraven time_point(const time_point<clock, Duration2>& t); 119227825Stheraven 120227825Stheraven // observer 121227825Stheraven 122227825Stheraven duration time_since_epoch() const; 123227825Stheraven 124227825Stheraven // arithmetic 125227825Stheraven 126227825Stheraven time_point& operator+=(const duration& d); 127227825Stheraven time_point& operator-=(const duration& d); 128227825Stheraven 129227825Stheraven // special values 130227825Stheraven 131227825Stheraven static constexpr time_point min(); 132227825Stheraven static constexpr time_point max(); 133227825Stheraven}; 134227825Stheraven 135227825Stheraven} // chrono 136227825Stheraven 137227825Stheraven// common_type traits 138227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 139227825Stheraven struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>; 140227825Stheraven 141227825Stheraventemplate <class Clock, class Duration1, class Duration2> 142227825Stheraven struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>; 143227825Stheraven 144227825Stheravennamespace chrono { 145227825Stheraven 146227825Stheraven// duration arithmetic 147227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 148227825Stheraven typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type 149227825Stheraven operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 150227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 151227825Stheraven typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type 152227825Stheraven operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 153227825Stheraventemplate <class Rep1, class Period, class Rep2> 154227825Stheraven duration<typename common_type<Rep1, Rep2>::type, Period> 155227825Stheraven operator*(const duration<Rep1, Period>& d, const Rep2& s); 156227825Stheraventemplate <class Rep1, class Period, class Rep2> 157227825Stheraven duration<typename common_type<Rep1, Rep2>::type, Period> 158227825Stheraven operator*(const Rep1& s, const duration<Rep2, Period>& d); 159227825Stheraventemplate <class Rep1, class Period, class Rep2> 160227825Stheraven duration<typename common_type<Rep1, Rep2>::type, Period> 161227825Stheraven operator/(const duration<Rep1, Period>& d, const Rep2& s); 162227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 163227825Stheraven typename common_type<Rep1, Rep2>::type 164227825Stheraven operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 165227825Stheraven 166227825Stheraven// duration comparisons 167227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 168227825Stheraven bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 169227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 170227825Stheraven bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 171227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 172227825Stheraven bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 173227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 174227825Stheraven bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 175227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 176227825Stheraven bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 177227825Stheraventemplate <class Rep1, class Period1, class Rep2, class Period2> 178227825Stheraven bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 179227825Stheraven 180227825Stheraven// duration_cast 181227825Stheraventemplate <class ToDuration, class Rep, class Period> 182227825Stheraven ToDuration duration_cast(const duration<Rep, Period>& d); 183227825Stheraven 184227825Stheraven// time_point arithmetic 185227825Stheraventemplate <class Clock, class Duration1, class Rep2, class Period2> 186227825Stheraven time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> 187227825Stheraven operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); 188227825Stheraventemplate <class Rep1, class Period1, class Clock, class Duration2> 189227825Stheraven time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> 190227825Stheraven operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs); 191227825Stheraventemplate <class Clock, class Duration1, class Rep2, class Period2> 192227825Stheraven time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> 193227825Stheraven operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); 194227825Stheraventemplate <class Clock, class Duration1, class Duration2> 195227825Stheraven typename common_type<Duration1, Duration2>::type 196227825Stheraven operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 197227825Stheraven 198227825Stheraven// time_point comparisons 199227825Stheraventemplate <class Clock, class Duration1, class Duration2> 200227825Stheraven bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 201227825Stheraventemplate <class Clock, class Duration1, class Duration2> 202227825Stheraven bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 203227825Stheraventemplate <class Clock, class Duration1, class Duration2> 204227825Stheraven bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 205227825Stheraventemplate <class Clock, class Duration1, class Duration2> 206227825Stheraven bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 207227825Stheraventemplate <class Clock, class Duration1, class Duration2> 208227825Stheraven bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 209227825Stheraventemplate <class Clock, class Duration1, class Duration2> 210227825Stheraven bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 211227825Stheraven 212227825Stheraven// time_point_cast 213227825Stheraven 214227825Stheraventemplate <class ToDuration, class Clock, class Duration> 215227825Stheraven time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t); 216227825Stheraven 217227825Stheraven// Clocks 218227825Stheraven 219227825Stheravenclass system_clock 220227825Stheraven{ 221227825Stheravenpublic: 222227825Stheraven typedef microseconds duration; 223227825Stheraven typedef duration::rep rep; 224227825Stheraven typedef duration::period period; 225227825Stheraven typedef chrono::time_point<system_clock> time_point; 226227825Stheraven static const bool is_steady = false; 227227825Stheraven 228227825Stheraven static time_point now() noexcept; 229227825Stheraven static time_t to_time_t (const time_point& __t) noexcept; 230227825Stheraven static time_point from_time_t(time_t __t) noexcept; 231227825Stheraven}; 232227825Stheraven 233227825Stheravenclass steady_clock 234227825Stheraven{ 235227825Stheravenpublic: 236227825Stheraven typedef nanoseconds duration; 237227825Stheraven typedef duration::rep rep; 238227825Stheraven typedef duration::period period; 239227825Stheraven typedef chrono::time_point<steady_clock, duration> time_point; 240227825Stheraven static const bool is_steady = true; 241227825Stheraven 242227825Stheraven static time_point now() noexcept; 243227825Stheraven}; 244227825Stheraven 245227825Stheraventypedef steady_clock high_resolution_clock; 246227825Stheraven 247227825Stheraven} // chrono 248227825Stheraven 249227825Stheraven} // std 250227825Stheraven*/ 251227825Stheraven 252227825Stheraven#include <__config> 253227825Stheraven#include <ctime> 254227825Stheraven#include <type_traits> 255227825Stheraven#include <ratio> 256227825Stheraven#include <limits> 257227825Stheraven 258232950Stheraven#include <__undef_min_max> 259232950Stheraven 260227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 261227825Stheraven#pragma GCC system_header 262227825Stheraven#endif 263227825Stheraven 264227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 265227825Stheraven 266227825Stheravennamespace chrono 267227825Stheraven{ 268227825Stheraven 269227825Stheraventemplate <class _Rep, class _Period = ratio<1> > class _LIBCPP_VISIBLE duration; 270227825Stheraven 271227825Stheraventemplate <class _Tp> 272227825Stheravenstruct __is_duration : false_type {}; 273227825Stheraven 274227825Stheraventemplate <class _Rep, class _Period> 275227825Stheravenstruct __is_duration<duration<_Rep, _Period> > : true_type {}; 276227825Stheraven 277227825Stheraventemplate <class _Rep, class _Period> 278227825Stheravenstruct __is_duration<const duration<_Rep, _Period> > : true_type {}; 279227825Stheraven 280227825Stheraventemplate <class _Rep, class _Period> 281227825Stheravenstruct __is_duration<volatile duration<_Rep, _Period> > : true_type {}; 282227825Stheraven 283227825Stheraventemplate <class _Rep, class _Period> 284227825Stheravenstruct __is_duration<const volatile duration<_Rep, _Period> > : true_type {}; 285227825Stheraven 286227825Stheraven} // chrono 287227825Stheraven 288227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 289227825Stheravenstruct _LIBCPP_VISIBLE common_type<chrono::duration<_Rep1, _Period1>, 290227825Stheraven chrono::duration<_Rep2, _Period2> > 291227825Stheraven{ 292227825Stheraven typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, 293227825Stheraven typename __ratio_gcd<_Period1, _Period2>::type> type; 294227825Stheraven}; 295227825Stheraven 296227825Stheravennamespace chrono { 297227825Stheraven 298227825Stheraven// duration_cast 299227825Stheraven 300227825Stheraventemplate <class _FromDuration, class _ToDuration, 301227825Stheraven class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type, 302227825Stheraven bool = _Period::num == 1, 303227825Stheraven bool = _Period::den == 1> 304227825Stheravenstruct __duration_cast; 305227825Stheraven 306227825Stheraventemplate <class _FromDuration, class _ToDuration, class _Period> 307227825Stheravenstruct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> 308227825Stheraven{ 309227825Stheraven _LIBCPP_INLINE_VISIBILITY 310227825Stheraven _ToDuration operator()(const _FromDuration& __fd) const 311227825Stheraven { 312227825Stheraven return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count())); 313227825Stheraven } 314227825Stheraven}; 315227825Stheraven 316227825Stheraventemplate <class _FromDuration, class _ToDuration, class _Period> 317227825Stheravenstruct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> 318227825Stheraven{ 319227825Stheraven _LIBCPP_INLINE_VISIBILITY 320227825Stheraven _ToDuration operator()(const _FromDuration& __fd) const 321227825Stheraven { 322227825Stheraven typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 323227825Stheraven return _ToDuration(static_cast<typename _ToDuration::rep>( 324227825Stheraven static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); 325227825Stheraven } 326227825Stheraven}; 327227825Stheraven 328227825Stheraventemplate <class _FromDuration, class _ToDuration, class _Period> 329227825Stheravenstruct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> 330227825Stheraven{ 331227825Stheraven _LIBCPP_INLINE_VISIBILITY 332227825Stheraven _ToDuration operator()(const _FromDuration& __fd) const 333227825Stheraven { 334227825Stheraven typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 335227825Stheraven return _ToDuration(static_cast<typename _ToDuration::rep>( 336227825Stheraven static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); 337227825Stheraven } 338227825Stheraven}; 339227825Stheraven 340227825Stheraventemplate <class _FromDuration, class _ToDuration, class _Period> 341227825Stheravenstruct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> 342227825Stheraven{ 343227825Stheraven _LIBCPP_INLINE_VISIBILITY 344227825Stheraven _ToDuration operator()(const _FromDuration& __fd) const 345227825Stheraven { 346227825Stheraven typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 347227825Stheraven return _ToDuration(static_cast<typename _ToDuration::rep>( 348227825Stheraven static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) 349227825Stheraven / static_cast<_Ct>(_Period::den))); 350227825Stheraven } 351227825Stheraven}; 352227825Stheraven 353227825Stheraventemplate <class _ToDuration, class _Rep, class _Period> 354227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 355227825Stheraventypename enable_if 356227825Stheraven< 357227825Stheraven __is_duration<_ToDuration>::value, 358227825Stheraven _ToDuration 359227825Stheraven>::type 360227825Stheravenduration_cast(const duration<_Rep, _Period>& __fd) 361227825Stheraven{ 362227825Stheraven return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd); 363227825Stheraven} 364227825Stheraven 365227825Stheraventemplate <class _Rep> 366227825Stheravenstruct _LIBCPP_VISIBLE treat_as_floating_point : is_floating_point<_Rep> {}; 367227825Stheraven 368227825Stheraventemplate <class _Rep> 369227825Stheravenstruct _LIBCPP_VISIBLE duration_values 370227825Stheraven{ 371227825Stheravenpublic: 372227825Stheraven _LIBCPP_INLINE_VISIBILITY static _Rep zero() {return _Rep(0);} 373227825Stheraven _LIBCPP_INLINE_VISIBILITY static _Rep max() {return numeric_limits<_Rep>::max();} 374227825Stheraven _LIBCPP_INLINE_VISIBILITY static _Rep min() {return numeric_limits<_Rep>::lowest();} 375227825Stheraven}; 376227825Stheraven 377227825Stheraven// duration 378227825Stheraven 379227825Stheraventemplate <class _Rep, class _Period> 380227825Stheravenclass _LIBCPP_VISIBLE duration 381227825Stheraven{ 382227825Stheraven static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); 383227825Stheraven static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); 384227825Stheraven static_assert(_Period::num > 0, "duration period must be positive"); 385227825Stheravenpublic: 386227825Stheraven typedef _Rep rep; 387227825Stheraven typedef _Period period; 388227825Stheravenprivate: 389227825Stheraven rep __rep_; 390227825Stheravenpublic: 391227825Stheraven 392227825Stheraven _LIBCPP_INLINE_VISIBILITY duration() {} // = default; 393227825Stheraven template <class _Rep2> 394227825Stheraven _LIBCPP_INLINE_VISIBILITY 395227825Stheraven explicit duration(const _Rep2& __r, 396227825Stheraven typename enable_if 397227825Stheraven < 398227825Stheraven is_convertible<_Rep2, rep>::value && 399227825Stheraven (treat_as_floating_point<rep>::value || 400227825Stheraven !treat_as_floating_point<_Rep2>::value) 401227825Stheraven >::type* = 0) 402227825Stheraven : __rep_(__r) {} 403227825Stheraven 404227825Stheraven // conversions 405227825Stheraven template <class _Rep2, class _Period2> 406227825Stheraven _LIBCPP_INLINE_VISIBILITY 407227825Stheraven duration(const duration<_Rep2, _Period2>& __d, 408227825Stheraven typename enable_if 409227825Stheraven < 410227825Stheraven treat_as_floating_point<rep>::value || 411227825Stheraven (ratio_divide<_Period2, period>::type::den == 1 && 412227825Stheraven !treat_as_floating_point<_Rep2>::value) 413227825Stheraven >::type* = 0) 414227825Stheraven : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {} 415227825Stheraven 416227825Stheraven // observer 417227825Stheraven 418227825Stheraven _LIBCPP_INLINE_VISIBILITY rep count() const {return __rep_;} 419227825Stheraven 420227825Stheraven // arithmetic 421227825Stheraven 422227825Stheraven _LIBCPP_INLINE_VISIBILITY duration operator+() const {return *this;} 423227825Stheraven _LIBCPP_INLINE_VISIBILITY duration operator-() const {return duration(-__rep_);} 424227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;} 425227825Stheraven _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);} 426227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;} 427227825Stheraven _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);} 428227825Stheraven 429227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} 430227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} 431227825Stheraven 432227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} 433227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} 434227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} 435227825Stheraven _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;} 436227825Stheraven 437227825Stheraven // special values 438227825Stheraven 439227825Stheraven _LIBCPP_INLINE_VISIBILITY static duration zero() {return duration(duration_values<rep>::zero());} 440227825Stheraven _LIBCPP_INLINE_VISIBILITY static duration min() {return duration(duration_values<rep>::min());} 441227825Stheraven _LIBCPP_INLINE_VISIBILITY static duration max() {return duration(duration_values<rep>::max());} 442227825Stheraven}; 443227825Stheraven 444227825Stheraventypedef duration<long long, nano> nanoseconds; 445227825Stheraventypedef duration<long long, micro> microseconds; 446227825Stheraventypedef duration<long long, milli> milliseconds; 447227825Stheraventypedef duration<long long > seconds; 448227825Stheraventypedef duration< long, ratio< 60> > minutes; 449227825Stheraventypedef duration< long, ratio<3600> > hours; 450227825Stheraven 451227825Stheraven// Duration == 452227825Stheraven 453227825Stheraventemplate <class _LhsDuration, class _RhsDuration> 454227825Stheravenstruct __duration_eq 455227825Stheraven{ 456227825Stheraven _LIBCPP_INLINE_VISIBILITY 457227825Stheraven bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) 458227825Stheraven { 459227825Stheraven typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; 460227825Stheraven return _Ct(__lhs).count() == _Ct(__rhs).count(); 461227825Stheraven } 462227825Stheraven}; 463227825Stheraven 464227825Stheraventemplate <class _LhsDuration> 465227825Stheravenstruct __duration_eq<_LhsDuration, _LhsDuration> 466227825Stheraven{ 467227825Stheraven _LIBCPP_INLINE_VISIBILITY 468227825Stheraven bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) 469227825Stheraven {return __lhs.count() == __rhs.count();} 470227825Stheraven}; 471227825Stheraven 472227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 473227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 474227825Stheravenbool 475227825Stheravenoperator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 476227825Stheraven{ 477227825Stheraven return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); 478227825Stheraven} 479227825Stheraven 480227825Stheraven// Duration != 481227825Stheraven 482227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 483227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 484227825Stheravenbool 485227825Stheravenoperator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 486227825Stheraven{ 487227825Stheraven return !(__lhs == __rhs); 488227825Stheraven} 489227825Stheraven 490227825Stheraven// Duration < 491227825Stheraven 492227825Stheraventemplate <class _LhsDuration, class _RhsDuration> 493227825Stheravenstruct __duration_lt 494227825Stheraven{ 495227825Stheraven _LIBCPP_INLINE_VISIBILITY 496227825Stheraven bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) 497227825Stheraven { 498227825Stheraven typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; 499227825Stheraven return _Ct(__lhs).count() < _Ct(__rhs).count(); 500227825Stheraven } 501227825Stheraven}; 502227825Stheraven 503227825Stheraventemplate <class _LhsDuration> 504227825Stheravenstruct __duration_lt<_LhsDuration, _LhsDuration> 505227825Stheraven{ 506227825Stheraven _LIBCPP_INLINE_VISIBILITY 507227825Stheraven bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) 508227825Stheraven {return __lhs.count() < __rhs.count();} 509227825Stheraven}; 510227825Stheraven 511227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 512227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 513227825Stheravenbool 514227825Stheravenoperator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 515227825Stheraven{ 516227825Stheraven return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); 517227825Stheraven} 518227825Stheraven 519227825Stheraven// Duration > 520227825Stheraven 521227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 522227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 523227825Stheravenbool 524227825Stheravenoperator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 525227825Stheraven{ 526227825Stheraven return __rhs < __lhs; 527227825Stheraven} 528227825Stheraven 529227825Stheraven// Duration <= 530227825Stheraven 531227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 532227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 533227825Stheravenbool 534227825Stheravenoperator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 535227825Stheraven{ 536227825Stheraven return !(__rhs < __lhs); 537227825Stheraven} 538227825Stheraven 539227825Stheraven// Duration >= 540227825Stheraven 541227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 542227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 543227825Stheravenbool 544227825Stheravenoperator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 545227825Stheraven{ 546227825Stheraven return !(__lhs < __rhs); 547227825Stheraven} 548227825Stheraven 549227825Stheraven// Duration + 550227825Stheraven 551227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 552227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 553227825Stheraventypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 554227825Stheravenoperator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 555227825Stheraven{ 556227825Stheraven typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs; 557227825Stheraven __r += __rhs; 558227825Stheraven return __r; 559227825Stheraven} 560227825Stheraven 561227825Stheraven// Duration - 562227825Stheraven 563227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 564227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 565227825Stheraventypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 566227825Stheravenoperator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 567227825Stheraven{ 568227825Stheraven typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs; 569227825Stheraven __r -= __rhs; 570227825Stheraven return __r; 571227825Stheraven} 572227825Stheraven 573227825Stheraven// Duration * 574227825Stheraven 575227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 576227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 577227825Stheraventypename enable_if 578227825Stheraven< 579227825Stheraven is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, 580227825Stheraven duration<typename common_type<_Rep1, _Rep2>::type, _Period> 581227825Stheraven>::type 582227825Stheravenoperator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 583227825Stheraven{ 584227825Stheraven typedef typename common_type<_Rep1, _Rep2>::type _Cr; 585227825Stheraven duration<_Cr, _Period> __r = __d; 586227825Stheraven __r *= static_cast<_Cr>(__s); 587227825Stheraven return __r; 588227825Stheraven} 589227825Stheraven 590227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 591227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 592227825Stheraventypename enable_if 593227825Stheraven< 594227825Stheraven is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, 595227825Stheraven duration<typename common_type<_Rep1, _Rep2>::type, _Period> 596227825Stheraven>::type 597227825Stheravenoperator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) 598227825Stheraven{ 599227825Stheraven return __d * __s; 600227825Stheraven} 601227825Stheraven 602227825Stheraven// Duration / 603227825Stheraven 604227825Stheraventemplate <class _Duration, class _Rep, bool = __is_duration<_Rep>::value> 605227825Stheravenstruct __duration_divide_result 606227825Stheraven{ 607227825Stheraven}; 608227825Stheraven 609227825Stheraventemplate <class _Duration, class _Rep2, 610227825Stheraven bool = is_convertible<_Rep2, 611227825Stheraven typename common_type<typename _Duration::rep, _Rep2>::type>::value> 612227825Stheravenstruct __duration_divide_imp 613227825Stheraven{ 614227825Stheraven}; 615227825Stheraven 616227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 617227825Stheravenstruct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true> 618227825Stheraven{ 619227825Stheraven typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type; 620227825Stheraven}; 621227825Stheraven 622227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 623227825Stheravenstruct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false> 624227825Stheraven : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2> 625227825Stheraven{ 626227825Stheraven}; 627227825Stheraven 628227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 629227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 630227825Stheraventypename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type 631227825Stheravenoperator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 632227825Stheraven{ 633227825Stheraven typedef typename common_type<_Rep1, _Rep2>::type _Cr; 634227825Stheraven duration<_Cr, _Period> __r = __d; 635227825Stheraven __r /= static_cast<_Cr>(__s); 636227825Stheraven return __r; 637227825Stheraven} 638227825Stheraven 639227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 640227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 641227825Stheraventypename common_type<_Rep1, _Rep2>::type 642227825Stheravenoperator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 643227825Stheraven{ 644227825Stheraven typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct; 645227825Stheraven return _Ct(__lhs).count() / _Ct(__rhs).count(); 646227825Stheraven} 647227825Stheraven 648227825Stheraven// Duration % 649227825Stheraven 650227825Stheraventemplate <class _Rep1, class _Period, class _Rep2> 651227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 652227825Stheraventypename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type 653227825Stheravenoperator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 654227825Stheraven{ 655227825Stheraven typedef typename common_type<_Rep1, _Rep2>::type _Cr; 656227825Stheraven duration<_Cr, _Period> __r = __d; 657227825Stheraven __r %= static_cast<_Cr>(__s); 658227825Stheraven return __r; 659227825Stheraven} 660227825Stheraven 661227825Stheraventemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 662227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 663227825Stheraventypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 664227825Stheravenoperator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 665227825Stheraven{ 666227825Stheraven typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs; 667227825Stheraven __r %= __rhs; 668227825Stheraven return __r; 669227825Stheraven} 670227825Stheraven 671227825Stheraven////////////////////////////////////////////////////////// 672227825Stheraven///////////////////// time_point ///////////////////////// 673227825Stheraven////////////////////////////////////////////////////////// 674227825Stheraven 675227825Stheraventemplate <class _Clock, class _Duration = typename _Clock::duration> 676227825Stheravenclass _LIBCPP_VISIBLE time_point 677227825Stheraven{ 678227825Stheraven static_assert(__is_duration<_Duration>::value, 679227825Stheraven "Second template parameter of time_point must be a std::chrono::duration"); 680227825Stheravenpublic: 681227825Stheraven typedef _Clock clock; 682227825Stheraven typedef _Duration duration; 683227825Stheraven typedef typename duration::rep rep; 684227825Stheraven typedef typename duration::period period; 685227825Stheravenprivate: 686227825Stheraven duration __d_; 687227825Stheraven 688227825Stheravenpublic: 689227825Stheraven _LIBCPP_INLINE_VISIBILITY time_point() : __d_(duration::zero()) {} 690227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit time_point(const duration& __d) : __d_(__d) {} 691227825Stheraven 692227825Stheraven // conversions 693227825Stheraven template <class _Duration2> 694227825Stheraven _LIBCPP_INLINE_VISIBILITY 695227825Stheraven time_point(const time_point<clock, _Duration2>& t, 696227825Stheraven typename enable_if 697227825Stheraven < 698227825Stheraven is_convertible<_Duration2, duration>::value 699227825Stheraven >::type* = 0) 700227825Stheraven : __d_(t.time_since_epoch()) {} 701227825Stheraven 702227825Stheraven // observer 703227825Stheraven 704227825Stheraven _LIBCPP_INLINE_VISIBILITY duration time_since_epoch() const {return __d_;} 705227825Stheraven 706227825Stheraven // arithmetic 707227825Stheraven 708227825Stheraven _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d;} 709227825Stheraven _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d;} 710227825Stheraven 711227825Stheraven // special values 712227825Stheraven 713227825Stheraven _LIBCPP_INLINE_VISIBILITY static time_point min() {return time_point(duration::min());} 714227825Stheraven _LIBCPP_INLINE_VISIBILITY static time_point max() {return time_point(duration::max());} 715227825Stheraven}; 716227825Stheraven 717227825Stheraven} // chrono 718227825Stheraven 719227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 720227825Stheravenstruct _LIBCPP_VISIBLE common_type<chrono::time_point<_Clock, _Duration1>, 721227825Stheraven chrono::time_point<_Clock, _Duration2> > 722227825Stheraven{ 723227825Stheraven typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; 724227825Stheraven}; 725227825Stheraven 726227825Stheravennamespace chrono { 727227825Stheraven 728227825Stheraventemplate <class _ToDuration, class _Clock, class _Duration> 729227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 730227825Stheraventime_point<_Clock, _ToDuration> 731227825Stheraventime_point_cast(const time_point<_Clock, _Duration>& __t) 732227825Stheraven{ 733227825Stheraven return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); 734227825Stheraven} 735227825Stheraven 736227825Stheraven// time_point == 737227825Stheraven 738227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 739227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 740227825Stheravenbool 741227825Stheravenoperator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 742227825Stheraven{ 743227825Stheraven return __lhs.time_since_epoch() == __rhs.time_since_epoch(); 744227825Stheraven} 745227825Stheraven 746227825Stheraven// time_point != 747227825Stheraven 748227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 749227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 750227825Stheravenbool 751227825Stheravenoperator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 752227825Stheraven{ 753227825Stheraven return !(__lhs == __rhs); 754227825Stheraven} 755227825Stheraven 756227825Stheraven// time_point < 757227825Stheraven 758227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 759227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 760227825Stheravenbool 761227825Stheravenoperator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 762227825Stheraven{ 763227825Stheraven return __lhs.time_since_epoch() < __rhs.time_since_epoch(); 764227825Stheraven} 765227825Stheraven 766227825Stheraven// time_point > 767227825Stheraven 768227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 769227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 770227825Stheravenbool 771227825Stheravenoperator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 772227825Stheraven{ 773227825Stheraven return __rhs < __lhs; 774227825Stheraven} 775227825Stheraven 776227825Stheraven// time_point <= 777227825Stheraven 778227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 779227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 780227825Stheravenbool 781227825Stheravenoperator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 782227825Stheraven{ 783227825Stheraven return !(__rhs < __lhs); 784227825Stheraven} 785227825Stheraven 786227825Stheraven// time_point >= 787227825Stheraven 788227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 789227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 790227825Stheravenbool 791227825Stheravenoperator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 792227825Stheraven{ 793227825Stheraven return !(__lhs < __rhs); 794227825Stheraven} 795227825Stheraven 796227825Stheraven// time_point operator+(time_point x, duration y); 797227825Stheraven 798227825Stheraventemplate <class _Clock, class _Duration1, class _Rep2, class _Period2> 799227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 800227825Stheraventime_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> 801227825Stheravenoperator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 802227825Stheraven{ 803227825Stheraven typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; 804227825Stheraven _Tr __r(__lhs.time_since_epoch()); 805227825Stheraven __r += __rhs; 806227825Stheraven return __r; 807227825Stheraven} 808227825Stheraven 809227825Stheraven// time_point operator+(duration x, time_point y); 810227825Stheraven 811227825Stheraventemplate <class _Rep1, class _Period1, class _Clock, class _Duration2> 812227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 813227825Stheraventime_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type> 814227825Stheravenoperator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 815227825Stheraven{ 816227825Stheraven return __rhs + __lhs; 817227825Stheraven} 818227825Stheraven 819227825Stheraven// time_point operator-(time_point x, duration y); 820227825Stheraven 821227825Stheraventemplate <class _Clock, class _Duration1, class _Rep2, class _Period2> 822227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 823227825Stheraventime_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> 824227825Stheravenoperator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 825227825Stheraven{ 826227825Stheraven return __lhs + (-__rhs); 827227825Stheraven} 828227825Stheraven 829227825Stheraven// duration operator-(time_point x, time_point y); 830227825Stheraven 831227825Stheraventemplate <class _Clock, class _Duration1, class _Duration2> 832227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 833227825Stheraventypename common_type<_Duration1, _Duration2>::type 834227825Stheravenoperator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 835227825Stheraven{ 836227825Stheraven return __lhs.time_since_epoch() - __rhs.time_since_epoch(); 837227825Stheraven} 838227825Stheraven 839227825Stheraven////////////////////////////////////////////////////////// 840227825Stheraven/////////////////////// clocks /////////////////////////// 841227825Stheraven////////////////////////////////////////////////////////// 842227825Stheraven 843227825Stheravenclass _LIBCPP_VISIBLE system_clock 844227825Stheraven{ 845227825Stheravenpublic: 846227825Stheraven typedef microseconds duration; 847227825Stheraven typedef duration::rep rep; 848227825Stheraven typedef duration::period period; 849227825Stheraven typedef chrono::time_point<system_clock> time_point; 850227825Stheraven static const bool is_steady = false; 851227825Stheraven 852227825Stheraven static time_point now() _NOEXCEPT; 853227825Stheraven static time_t to_time_t (const time_point& __t) _NOEXCEPT; 854227825Stheraven static time_point from_time_t(time_t __t) _NOEXCEPT; 855227825Stheraven}; 856227825Stheraven 857227825Stheravenclass _LIBCPP_VISIBLE steady_clock 858227825Stheraven{ 859227825Stheravenpublic: 860227825Stheraven typedef nanoseconds duration; 861227825Stheraven typedef duration::rep rep; 862227825Stheraven typedef duration::period period; 863227825Stheraven typedef chrono::time_point<steady_clock, duration> time_point; 864227825Stheraven static const bool is_steady = true; 865227825Stheraven 866227825Stheraven static time_point now() _NOEXCEPT; 867227825Stheraven}; 868227825Stheraven 869227825Stheraventypedef steady_clock high_resolution_clock; 870227825Stheraven 871227825Stheraven} // chrono 872227825Stheraven 873227825Stheraven_LIBCPP_END_NAMESPACE_STD 874227825Stheraven 875227825Stheraven#endif // _LIBCPP_CHRONO 876