chrono 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_CHRONO
  10. #define _LIBCPP_CHRONO
  11. /*
  12. chrono synopsis
  13. #include <compare> // C++20
  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> inline 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(); // noexcept in C++20
  30. static constexpr Rep max(); // noexcept in C++20
  31. static constexpr Rep min(); // noexcept in C++20
  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 typename _Period::type 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 common_type<duration>::type operator+() const;
  64. constexpr common_type<duration>::type operator-() const;
  65. constexpr duration& operator++(); // constexpr in C++17
  66. constexpr duration operator++(int); // constexpr in C++17
  67. constexpr duration& operator--(); // constexpr in C++17
  68. constexpr duration operator--(int); // constexpr in C++17
  69. constexpr duration& operator+=(const duration& d); // constexpr in C++17
  70. constexpr duration& operator-=(const duration& d); // constexpr in C++17
  71. duration& operator*=(const rep& rhs); // constexpr in C++17
  72. duration& operator/=(const rep& rhs); // constexpr in C++17
  73. duration& operator%=(const rep& rhs); // constexpr in C++17
  74. duration& operator%=(const duration& rhs); // constexpr in C++17
  75. // special values
  76. static constexpr duration zero(); // noexcept in C++20
  77. static constexpr duration min(); // noexcept in C++20
  78. static constexpr duration max(); // noexcept in C++20
  79. };
  80. typedef duration<long long, nano> nanoseconds;
  81. typedef duration<long long, micro> microseconds;
  82. typedef duration<long long, milli> milliseconds;
  83. typedef duration<long long > seconds;
  84. typedef duration< long, ratio< 60> > minutes;
  85. typedef duration< long, ratio<3600> > hours;
  86. template <class Clock, class Duration = typename Clock::duration>
  87. class time_point
  88. {
  89. public:
  90. typedef Clock clock;
  91. typedef Duration duration;
  92. typedef typename duration::rep rep;
  93. typedef typename duration::period period;
  94. private:
  95. duration d_; // exposition only
  96. public:
  97. time_point(); // has value "epoch" // constexpr in C++14
  98. explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14
  99. // conversions
  100. template <class Duration2>
  101. time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
  102. // observer
  103. duration time_since_epoch() const; // constexpr in C++14
  104. // arithmetic
  105. time_point& operator+=(const duration& d); // constexpr in C++17
  106. time_point& operator-=(const duration& d); // constexpr in C++17
  107. // special values
  108. static constexpr time_point min(); // noexcept in C++20
  109. static constexpr time_point max(); // noexcept in C++20
  110. };
  111. } // chrono
  112. // common_type traits
  113. template <class Rep1, class Period1, class Rep2, class Period2>
  114. struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
  115. template <class Clock, class Duration1, class Duration2>
  116. struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
  117. namespace chrono {
  118. // duration arithmetic
  119. template <class Rep1, class Period1, class Rep2, class Period2>
  120. constexpr
  121. typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
  122. operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  123. template <class Rep1, class Period1, class Rep2, class Period2>
  124. constexpr
  125. typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
  126. operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  127. template <class Rep1, class Period, class Rep2>
  128. constexpr
  129. duration<typename common_type<Rep1, Rep2>::type, Period>
  130. operator*(const duration<Rep1, Period>& d, const Rep2& s);
  131. template <class Rep1, class Period, class Rep2>
  132. constexpr
  133. duration<typename common_type<Rep1, Rep2>::type, Period>
  134. operator*(const Rep1& s, const duration<Rep2, Period>& d);
  135. template <class Rep1, class Period, class Rep2>
  136. constexpr
  137. duration<typename common_type<Rep1, Rep2>::type, Period>
  138. operator/(const duration<Rep1, Period>& d, const Rep2& s);
  139. template <class Rep1, class Period1, class Rep2, class Period2>
  140. constexpr
  141. typename common_type<Rep1, Rep2>::type
  142. operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  143. // duration comparisons
  144. template <class Rep1, class Period1, class Rep2, class Period2>
  145. constexpr
  146. bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  147. template <class Rep1, class Period1, class Rep2, class Period2>
  148. constexpr
  149. bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  150. template <class Rep1, class Period1, class Rep2, class Period2>
  151. constexpr
  152. bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  153. template <class Rep1, class Period1, class Rep2, class Period2>
  154. constexpr
  155. bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  156. template <class Rep1, class Period1, class Rep2, class Period2>
  157. constexpr
  158. bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  159. template <class Rep1, class Period1, class Rep2, class Period2>
  160. constexpr
  161. bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  162. // duration_cast
  163. template <class ToDuration, class Rep, class Period>
  164. ToDuration duration_cast(const duration<Rep, Period>& d);
  165. template <class ToDuration, class Rep, class Period>
  166. constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17
  167. template <class ToDuration, class Rep, class Period>
  168. constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17
  169. template <class ToDuration, class Rep, class Period>
  170. constexpr ToDuration round(const duration<Rep, Period>& d); // C++17
  171. // duration I/O
  172. template<class charT, class traits, class Rep, class Period> // C++20
  173. basic_ostream<charT, traits>&
  174. operator<<(basic_ostream<charT, traits>& os,
  175. const duration<Rep, Period>& d);
  176. // time_point arithmetic (all constexpr in C++14)
  177. template <class Clock, class Duration1, class Rep2, class Period2>
  178. time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
  179. operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
  180. template <class Rep1, class Period1, class Clock, class Duration2>
  181. time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
  182. operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
  183. template <class Clock, class Duration1, class Rep2, class Period2>
  184. time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
  185. operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
  186. template <class Clock, class Duration1, class Duration2>
  187. typename common_type<Duration1, Duration2>::type
  188. operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  189. // time_point comparisons (all constexpr in C++14)
  190. template <class Clock, class Duration1, class Duration2>
  191. bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  192. template <class Clock, class Duration1, class Duration2>
  193. bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  194. template <class Clock, class Duration1, class Duration2>
  195. bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  196. template <class Clock, class Duration1, class Duration2>
  197. bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  198. template <class Clock, class Duration1, class Duration2>
  199. bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  200. template <class Clock, class Duration1, class Duration2>
  201. bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  202. // time_point_cast (constexpr in C++14)
  203. template <class ToDuration, class Clock, class Duration>
  204. time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
  205. template <class ToDuration, class Clock, class Duration>
  206. constexpr time_point<Clock, ToDuration>
  207. floor(const time_point<Clock, Duration>& tp); // C++17
  208. template <class ToDuration, class Clock, class Duration>
  209. constexpr time_point<Clock, ToDuration>
  210. ceil(const time_point<Clock, Duration>& tp); // C++17
  211. template <class ToDuration, class Clock, class Duration>
  212. constexpr time_point<Clock, ToDuration>
  213. round(const time_point<Clock, Duration>& tp); // C++17
  214. template <class Rep, class Period>
  215. constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17
  216. // Clocks
  217. class system_clock
  218. {
  219. public:
  220. typedef microseconds duration;
  221. typedef duration::rep rep;
  222. typedef duration::period period;
  223. typedef chrono::time_point<system_clock> time_point;
  224. static const bool is_steady = false; // constexpr in C++14
  225. static time_point now() noexcept;
  226. static time_t to_time_t (const time_point& __t) noexcept;
  227. static time_point from_time_t(time_t __t) noexcept;
  228. };
  229. template <class Duration>
  230. using sys_time = time_point<system_clock, Duration>; // C++20
  231. using sys_seconds = sys_time<seconds>; // C++20
  232. using sys_days = sys_time<days>; // C++20
  233. class file_clock // C++20
  234. {
  235. public:
  236. typedef see-below rep;
  237. typedef nano period;
  238. typedef chrono::duration<rep, period> duration;
  239. typedef chrono::time_point<file_clock> time_point;
  240. static constexpr bool is_steady = false;
  241. static time_point now() noexcept;
  242. template<class Duration>
  243. static sys_time<see-below> to_sys(const file_time<Duration>&);
  244. template<class Duration>
  245. static file_time<see-below> from_sys(const sys_time<Duration>&);
  246. };
  247. template<class Duration>
  248. using file_time = time_point<file_clock, Duration>; // C++20
  249. class steady_clock
  250. {
  251. public:
  252. typedef nanoseconds duration;
  253. typedef duration::rep rep;
  254. typedef duration::period period;
  255. typedef chrono::time_point<steady_clock, duration> time_point;
  256. static const bool is_steady = true; // constexpr in C++14
  257. static time_point now() noexcept;
  258. };
  259. typedef steady_clock high_resolution_clock;
  260. // 25.7.8, local time // C++20
  261. struct local_t {};
  262. template<class Duration>
  263. using local_time = time_point<local_t, Duration>;
  264. using local_seconds = local_time<seconds>;
  265. using local_days = local_time<days>;
  266. // 25.8.2, class last_spec // C++20
  267. struct last_spec;
  268. // 25.8.3, class day // C++20
  269. class day;
  270. constexpr bool operator==(const day& x, const day& y) noexcept;
  271. constexpr strong_ordering operator<=>(const day& x, const day& y) noexcept;
  272. constexpr day operator+(const day& x, const days& y) noexcept;
  273. constexpr day operator+(const days& x, const day& y) noexcept;
  274. constexpr day operator-(const day& x, const days& y) noexcept;
  275. constexpr days operator-(const day& x, const day& y) noexcept;
  276. template<class charT, class traits>
  277. basic_ostream<charT, traits>&
  278. operator<<(basic_ostream<charT, traits>& os, const day& d);
  279. // 25.8.4, class month // C++20
  280. class month;
  281. constexpr bool operator==(const month& x, const month& y) noexcept;
  282. constexpr strong_ordering operator<=>(const month& x, const month& y) noexcept;
  283. constexpr month operator+(const month& x, const months& y) noexcept;
  284. constexpr month operator+(const months& x, const month& y) noexcept;
  285. constexpr month operator-(const month& x, const months& y) noexcept;
  286. constexpr months operator-(const month& x, const month& y) noexcept;
  287. template<class charT, class traits>
  288. basic_ostream<charT, traits>&
  289. operator<<(basic_ostream<charT, traits>& os, const month& m);
  290. // 25.8.5, class year // C++20
  291. class year;
  292. constexpr bool operator==(const year& x, const year& y) noexcept;
  293. constexpr strong_ordering operator<=>(const year& x, const year& y) noexcept;
  294. constexpr year operator+(const year& x, const years& y) noexcept;
  295. constexpr year operator+(const years& x, const year& y) noexcept;
  296. constexpr year operator-(const year& x, const years& y) noexcept;
  297. constexpr years operator-(const year& x, const year& y) noexcept;
  298. template<class charT, class traits>
  299. basic_ostream<charT, traits>&
  300. operator<<(basic_ostream<charT, traits>& os, const year& y);
  301. // 25.8.6, class weekday // C++20
  302. class weekday;
  303. constexpr bool operator==(const weekday& x, const weekday& y) noexcept;
  304. constexpr bool operator!=(const weekday& x, const weekday& y) noexcept;
  305. constexpr weekday operator+(const weekday& x, const days& y) noexcept;
  306. constexpr weekday operator+(const days& x, const weekday& y) noexcept;
  307. constexpr weekday operator-(const weekday& x, const days& y) noexcept;
  308. constexpr days operator-(const weekday& x, const weekday& y) noexcept;
  309. template<class charT, class traits>
  310. basic_ostream<charT, traits>&
  311. operator<<(basic_ostream<charT, traits>& os, const weekday& wd);
  312. // 25.8.7, class weekday_indexed // C++20
  313. class weekday_indexed;
  314. constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept;
  315. constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept;
  316. template<class charT, class traits>
  317. basic_ostream<charT, traits>&
  318. operator<<(basic_ostream<charT, traits>& os, const weekday_indexed& wdi);
  319. // 25.8.8, class weekday_last // C++20
  320. class weekday_last;
  321. constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept;
  322. constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept;
  323. template<class charT, class traits>
  324. basic_ostream<charT, traits>&
  325. operator<<(basic_ostream<charT, traits>& os, const weekday_last& wdl);
  326. // 25.8.9, class month_day // C++20
  327. class month_day;
  328. constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
  329. constexpr strong_ordering operator<=>(const month_day& x, const month_day& y) noexcept;
  330. template<class charT, class traits>
  331. basic_ostream<charT, traits>&
  332. operator<<(basic_ostream<charT, traits>& os, const month_day& md);
  333. // 25.8.10, class month_day_last // C++20
  334. class month_day_last;
  335. constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept;
  336. constexpr strong_ordering operator<=>(const month_day_last& x, const month_day_last& y) noexcept;
  337. template<class charT, class traits>
  338. basic_ostream<charT, traits>&
  339. operator<<(basic_ostream<charT, traits>& os, const month_day_last& mdl);
  340. // 25.8.11, class month_weekday // C++20
  341. class month_weekday;
  342. constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept;
  343. constexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept;
  344. template<class charT, class traits>
  345. basic_ostream<charT, traits>&
  346. operator<<(basic_ostream<charT, traits>& os, const month_weekday& mwd);
  347. // 25.8.12, class month_weekday_last // C++20
  348. class month_weekday_last;
  349. constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept;
  350. constexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept;
  351. template<class charT, class traits>
  352. basic_ostream<charT, traits>&
  353. operator<<(basic_ostream<charT, traits>& os, const month_weekday_last& mwdl);
  354. // 25.8.13, class year_month // C++20
  355. class year_month;
  356. constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
  357. constexpr strong_ordering operator<=>(const year_month& x, const year_month& y) noexcept;
  358. constexpr year_month operator+(const year_month& ym, const months& dm) noexcept;
  359. constexpr year_month operator+(const months& dm, const year_month& ym) noexcept;
  360. constexpr year_month operator-(const year_month& ym, const months& dm) noexcept;
  361. constexpr months operator-(const year_month& x, const year_month& y) noexcept;
  362. constexpr year_month operator+(const year_month& ym, const years& dy) noexcept;
  363. constexpr year_month operator+(const years& dy, const year_month& ym) noexcept;
  364. constexpr year_month operator-(const year_month& ym, const years& dy) noexcept;
  365. template<class charT, class traits>
  366. basic_ostream<charT, traits>&
  367. operator<<(basic_ostream<charT, traits>& os, const year_month& ym);
  368. // 25.8.14, class year_month_day class // C++20
  369. year_month_day;
  370. constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
  371. constexpr strong_ordering operator<=>(const year_month_day& x, const year_month_day& y) noexcept;
  372. constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept;
  373. constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept;
  374. constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept;
  375. constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept;
  376. constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept;
  377. constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept;
  378. template<class charT, class traits>
  379. basic_ostream<charT, traits>&
  380. operator<<(basic_ostream<charT, traits>& os, const year_month_day& ymd);
  381. // 25.8.15, class year_month_day_last // C++20
  382. class year_month_day_last;
  383. constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept;
  384. constexpr strong_ordering operator<=>(const year_month_day_last_day& x, const year_month_day_last_day& y) noexcept;
  385. constexpr year_month_day_last
  386. operator+(const year_month_day_last& ymdl, const months& dm) noexcept;
  387. constexpr year_month_day_last
  388. operator+(const months& dm, const year_month_day_last& ymdl) noexcept;
  389. constexpr year_month_day_last
  390. operator+(const year_month_day_last& ymdl, const years& dy) noexcept;
  391. constexpr year_month_day_last
  392. operator+(const years& dy, const year_month_day_last& ymdl) noexcept;
  393. constexpr year_month_day_last
  394. operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
  395. constexpr year_month_day_last
  396. operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
  397. template<class charT, class traits>
  398. basic_ostream<charT, traits>&
  399. operator<<(basic_ostream<charT, traits>& os, const year_month_day_last& ymdl);
  400. // 25.8.16, class year_month_weekday // C++20
  401. class year_month_weekday;
  402. constexpr bool operator==(const year_month_weekday& x,
  403. const year_month_weekday& y) noexcept;
  404. constexpr bool operator!=(const year_month_weekday& x,
  405. const year_month_weekday& y) noexcept;
  406. constexpr year_month_weekday
  407. operator+(const year_month_weekday& ymwd, const months& dm) noexcept;
  408. constexpr year_month_weekday
  409. operator+(const months& dm, const year_month_weekday& ymwd) noexcept;
  410. constexpr year_month_weekday
  411. operator+(const year_month_weekday& ymwd, const years& dy) noexcept;
  412. constexpr year_month_weekday
  413. operator+(const years& dy, const year_month_weekday& ymwd) noexcept;
  414. constexpr year_month_weekday
  415. operator-(const year_month_weekday& ymwd, const months& dm) noexcept;
  416. constexpr year_month_weekday
  417. operator-(const year_month_weekday& ymwd, const years& dy) noexcept;
  418. template<class charT, class traits>
  419. basic_ostream<charT, traits>&
  420. operator<<(basic_ostream<charT, traits>& os, const year_month_weekday& ymwd);
  421. // 25.8.17, class year_month_weekday_last // C++20
  422. class year_month_weekday_last;
  423. constexpr bool operator==(const year_month_weekday_last& x,
  424. const year_month_weekday_last& y) noexcept;
  425. constexpr bool operator!=(const year_month_weekday_last& x,
  426. const year_month_weekday_last& y) noexcept;
  427. constexpr year_month_weekday_last
  428. operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
  429. constexpr year_month_weekday_last
  430. operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept;
  431. constexpr year_month_weekday_last
  432. operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
  433. constexpr year_month_weekday_last
  434. operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept;
  435. constexpr year_month_weekday_last
  436. operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
  437. constexpr year_month_weekday_last
  438. operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
  439. template<class charT, class traits>
  440. basic_ostream<charT, traits>&
  441. operator<<(basic_ostream<charT, traits>& os, const year_month_weekday_last& ymwdl);
  442. // 25.8.18, civil calendar conventional syntax operators // C++20
  443. constexpr year_month
  444. operator/(const year& y, const month& m) noexcept;
  445. constexpr year_month
  446. operator/(const year& y, int m) noexcept;
  447. constexpr month_day
  448. operator/(const month& m, const day& d) noexcept;
  449. constexpr month_day
  450. operator/(const month& m, int d) noexcept;
  451. constexpr month_day
  452. operator/(int m, const day& d) noexcept;
  453. constexpr month_day
  454. operator/(const day& d, const month& m) noexcept;
  455. constexpr month_day
  456. operator/(const day& d, int m) noexcept;
  457. constexpr month_day_last
  458. operator/(const month& m, last_spec) noexcept;
  459. constexpr month_day_last
  460. operator/(int m, last_spec) noexcept;
  461. constexpr month_day_last
  462. operator/(last_spec, const month& m) noexcept;
  463. constexpr month_day_last
  464. operator/(last_spec, int m) noexcept;
  465. constexpr month_weekday
  466. operator/(const month& m, const weekday_indexed& wdi) noexcept;
  467. constexpr month_weekday
  468. operator/(int m, const weekday_indexed& wdi) noexcept;
  469. constexpr month_weekday
  470. operator/(const weekday_indexed& wdi, const month& m) noexcept;
  471. constexpr month_weekday
  472. operator/(const weekday_indexed& wdi, int m) noexcept;
  473. constexpr month_weekday_last
  474. operator/(const month& m, const weekday_last& wdl) noexcept;
  475. constexpr month_weekday_last
  476. operator/(int m, const weekday_last& wdl) noexcept;
  477. constexpr month_weekday_last
  478. operator/(const weekday_last& wdl, const month& m) noexcept;
  479. constexpr month_weekday_last
  480. operator/(const weekday_last& wdl, int m) noexcept;
  481. constexpr year_month_day
  482. operator/(const year_month& ym, const day& d) noexcept;
  483. constexpr year_month_day
  484. operator/(const year_month& ym, int d) noexcept;
  485. constexpr year_month_day
  486. operator/(const year& y, const month_day& md) noexcept;
  487. constexpr year_month_day
  488. operator/(int y, const month_day& md) noexcept;
  489. constexpr year_month_day
  490. operator/(const month_day& md, const year& y) noexcept;
  491. constexpr year_month_day
  492. operator/(const month_day& md, int y) noexcept;
  493. constexpr year_month_day_last
  494. operator/(const year_month& ym, last_spec) noexcept;
  495. constexpr year_month_day_last
  496. operator/(const year& y, const month_day_last& mdl) noexcept;
  497. constexpr year_month_day_last
  498. operator/(int y, const month_day_last& mdl) noexcept;
  499. constexpr year_month_day_last
  500. operator/(const month_day_last& mdl, const year& y) noexcept;
  501. constexpr year_month_day_last
  502. operator/(const month_day_last& mdl, int y) noexcept;
  503. constexpr year_month_weekday
  504. operator/(const year_month& ym, const weekday_indexed& wdi) noexcept;
  505. constexpr year_month_weekday
  506. operator/(const year& y, const month_weekday& mwd) noexcept;
  507. constexpr year_month_weekday
  508. operator/(int y, const month_weekday& mwd) noexcept;
  509. constexpr year_month_weekday
  510. operator/(const month_weekday& mwd, const year& y) noexcept;
  511. constexpr year_month_weekday
  512. operator/(const month_weekday& mwd, int y) noexcept;
  513. constexpr year_month_weekday_last
  514. operator/(const year_month& ym, const weekday_last& wdl) noexcept;
  515. constexpr year_month_weekday_last
  516. operator/(const year& y, const month_weekday_last& mwdl) noexcept;
  517. constexpr year_month_weekday_last
  518. operator/(int y, const month_weekday_last& mwdl) noexcept;
  519. constexpr year_month_weekday_last
  520. operator/(const month_weekday_last& mwdl, const year& y) noexcept;
  521. constexpr year_month_weekday_last
  522. operator/(const month_weekday_last& mwdl, int y) noexcept;
  523. // 26.9, class template hh_mm_ss
  524. template <class Duration>
  525. class hh_mm_ss
  526. {
  527. bool is_neg; // exposition only
  528. chrono::hours h; // exposition only
  529. chrono::minutes m; // exposition only
  530. chrono::seconds s; // exposition only
  531. precision ss; // exposition only
  532. public:
  533. static unsigned constexpr fractional_width = see below;
  534. using precision = see below;
  535. constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {}
  536. constexpr explicit hh_mm_ss(Duration d) noexcept;
  537. constexpr bool is_negative() const noexcept;
  538. constexpr chrono::hours hours() const noexcept;
  539. constexpr chrono::minutes minutes() const noexcept;
  540. constexpr chrono::seconds seconds() const noexcept;
  541. constexpr precision subseconds() const noexcept;
  542. constexpr explicit operator precision() const noexcept;
  543. constexpr precision to_duration() const noexcept;
  544. };
  545. // 26.10, 12/24 hour functions
  546. constexpr bool is_am(hours const& h) noexcept;
  547. constexpr bool is_pm(hours const& h) noexcept;
  548. constexpr hours make12(const hours& h) noexcept;
  549. constexpr hours make24(const hours& h, bool is_pm) noexcept;
  550. // 25.10.5, class time_zone // C++20
  551. enum class choose {earliest, latest};
  552. class time_zone;
  553. bool operator==(const time_zone& x, const time_zone& y) noexcept;
  554. bool operator!=(const time_zone& x, const time_zone& y) noexcept;
  555. bool operator<(const time_zone& x, const time_zone& y) noexcept;
  556. bool operator>(const time_zone& x, const time_zone& y) noexcept;
  557. bool operator<=(const time_zone& x, const time_zone& y) noexcept;
  558. bool operator>=(const time_zone& x, const time_zone& y) noexcept;
  559. } // chrono
  560. namespace std {
  561. template<class Rep, class Period, class charT>
  562. struct formatter<chrono::duration<Rep, Period>, charT>; // C++20
  563. template<class charT> struct formatter<chrono::day, charT>; // C++20
  564. template<class charT> struct formatter<chrono::month, charT>; // C++20
  565. template<class charT> struct formatter<chrono::year, charT>; // C++20
  566. template<class charT> struct formatter<chrono::weekday, charT>; // C++20
  567. template<class charT> struct formatter<chrono::weekday_indexed, charT>; // C++20
  568. template<class charT> struct formatter<chrono::weekday_last, charT>; // C++20
  569. template<class charT> struct formatter<chrono::month_day, charT>; // C++20
  570. template<class charT> struct formatter<chrono::month_day_last, charT>; // C++20
  571. template<class charT> struct formatter<chrono::month_weekday, charT>; // C++20
  572. template<class charT> struct formatter<chrono::month_weekday_last, charT>; // C++20
  573. template<class charT> struct formatter<chrono::year_month, charT>; // C++20
  574. template<class charT> struct formatter<chrono::year_month_day, charT>; // C++20
  575. template<class charT> struct formatter<chrono::year_month_day_last, charT>; // C++20
  576. template<class charT> struct formatter<chrono::year_month_weekday, charT>; // C++20
  577. template<class charT> struct formatter<chrono::year_month_weekday_last, charT>; // C++20
  578. } // namespace std
  579. namespace chrono {
  580. // calendrical constants
  581. inline constexpr last_spec last{}; // C++20
  582. inline constexpr chrono::weekday Sunday{0}; // C++20
  583. inline constexpr chrono::weekday Monday{1}; // C++20
  584. inline constexpr chrono::weekday Tuesday{2}; // C++20
  585. inline constexpr chrono::weekday Wednesday{3}; // C++20
  586. inline constexpr chrono::weekday Thursday{4}; // C++20
  587. inline constexpr chrono::weekday Friday{5}; // C++20
  588. inline constexpr chrono::weekday Saturday{6}; // C++20
  589. inline constexpr chrono::month January{1}; // C++20
  590. inline constexpr chrono::month February{2}; // C++20
  591. inline constexpr chrono::month March{3}; // C++20
  592. inline constexpr chrono::month April{4}; // C++20
  593. inline constexpr chrono::month May{5}; // C++20
  594. inline constexpr chrono::month June{6}; // C++20
  595. inline constexpr chrono::month July{7}; // C++20
  596. inline constexpr chrono::month August{8}; // C++20
  597. inline constexpr chrono::month September{9}; // C++20
  598. inline constexpr chrono::month October{10}; // C++20
  599. inline constexpr chrono::month November{11}; // C++20
  600. inline constexpr chrono::month December{12}; // C++20
  601. } // chrono
  602. inline namespace literals {
  603. inline namespace chrono_literals {
  604. constexpr chrono::hours operator ""h(unsigned long long); // C++14
  605. constexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14
  606. constexpr chrono::minutes operator ""min(unsigned long long); // C++14
  607. constexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14
  608. constexpr chrono::seconds operator ""s(unsigned long long); // C++14
  609. constexpr chrono::duration<unspecified > operator ""s(long double); // C++14
  610. constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14
  611. constexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14
  612. constexpr chrono::microseconds operator ""us(unsigned long long); // C++14
  613. constexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14
  614. constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14
  615. constexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14
  616. constexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20
  617. constexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20
  618. } // chrono_literals
  619. } // literals
  620. } // std
  621. */
  622. #include <__assert> // all public C++ headers provide the assertion handler
  623. #include <__chrono/calendar.h>
  624. #include <__chrono/convert_to_timespec.h>
  625. #include <__chrono/convert_to_tm.h>
  626. #include <__chrono/day.h>
  627. #include <__chrono/duration.h>
  628. #include <__chrono/file_clock.h>
  629. #include <__chrono/hh_mm_ss.h>
  630. #include <__chrono/high_resolution_clock.h>
  631. #include <__chrono/literals.h>
  632. #include <__chrono/month.h>
  633. #include <__chrono/month_weekday.h>
  634. #include <__chrono/monthday.h>
  635. #include <__chrono/steady_clock.h>
  636. #include <__chrono/system_clock.h>
  637. #include <__chrono/time_point.h>
  638. #include <__chrono/weekday.h>
  639. #include <__chrono/year.h>
  640. #include <__chrono/year_month.h>
  641. #include <__chrono/year_month_day.h>
  642. #include <__chrono/year_month_weekday.h>
  643. #include <__config>
  644. #include <version>
  645. // standard-mandated includes
  646. // [time.syn]
  647. #include <compare>
  648. #if 0
  649. # include <__chrono/formatter.h>
  650. # include <__chrono/ostream.h>
  651. # include <__chrono/parser_std_format_spec.h>
  652. # include <__chrono/statically_widen.h>
  653. #endif
  654. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  655. # pragma GCC system_header
  656. #endif
  657. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  658. # include <concepts>
  659. #endif
  660. #endif // _LIBCPP_CHRONO