chrono 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. // -*- C++ -*-
  2. //===---------------------------- chrono ----------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_CHRONO
  11. #define _LIBCPP_CHRONO
  12. /*
  13. chrono synopsis
  14. namespace std
  15. {
  16. namespace chrono
  17. {
  18. template <class ToDuration, class Rep, class Period>
  19. constexpr
  20. ToDuration
  21. duration_cast(const duration<Rep, Period>& fd);
  22. template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
  23. template <class Rep> constexpr bool treat_as_floating_point_v
  24. = treat_as_floating_point<Rep>::value; // C++17
  25. template <class Rep>
  26. struct duration_values
  27. {
  28. public:
  29. static constexpr Rep zero();
  30. static constexpr Rep max();
  31. static constexpr Rep min();
  32. };
  33. // duration
  34. template <class Rep, class Period = ratio<1>>
  35. class duration
  36. {
  37. static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
  38. static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
  39. static_assert(Period::num > 0, "duration period must be positive");
  40. public:
  41. typedef Rep rep;
  42. typedef Period period;
  43. constexpr duration() = default;
  44. template <class Rep2>
  45. constexpr explicit duration(const Rep2& r,
  46. typename enable_if
  47. <
  48. is_convertible<Rep2, rep>::value &&
  49. (treat_as_floating_point<rep>::value ||
  50. !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
  51. >::type* = 0);
  52. // conversions
  53. template <class Rep2, class Period2>
  54. constexpr duration(const duration<Rep2, Period2>& d,
  55. typename enable_if
  56. <
  57. treat_as_floating_point<rep>::value ||
  58. ratio_divide<Period2, period>::type::den == 1
  59. >::type* = 0);
  60. // observer
  61. constexpr rep count() const;
  62. // arithmetic
  63. constexpr duration operator+() const;
  64. constexpr duration operator-() const;
  65. duration& operator++();
  66. duration operator++(int);
  67. duration& operator--();
  68. duration operator--(int);
  69. duration& operator+=(const duration& d);
  70. duration& operator-=(const duration& d);
  71. duration& operator*=(const rep& rhs);
  72. duration& operator/=(const rep& rhs);
  73. // special values
  74. static constexpr duration zero();
  75. static constexpr duration min();
  76. static constexpr duration max();
  77. };
  78. typedef duration<long long, nano> nanoseconds;
  79. typedef duration<long long, micro> microseconds;
  80. typedef duration<long long, milli> milliseconds;
  81. typedef duration<long long > seconds;
  82. typedef duration< long, ratio< 60> > minutes;
  83. typedef duration< long, ratio<3600> > hours;
  84. template <class Clock, class Duration = typename Clock::duration>
  85. class time_point
  86. {
  87. public:
  88. typedef Clock clock;
  89. typedef Duration duration;
  90. typedef typename duration::rep rep;
  91. typedef typename duration::period period;
  92. private:
  93. duration d_; // exposition only
  94. public:
  95. time_point(); // has value "epoch" // constexpr in C++14
  96. explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14
  97. // conversions
  98. template <class Duration2>
  99. time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
  100. // observer
  101. duration time_since_epoch() const; // constexpr in C++14
  102. // arithmetic
  103. time_point& operator+=(const duration& d);
  104. time_point& operator-=(const duration& d);
  105. // special values
  106. static constexpr time_point min();
  107. static constexpr time_point max();
  108. };
  109. } // chrono
  110. // common_type traits
  111. template <class Rep1, class Period1, class Rep2, class Period2>
  112. struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
  113. template <class Clock, class Duration1, class Duration2>
  114. struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
  115. namespace chrono {
  116. // duration arithmetic
  117. template <class Rep1, class Period1, class Rep2, class Period2>
  118. constexpr
  119. typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
  120. operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  121. template <class Rep1, class Period1, class Rep2, class Period2>
  122. constexpr
  123. typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
  124. operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  125. template <class Rep1, class Period, class Rep2>
  126. constexpr
  127. duration<typename common_type<Rep1, Rep2>::type, Period>
  128. operator*(const duration<Rep1, Period>& d, const Rep2& s);
  129. template <class Rep1, class Period, class Rep2>
  130. constexpr
  131. duration<typename common_type<Rep1, Rep2>::type, Period>
  132. operator*(const Rep1& s, const duration<Rep2, Period>& d);
  133. template <class Rep1, class Period, class Rep2>
  134. constexpr
  135. duration<typename common_type<Rep1, Rep2>::type, Period>
  136. operator/(const duration<Rep1, Period>& d, const Rep2& s);
  137. template <class Rep1, class Period1, class Rep2, class Period2>
  138. constexpr
  139. typename common_type<Rep1, Rep2>::type
  140. operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  141. // duration comparisons
  142. template <class Rep1, class Period1, class Rep2, class Period2>
  143. constexpr
  144. bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  145. template <class Rep1, class Period1, class Rep2, class Period2>
  146. constexpr
  147. bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  148. template <class Rep1, class Period1, class Rep2, class Period2>
  149. constexpr
  150. bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  151. template <class Rep1, class Period1, class Rep2, class Period2>
  152. constexpr
  153. bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  154. template <class Rep1, class Period1, class Rep2, class Period2>
  155. constexpr
  156. bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  157. template <class Rep1, class Period1, class Rep2, class Period2>
  158. constexpr
  159. bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  160. // duration_cast
  161. template <class ToDuration, class Rep, class Period>
  162. ToDuration duration_cast(const duration<Rep, Period>& d);
  163. template <class ToDuration, class Rep, class Period>
  164. constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17
  165. template <class ToDuration, class Rep, class Period>
  166. constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17
  167. template <class ToDuration, class Rep, class Period>
  168. constexpr ToDuration round(const duration<Rep, Period>& d); // C++17
  169. // time_point arithmetic (all constexpr in C++14)
  170. template <class Clock, class Duration1, class Rep2, class Period2>
  171. time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
  172. operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
  173. template <class Rep1, class Period1, class Clock, class Duration2>
  174. time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
  175. operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
  176. template <class Clock, class Duration1, class Rep2, class Period2>
  177. time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
  178. operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
  179. template <class Clock, class Duration1, class Duration2>
  180. typename common_type<Duration1, Duration2>::type
  181. operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  182. // time_point comparisons (all constexpr in C++14)
  183. template <class Clock, class Duration1, class Duration2>
  184. bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  185. template <class Clock, class Duration1, class Duration2>
  186. bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  187. template <class Clock, class Duration1, class Duration2>
  188. bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  189. template <class Clock, class Duration1, class Duration2>
  190. bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  191. template <class Clock, class Duration1, class Duration2>
  192. bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  193. template <class Clock, class Duration1, class Duration2>
  194. bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  195. // time_point_cast (constexpr in C++14)
  196. template <class ToDuration, class Clock, class Duration>
  197. time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
  198. template <class ToDuration, class Clock, class Duration>
  199. constexpr time_point<Clock, ToDuration>
  200. floor(const time_point<Clock, Duration>& tp); // C++17
  201. template <class ToDuration, class Clock, class Duration>
  202. constexpr time_point<Clock, ToDuration>
  203. ceil(const time_point<Clock, Duration>& tp); // C++17
  204. template <class ToDuration, class Clock, class Duration>
  205. constexpr time_point<Clock, ToDuration>
  206. round(const time_point<Clock, Duration>& tp); // C++17
  207. template <class Rep, class Period>
  208. constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17
  209. // Clocks
  210. class system_clock
  211. {
  212. public:
  213. typedef microseconds duration;
  214. typedef duration::rep rep;
  215. typedef duration::period period;
  216. typedef chrono::time_point<system_clock> time_point;
  217. static const bool is_steady = false; // constexpr in C++14
  218. static time_point now() noexcept;
  219. static time_t to_time_t (const time_point& __t) noexcept;
  220. static time_point from_time_t(time_t __t) noexcept;
  221. };
  222. class steady_clock
  223. {
  224. public:
  225. typedef nanoseconds duration;
  226. typedef duration::rep rep;
  227. typedef duration::period period;
  228. typedef chrono::time_point<steady_clock, duration> time_point;
  229. static const bool is_steady = true; // constexpr in C++14
  230. static time_point now() noexcept;
  231. };
  232. typedef steady_clock high_resolution_clock;
  233. } // chrono
  234. constexpr chrono::hours operator "" h(unsigned long long); // C++14
  235. constexpr chrono::duration<unspecified , ratio<3600,1>> operator "" h(long double); // C++14
  236. constexpr chrono::minutes operator "" min(unsigned long long); // C++14
  237. constexpr chrono::duration<unspecified , ratio<60,1>> operator "" min(long double); // C++14
  238. constexpr chrono::seconds operator "" s(unsigned long long); // C++14
  239. constexpr chrono::duration<unspecified > operator "" s(long double); // C++14
  240. constexpr chrono::milliseconds operator "" ms(unsigned long long); // C++14
  241. constexpr chrono::duration<unspecified , milli> operator "" ms(long double); // C++14
  242. constexpr chrono::microseconds operator "" us(unsigned long long); // C++14
  243. constexpr chrono::duration<unspecified , micro> operator "" us(long double); // C++14
  244. constexpr chrono::nanoseconds operator "" ns(unsigned long long); // C++14
  245. constexpr chrono::duration<unspecified , nano> operator "" ns(long double); // C++14
  246. } // std
  247. */
  248. // Not supported in SGX.
  249. #include <__config>
  250. #if !defined(_LIBCPP_SGX_CONFIG)
  251. #include <ctime>
  252. #include <type_traits>
  253. #include <ratio>
  254. #include <limits>
  255. #include <__undef_min_max>
  256. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  257. #pragma GCC system_header
  258. #endif
  259. _LIBCPP_BEGIN_NAMESPACE_STD
  260. namespace chrono
  261. {
  262. template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS_ONLY duration;
  263. template <class _Tp>
  264. struct __is_duration : false_type {};
  265. template <class _Rep, class _Period>
  266. struct __is_duration<duration<_Rep, _Period> > : true_type {};
  267. template <class _Rep, class _Period>
  268. struct __is_duration<const duration<_Rep, _Period> > : true_type {};
  269. template <class _Rep, class _Period>
  270. struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
  271. template <class _Rep, class _Period>
  272. struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
  273. } // chrono
  274. template <class _Rep1, class _Period1, class _Rep2, class _Period2>
  275. struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::duration<_Rep1, _Period1>,
  276. chrono::duration<_Rep2, _Period2> >
  277. {
  278. typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
  279. typename __ratio_gcd<_Period1, _Period2>::type> type;
  280. };
  281. namespace chrono {
  282. // duration_cast
  283. template <class _FromDuration, class _ToDuration,
  284. class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
  285. bool = _Period::num == 1,
  286. bool = _Period::den == 1>
  287. struct __duration_cast;
  288. template <class _FromDuration, class _ToDuration, class _Period>
  289. struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
  290. {
  291. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  292. _ToDuration operator()(const _FromDuration& __fd) const
  293. {
  294. return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
  295. }
  296. };
  297. template <class _FromDuration, class _ToDuration, class _Period>
  298. struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
  299. {
  300. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  301. _ToDuration operator()(const _FromDuration& __fd) const
  302. {
  303. typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
  304. return _ToDuration(static_cast<typename _ToDuration::rep>(
  305. static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
  306. }
  307. };
  308. template <class _FromDuration, class _ToDuration, class _Period>
  309. struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
  310. {
  311. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  312. _ToDuration operator()(const _FromDuration& __fd) const
  313. {
  314. typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
  315. return _ToDuration(static_cast<typename _ToDuration::rep>(
  316. static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
  317. }
  318. };
  319. template <class _FromDuration, class _ToDuration, class _Period>
  320. struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
  321. {
  322. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  323. _ToDuration operator()(const _FromDuration& __fd) const
  324. {
  325. typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
  326. return _ToDuration(static_cast<typename _ToDuration::rep>(
  327. static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
  328. / static_cast<_Ct>(_Period::den)));
  329. }
  330. };
  331. template <class _ToDuration, class _Rep, class _Period>
  332. inline _LIBCPP_INLINE_VISIBILITY
  333. _LIBCPP_CONSTEXPR
  334. typename enable_if
  335. <
  336. __is_duration<_ToDuration>::value,
  337. _ToDuration
  338. >::type
  339. duration_cast(const duration<_Rep, _Period>& __fd)
  340. {
  341. return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
  342. }
  343. template <class _Rep>
  344. struct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {};
  345. #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
  346. template <class _Rep> _LIBCPP_CONSTEXPR bool treat_as_floating_point_v
  347. = treat_as_floating_point<_Rep>::value;
  348. #endif
  349. template <class _Rep>
  350. struct _LIBCPP_TYPE_VIS_ONLY duration_values
  351. {
  352. public:
  353. _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);}
  354. _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() {return numeric_limits<_Rep>::max();}
  355. _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();}
  356. };
  357. #if _LIBCPP_STD_VER > 14
  358. template <class _ToDuration, class _Rep, class _Period>
  359. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  360. typename enable_if
  361. <
  362. __is_duration<_ToDuration>::value,
  363. _ToDuration
  364. >::type
  365. floor(const duration<_Rep, _Period>& __d)
  366. {
  367. _ToDuration __t = duration_cast<_ToDuration>(__d);
  368. if (__t > __d)
  369. __t = __t - _ToDuration{1};
  370. return __t;
  371. }
  372. template <class _ToDuration, class _Rep, class _Period>
  373. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  374. typename enable_if
  375. <
  376. __is_duration<_ToDuration>::value,
  377. _ToDuration
  378. >::type
  379. ceil(const duration<_Rep, _Period>& __d)
  380. {
  381. _ToDuration __t = duration_cast<_ToDuration>(__d);
  382. if (__t < __d)
  383. __t = __t + _ToDuration{1};
  384. return __t;
  385. }
  386. template <class _ToDuration, class _Rep, class _Period>
  387. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  388. typename enable_if
  389. <
  390. __is_duration<_ToDuration>::value,
  391. _ToDuration
  392. >::type
  393. round(const duration<_Rep, _Period>& __d)
  394. {
  395. _ToDuration __lower = floor<_ToDuration>(__d);
  396. _ToDuration __upper = __lower + _ToDuration{1};
  397. auto __lowerDiff = __d - __lower;
  398. auto __upperDiff = __upper - __d;
  399. if (__lowerDiff < __upperDiff)
  400. return __lower;
  401. if (__lowerDiff > __upperDiff)
  402. return __upper;
  403. return __lower.count() & 1 ? __upper : __lower;
  404. }
  405. #endif
  406. // duration
  407. template <class _Rep, class _Period>
  408. class _LIBCPP_TYPE_VIS_ONLY duration
  409. {
  410. static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
  411. static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
  412. static_assert(_Period::num > 0, "duration period must be positive");
  413. template <class _R1, class _R2>
  414. struct __no_overflow
  415. {
  416. private:
  417. static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
  418. static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
  419. static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
  420. static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
  421. static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
  422. static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
  423. static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
  424. template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
  425. struct __mul // __overflow == false
  426. {
  427. static const intmax_t value = _Xp * _Yp;
  428. };
  429. template <intmax_t _Xp, intmax_t _Yp>
  430. struct __mul<_Xp, _Yp, true>
  431. {
  432. static const intmax_t value = 1;
  433. };
  434. public:
  435. static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
  436. typedef ratio<__mul<__n1, __d2, !value>::value,
  437. __mul<__n2, __d1, !value>::value> type;
  438. };
  439. public:
  440. typedef _Rep rep;
  441. typedef _Period period;
  442. private:
  443. rep __rep_;
  444. public:
  445. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  446. #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
  447. duration() = default;
  448. #else
  449. duration() {}
  450. #endif
  451. template <class _Rep2>
  452. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  453. explicit duration(const _Rep2& __r,
  454. typename enable_if
  455. <
  456. is_convertible<_Rep2, rep>::value &&
  457. (treat_as_floating_point<rep>::value ||
  458. !treat_as_floating_point<_Rep2>::value)
  459. >::type* = 0)
  460. : __rep_(__r) {}
  461. // conversions
  462. template <class _Rep2, class _Period2>
  463. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  464. duration(const duration<_Rep2, _Period2>& __d,
  465. typename enable_if
  466. <
  467. __no_overflow<_Period2, period>::value && (
  468. treat_as_floating_point<rep>::value ||
  469. (__no_overflow<_Period2, period>::type::den == 1 &&
  470. !treat_as_floating_point<_Rep2>::value))
  471. >::type* = 0)
  472. : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
  473. // observer
  474. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
  475. // arithmetic
  476. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;}
  477. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);}
  478. _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;}
  479. _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);}
  480. _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;}
  481. _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);}
  482. _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
  483. _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
  484. _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
  485. _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
  486. _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
  487. _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
  488. // special values
  489. _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
  490. _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values<rep>::min());}
  491. _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values<rep>::max());}
  492. };
  493. typedef duration<long long, nano> nanoseconds;
  494. typedef duration<long long, micro> microseconds;
  495. typedef duration<long long, milli> milliseconds;
  496. typedef duration<long long > seconds;
  497. typedef duration< long, ratio< 60> > minutes;
  498. typedef duration< long, ratio<3600> > hours;
  499. // Duration ==
  500. template <class _LhsDuration, class _RhsDuration>
  501. struct __duration_eq
  502. {
  503. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  504. bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
  505. {
  506. typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
  507. return _Ct(__lhs).count() == _Ct(__rhs).count();
  508. }
  509. };
  510. template <class _LhsDuration>
  511. struct __duration_eq<_LhsDuration, _LhsDuration>
  512. {
  513. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  514. bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
  515. {return __lhs.count() == __rhs.count();}
  516. };
  517. template <class _Rep1, class _Period1, class _Rep2, class _Period2>
  518. inline _LIBCPP_INLINE_VISIBILITY
  519. _LIBCPP_CONSTEXPR
  520. bool
  521. operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  522. {
  523. return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
  524. }
  525. // Duration !=
  526. template <class _Rep1, class _Period1, class _Rep2, class _Period2>
  527. inline _LIBCPP_INLINE_VISIBILITY
  528. _LIBCPP_CONSTEXPR
  529. bool
  530. operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  531. {
  532. return !(__lhs == __rhs);
  533. }
  534. // Duration <
  535. template <class _LhsDuration, class _RhsDuration>
  536. struct __duration_lt
  537. {
  538. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  539. bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
  540. {
  541. typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
  542. return _Ct(__lhs).count() < _Ct(__rhs).count();
  543. }
  544. };
  545. template <class _LhsDuration>
  546. struct __duration_lt<_LhsDuration, _LhsDuration>
  547. {
  548. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  549. bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
  550. {return __lhs.count() < __rhs.count();}
  551. };
  552. template <class _Rep1, class _Period1, class _Rep2, class _Period2>
  553. inline _LIBCPP_INLINE_VISIBILITY
  554. _LIBCPP_CONSTEXPR
  555. bool
  556. operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  557. {
  558. return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
  559. }
  560. // Duration >
  561. template <class _Rep1, class _Period1, class _Rep2, class _Period2>
  562. inline _LIBCPP_INLINE_VISIBILITY
  563. _LIBCPP_CONSTEXPR
  564. bool
  565. operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  566. {
  567. return __rhs < __lhs;
  568. }
  569. // Duration <=
  570. template <class _Rep1, class _Period1, class _Rep2, class _Period2>
  571. inline _LIBCPP_INLINE_VISIBILITY
  572. _LIBCPP_CONSTEXPR
  573. bool
  574. operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  575. {
  576. return !(__rhs < __lhs);
  577. }
  578. // Duration >=
  579. template <class _Rep1, class _Period1, class _Rep2, class _Period2>
  580. inline _LIBCPP_INLINE_VISIBILITY
  581. _LIBCPP_CONSTEXPR
  582. bool
  583. operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  584. {
  585. return !(__lhs < __rhs);
  586. }
  587. // Duration +
  588. template <class _Rep1, class _Period1, class _Rep2, class _Period2>
  589. inline _LIBCPP_INLINE_VISIBILITY
  590. _LIBCPP_CONSTEXPR
  591. typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
  592. operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  593. {
  594. typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
  595. return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
  596. }
  597. // Duration -
  598. template <class _Rep1, class _Period1, class _Rep2, class _Period2>
  599. inline _LIBCPP_INLINE_VISIBILITY
  600. _LIBCPP_CONSTEXPR
  601. typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
  602. operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  603. {
  604. typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
  605. return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
  606. }
  607. // Duration *
  608. template <class _Rep1, class _Period, class _Rep2>
  609. inline _LIBCPP_INLINE_VISIBILITY
  610. _LIBCPP_CONSTEXPR
  611. typename enable_if
  612. <
  613. is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
  614. duration<typename common_type<_Rep1, _Rep2>::type, _Period>
  615. >::type
  616. operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
  617. {
  618. typedef typename common_type<_Rep1, _Rep2>::type _Cr;
  619. typedef duration<_Cr, _Period> _Cd;
  620. return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
  621. }
  622. template <class _Rep1, class _Period, class _Rep2>
  623. inline _LIBCPP_INLINE_VISIBILITY
  624. _LIBCPP_CONSTEXPR
  625. typename enable_if
  626. <
  627. is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
  628. duration<typename common_type<_Rep1, _Rep2>::type, _Period>
  629. >::type
  630. operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
  631. {
  632. return __d * __s;
  633. }
  634. // Duration /
  635. template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
  636. struct __duration_divide_result
  637. {
  638. };
  639. template <class _Duration, class _Rep2,
  640. bool = is_convertible<_Rep2,
  641. typename common_type<typename _Duration::rep, _Rep2>::type>::value>
  642. struct __duration_divide_imp
  643. {
  644. };
  645. template <class _Rep1, class _Period, class _Rep2>
  646. struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
  647. {
  648. typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
  649. };
  650. template <class _Rep1, class _Period, class _Rep2>
  651. struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
  652. : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
  653. {
  654. };
  655. template <class _Rep1, class _Period, class _Rep2>
  656. inline _LIBCPP_INLINE_VISIBILITY
  657. _LIBCPP_CONSTEXPR
  658. typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
  659. operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
  660. {
  661. typedef typename common_type<_Rep1, _Rep2>::type _Cr;
  662. typedef duration<_Cr, _Period> _Cd;
  663. return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
  664. }
  665. template <class _Rep1, class _Period1, class _Rep2, class _Period2>
  666. inline _LIBCPP_INLINE_VISIBILITY
  667. _LIBCPP_CONSTEXPR
  668. typename common_type<_Rep1, _Rep2>::type
  669. operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  670. {
  671. typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
  672. return _Ct(__lhs).count() / _Ct(__rhs).count();
  673. }
  674. // Duration %
  675. template <class _Rep1, class _Period, class _Rep2>
  676. inline _LIBCPP_INLINE_VISIBILITY
  677. _LIBCPP_CONSTEXPR
  678. typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
  679. operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
  680. {
  681. typedef typename common_type<_Rep1, _Rep2>::type _Cr;
  682. typedef duration<_Cr, _Period> _Cd;
  683. return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
  684. }
  685. template <class _Rep1, class _Period1, class _Rep2, class _Period2>
  686. inline _LIBCPP_INLINE_VISIBILITY
  687. _LIBCPP_CONSTEXPR
  688. typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
  689. operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  690. {
  691. typedef typename common_type<_Rep1, _Rep2>::type _Cr;
  692. typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
  693. return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
  694. }
  695. //////////////////////////////////////////////////////////
  696. ///////////////////// time_point /////////////////////////
  697. //////////////////////////////////////////////////////////
  698. template <class _Clock, class _Duration = typename _Clock::duration>
  699. class _LIBCPP_TYPE_VIS_ONLY time_point
  700. {
  701. static_assert(__is_duration<_Duration>::value,
  702. "Second template parameter of time_point must be a std::chrono::duration");
  703. public:
  704. typedef _Clock clock;
  705. typedef _Duration duration;
  706. typedef typename duration::rep rep;
  707. typedef typename duration::period period;
  708. private:
  709. duration __d_;
  710. public:
  711. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
  712. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
  713. // conversions
  714. template <class _Duration2>
  715. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  716. time_point(const time_point<clock, _Duration2>& t,
  717. typename enable_if
  718. <
  719. is_convertible<_Duration2, duration>::value
  720. >::type* = 0)
  721. : __d_(t.time_since_epoch()) {}
  722. // observer
  723. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
  724. // arithmetic
  725. _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
  726. _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
  727. // special values
  728. _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());}
  729. _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());}
  730. };
  731. } // chrono
  732. template <class _Clock, class _Duration1, class _Duration2>
  733. struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::time_point<_Clock, _Duration1>,
  734. chrono::time_point<_Clock, _Duration2> >
  735. {
  736. typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
  737. };
  738. namespace chrono {
  739. template <class _ToDuration, class _Clock, class _Duration>
  740. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  741. time_point<_Clock, _ToDuration>
  742. time_point_cast(const time_point<_Clock, _Duration>& __t)
  743. {
  744. return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
  745. }
  746. #if _LIBCPP_STD_VER > 14
  747. template <class _ToDuration, class _Clock, class _Duration>
  748. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  749. typename enable_if
  750. <
  751. __is_duration<_ToDuration>::value,
  752. time_point<_Clock, _ToDuration>
  753. >::type
  754. floor(const time_point<_Clock, _Duration>& __t)
  755. {
  756. return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
  757. }
  758. template <class _ToDuration, class _Clock, class _Duration>
  759. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  760. typename enable_if
  761. <
  762. __is_duration<_ToDuration>::value,
  763. time_point<_Clock, _ToDuration>
  764. >::type
  765. ceil(const time_point<_Clock, _Duration>& __t)
  766. {
  767. return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
  768. }
  769. template <class _ToDuration, class _Clock, class _Duration>
  770. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  771. typename enable_if
  772. <
  773. __is_duration<_ToDuration>::value,
  774. time_point<_Clock, _ToDuration>
  775. >::type
  776. round(const time_point<_Clock, _Duration>& __t)
  777. {
  778. return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
  779. }
  780. template <class _Rep, class _Period>
  781. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  782. typename enable_if
  783. <
  784. numeric_limits<_Rep>::is_signed,
  785. duration<_Rep, _Period>
  786. >::type
  787. abs(duration<_Rep, _Period> __d)
  788. {
  789. return __d >= __d.zero() ? __d : -__d;
  790. }
  791. #endif
  792. // time_point ==
  793. template <class _Clock, class _Duration1, class _Duration2>
  794. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  795. bool
  796. operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
  797. {
  798. return __lhs.time_since_epoch() == __rhs.time_since_epoch();
  799. }
  800. // time_point !=
  801. template <class _Clock, class _Duration1, class _Duration2>
  802. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  803. bool
  804. operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
  805. {
  806. return !(__lhs == __rhs);
  807. }
  808. // time_point <
  809. template <class _Clock, class _Duration1, class _Duration2>
  810. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  811. bool
  812. operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
  813. {
  814. return __lhs.time_since_epoch() < __rhs.time_since_epoch();
  815. }
  816. // time_point >
  817. template <class _Clock, class _Duration1, class _Duration2>
  818. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  819. bool
  820. operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
  821. {
  822. return __rhs < __lhs;
  823. }
  824. // time_point <=
  825. template <class _Clock, class _Duration1, class _Duration2>
  826. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  827. bool
  828. operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
  829. {
  830. return !(__rhs < __lhs);
  831. }
  832. // time_point >=
  833. template <class _Clock, class _Duration1, class _Duration2>
  834. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  835. bool
  836. operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
  837. {
  838. return !(__lhs < __rhs);
  839. }
  840. // time_point operator+(time_point x, duration y);
  841. template <class _Clock, class _Duration1, class _Rep2, class _Period2>
  842. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  843. time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
  844. operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  845. {
  846. typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
  847. return _Tr (__lhs.time_since_epoch() + __rhs);
  848. }
  849. // time_point operator+(duration x, time_point y);
  850. template <class _Rep1, class _Period1, class _Clock, class _Duration2>
  851. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  852. time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
  853. operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
  854. {
  855. return __rhs + __lhs;
  856. }
  857. // time_point operator-(time_point x, duration y);
  858. template <class _Clock, class _Duration1, class _Rep2, class _Period2>
  859. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  860. time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
  861. operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
  862. {
  863. return __lhs + (-__rhs);
  864. }
  865. // duration operator-(time_point x, time_point y);
  866. template <class _Clock, class _Duration1, class _Duration2>
  867. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  868. typename common_type<_Duration1, _Duration2>::type
  869. operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
  870. {
  871. return __lhs.time_since_epoch() - __rhs.time_since_epoch();
  872. }
  873. //////////////////////////////////////////////////////////
  874. /////////////////////// clocks ///////////////////////////
  875. //////////////////////////////////////////////////////////
  876. class _LIBCPP_TYPE_VIS system_clock
  877. {
  878. public:
  879. typedef microseconds duration;
  880. typedef duration::rep rep;
  881. typedef duration::period period;
  882. typedef chrono::time_point<system_clock> time_point;
  883. static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
  884. static time_point now() _NOEXCEPT;
  885. static time_t to_time_t (const time_point& __t) _NOEXCEPT;
  886. static time_point from_time_t(time_t __t) _NOEXCEPT;
  887. };
  888. #ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
  889. class _LIBCPP_TYPE_VIS steady_clock
  890. {
  891. public:
  892. typedef nanoseconds duration;
  893. typedef duration::rep rep;
  894. typedef duration::period period;
  895. typedef chrono::time_point<steady_clock, duration> time_point;
  896. static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
  897. static time_point now() _NOEXCEPT;
  898. };
  899. typedef steady_clock high_resolution_clock;
  900. #else
  901. typedef system_clock high_resolution_clock;
  902. #endif
  903. } // chrono
  904. #if _LIBCPP_STD_VER > 11
  905. // Suffixes for duration literals [time.duration.literals]
  906. inline namespace literals
  907. {
  908. inline namespace chrono_literals
  909. {
  910. constexpr chrono::hours operator"" h(unsigned long long __h)
  911. {
  912. return chrono::hours(static_cast<chrono::hours::rep>(__h));
  913. }
  914. constexpr chrono::duration<long double, ratio<3600,1>> operator"" h(long double __h)
  915. {
  916. return chrono::duration<long double, ratio<3600,1>>(__h);
  917. }
  918. constexpr chrono::minutes operator"" min(unsigned long long __m)
  919. {
  920. return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
  921. }
  922. constexpr chrono::duration<long double, ratio<60,1>> operator"" min(long double __m)
  923. {
  924. return chrono::duration<long double, ratio<60,1>> (__m);
  925. }
  926. constexpr chrono::seconds operator"" s(unsigned long long __s)
  927. {
  928. return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
  929. }
  930. constexpr chrono::duration<long double> operator"" s(long double __s)
  931. {
  932. return chrono::duration<long double> (__s);
  933. }
  934. constexpr chrono::milliseconds operator"" ms(unsigned long long __ms)
  935. {
  936. return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
  937. }
  938. constexpr chrono::duration<long double, milli> operator"" ms(long double __ms)
  939. {
  940. return chrono::duration<long double, milli>(__ms);
  941. }
  942. constexpr chrono::microseconds operator"" us(unsigned long long __us)
  943. {
  944. return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
  945. }
  946. constexpr chrono::duration<long double, micro> operator"" us(long double __us)
  947. {
  948. return chrono::duration<long double, micro> (__us);
  949. }
  950. constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns)
  951. {
  952. return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
  953. }
  954. constexpr chrono::duration<long double, nano> operator"" ns(long double __ns)
  955. {
  956. return chrono::duration<long double, nano> (__ns);
  957. }
  958. }}
  959. namespace chrono { // hoist the literals into namespace std::chrono
  960. using namespace literals::chrono_literals;
  961. }
  962. #endif
  963. _LIBCPP_END_NAMESPACE_STD
  964. #endif // !defined(_LIBCPP_SGX_CONFIG)
  965. #endif // _LIBCPP_CHRONO