master
  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
 10#ifndef _LIBCPP___CHRONO_DURATION_H
 11#define _LIBCPP___CHRONO_DURATION_H
 12
 13#include <__compare/ordering.h>
 14#include <__compare/three_way_comparable.h>
 15#include <__config>
 16#include <__type_traits/common_type.h>
 17#include <__type_traits/enable_if.h>
 18#include <__type_traits/is_convertible.h>
 19#include <__type_traits/is_floating_point.h>
 20#include <limits>
 21#include <ratio>
 22
 23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 24#  pragma GCC system_header
 25#endif
 26
 27_LIBCPP_PUSH_MACROS
 28#include <__undef_macros>
 29
 30_LIBCPP_BEGIN_NAMESPACE_STD
 31
 32namespace chrono {
 33
 34template <class _Rep, class _Period = ratio<1> >
 35class duration;
 36
 37template <class _Tp>
 38inline const bool __is_duration_v = false;
 39
 40template <class _Rep, class _Period>
 41inline const bool __is_duration_v<duration<_Rep, _Period> > = true;
 42
 43template <class _Rep, class _Period>
 44inline const bool __is_duration_v<const duration<_Rep, _Period> > = true;
 45
 46template <class _Rep, class _Period>
 47inline const bool __is_duration_v<volatile duration<_Rep, _Period> > = true;
 48
 49template <class _Rep, class _Period>
 50inline const bool __is_duration_v<const volatile duration<_Rep, _Period> > = true;
 51
 52} // namespace chrono
 53
 54template <class _Rep1, class _Period1, class _Rep2, class _Period2>
 55struct common_type<chrono::duration<_Rep1, _Period1>, chrono::duration<_Rep2, _Period2> > {
 56  typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, __ratio_gcd<_Period1, _Period2> > type;
 57};
 58
 59namespace chrono {
 60
 61// duration_cast
 62
 63template <class _FromDuration,
 64          class _ToDuration,
 65          class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
 66          bool          = _Period::num == 1,
 67          bool          = _Period::den == 1>
 68struct __duration_cast;
 69
 70template <class _FromDuration, class _ToDuration, class _Period>
 71struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> {
 72  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const {
 73    return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
 74  }
 75};
 76
 77template <class _FromDuration, class _ToDuration, class _Period>
 78struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> {
 79  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const {
 80    typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
 81    return _ToDuration(
 82        static_cast<typename _ToDuration::rep>(static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
 83  }
 84};
 85
 86template <class _FromDuration, class _ToDuration, class _Period>
 87struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> {
 88  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const {
 89    typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
 90    return _ToDuration(
 91        static_cast<typename _ToDuration::rep>(static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
 92  }
 93};
 94
 95template <class _FromDuration, class _ToDuration, class _Period>
 96struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> {
 97  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const {
 98    typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
 99    return _ToDuration(static_cast<typename _ToDuration::rep>(
100        static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) / static_cast<_Ct>(_Period::den)));
101  }
102};
103
104template <class _ToDuration, class _Rep, class _Period, __enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
105inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration duration_cast(const duration<_Rep, _Period>& __fd) {
106  return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
107}
108
109template <class _Rep>
110struct treat_as_floating_point : is_floating_point<_Rep> {};
111
112#if _LIBCPP_STD_VER >= 17
113template <class _Rep>
114inline constexpr bool treat_as_floating_point_v = treat_as_floating_point<_Rep>::value;
115#endif
116
117template <class _Rep>
118struct duration_values {
119public:
120  _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT { return _Rep(0); }
121  _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT { return numeric_limits<_Rep>::max(); }
122  _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT { return numeric_limits<_Rep>::lowest(); }
123};
124
125#if _LIBCPP_STD_VER >= 17
126template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
127inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration floor(const duration<_Rep, _Period>& __d) {
128  _ToDuration __t = chrono::duration_cast<_ToDuration>(__d);
129  if (__t > __d)
130    __t = __t - _ToDuration{1};
131  return __t;
132}
133
134template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
135inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration ceil(const duration<_Rep, _Period>& __d) {
136  _ToDuration __t = chrono::duration_cast<_ToDuration>(__d);
137  if (__t < __d)
138    __t = __t + _ToDuration{1};
139  return __t;
140}
141
142template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
143inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration round(const duration<_Rep, _Period>& __d) {
144  _ToDuration __lower = chrono::floor<_ToDuration>(__d);
145  _ToDuration __upper = __lower + _ToDuration{1};
146  auto __lower_diff   = __d - __lower;
147  auto __upper_diff   = __upper - __d;
148  if (__lower_diff < __upper_diff)
149    return __lower;
150  if (__lower_diff > __upper_diff)
151    return __upper;
152  return __lower.count() & 1 ? __upper : __lower;
153}
154#endif
155
156// duration
157
158template <class _Rep, class _Period>
159class duration {
160  static_assert(!__is_duration_v<_Rep>, "A duration representation can not be a duration");
161  static_assert(__is_ratio_v<_Period>, "Second template parameter of duration must be a std::ratio");
162  static_assert(_Period::num > 0, "duration period must be positive");
163
164  template <class _R1, class _R2>
165  struct __no_overflow {
166  private:
167    static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>;
168    static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>;
169    static const intmax_t __n1        = _R1::num / __gcd_n1_n2;
170    static const intmax_t __d1        = _R1::den / __gcd_d1_d2;
171    static const intmax_t __n2        = _R2::num / __gcd_n1_n2;
172    static const intmax_t __d2        = _R2::den / __gcd_d1_d2;
173    static const intmax_t max         = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
174
175    template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
176    struct __mul // __overflow == false
177    {
178      static const intmax_t value = _Xp * _Yp;
179    };
180
181    template <intmax_t _Xp, intmax_t _Yp>
182    struct __mul<_Xp, _Yp, true> {
183      static const intmax_t value = 1;
184    };
185
186  public:
187    static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
188    typedef ratio<__mul<__n1, __d2, !value>::value, __mul<__n2, __d1, !value>::value> type;
189  };
190
191public:
192  typedef _Rep rep;
193  typedef typename _Period::type period;
194
195private:
196  rep __rep_;
197
198public:
199#ifndef _LIBCPP_CXX03_LANG
200  constexpr duration() = default;
201#else
202  _LIBCPP_HIDE_FROM_ABI duration() {}
203#endif
204
205  template <class _Rep2,
206            __enable_if_t<is_convertible<const _Rep2&, rep>::value &&
207                              (treat_as_floating_point<rep>::value || !treat_as_floating_point<_Rep2>::value),
208                          int> = 0>
209  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit duration(const _Rep2& __r) : __rep_(__r) {}
210
211  // conversions
212  template <class _Rep2,
213            class _Period2,
214            __enable_if_t<__no_overflow<_Period2, period>::value && (treat_as_floating_point<rep>::value ||
215                                                                     (__no_overflow<_Period2, period>::type::den == 1 &&
216                                                                      !treat_as_floating_point<_Rep2>::value)),
217                          int> = 0>
218  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration(const duration<_Rep2, _Period2>& __d)
219      : __rep_(chrono::duration_cast<duration>(__d).count()) {}
220
221  // observer
222
223  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR rep count() const { return __rep_; }
224
225  // arithmetic
226
227  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {
228    return typename common_type<duration>::type(*this);
229  }
230  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {
231    return typename common_type<duration>::type(-__rep_);
232  }
233  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator++() {
234    ++__rep_;
235    return *this;
236  }
237  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration operator++(int) { return duration(__rep_++); }
238  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator--() {
239    --__rep_;
240    return *this;
241  }
242  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration operator--(int) { return duration(__rep_--); }
243
244  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator+=(const duration& __d) {
245    __rep_ += __d.count();
246    return *this;
247  }
248  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator-=(const duration& __d) {
249    __rep_ -= __d.count();
250    return *this;
251  }
252
253  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator*=(const rep& __rhs) {
254    __rep_ *= __rhs;
255    return *this;
256  }
257  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator/=(const rep& __rhs) {
258    __rep_ /= __rhs;
259    return *this;
260  }
261  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator%=(const rep& __rhs) {
262    __rep_ %= __rhs;
263    return *this;
264  }
265  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator%=(const duration& __rhs) {
266    __rep_ %= __rhs.count();
267    return *this;
268  }
269
270  // special values
271
272  _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {
273    return duration(duration_values<rep>::zero());
274  }
275  _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT {
276    return duration(duration_values<rep>::min());
277  }
278  _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT {
279    return duration(duration_values<rep>::max());
280  }
281};
282
283typedef duration<long long, nano> nanoseconds;
284typedef duration<long long, micro> microseconds;
285typedef duration<long long, milli> milliseconds;
286typedef duration<long long > seconds;
287typedef duration< long, ratio< 60> > minutes;
288typedef duration< long, ratio<3600> > hours;
289#if _LIBCPP_STD_VER >= 20
290typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
291typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks;
292typedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years;
293typedef duration< int, ratio_divide<years::period, ratio<12>>> months;
294#endif
295// Duration ==
296
297template <class _LhsDuration, class _RhsDuration>
298struct __duration_eq {
299  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const {
300    typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
301    return _Ct(__lhs).count() == _Ct(__rhs).count();
302  }
303};
304
305template <class _LhsDuration>
306struct __duration_eq<_LhsDuration, _LhsDuration> {
307  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const {
308    return __lhs.count() == __rhs.count();
309  }
310};
311
312template <class _Rep1, class _Period1, class _Rep2, class _Period2>
313inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
314operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
315  return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
316}
317
318#if _LIBCPP_STD_VER <= 17
319
320// Duration !=
321
322template <class _Rep1, class _Period1, class _Rep2, class _Period2>
323inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
324operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
325  return !(__lhs == __rhs);
326}
327
328#endif // _LIBCPP_STD_VER <= 17
329
330// Duration <
331
332template <class _LhsDuration, class _RhsDuration>
333struct __duration_lt {
334  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const {
335    typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
336    return _Ct(__lhs).count() < _Ct(__rhs).count();
337  }
338};
339
340template <class _LhsDuration>
341struct __duration_lt<_LhsDuration, _LhsDuration> {
342  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const {
343    return __lhs.count() < __rhs.count();
344  }
345};
346
347template <class _Rep1, class _Period1, class _Rep2, class _Period2>
348inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
349operator<(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
350  return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
351}
352
353// Duration >
354
355template <class _Rep1, class _Period1, class _Rep2, class _Period2>
356inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
357operator>(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
358  return __rhs < __lhs;
359}
360
361// Duration <=
362
363template <class _Rep1, class _Period1, class _Rep2, class _Period2>
364inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
365operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
366  return !(__rhs < __lhs);
367}
368
369// Duration >=
370
371template <class _Rep1, class _Period1, class _Rep2, class _Period2>
372inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
373operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
374  return !(__lhs < __rhs);
375}
376
377#if _LIBCPP_STD_VER >= 20
378
379template <class _Rep1, class _Period1, class _Rep2, class _Period2>
380  requires three_way_comparable<common_type_t<_Rep1, _Rep2>>
381_LIBCPP_HIDE_FROM_ABI constexpr auto
382operator<=>(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
383  using _Ct = common_type_t<duration<_Rep1, _Period1>, duration<_Rep2, _Period2>>;
384  return _Ct(__lhs).count() <=> _Ct(__rhs).count();
385}
386
387#endif // _LIBCPP_STD_VER >= 20
388
389// Duration +
390
391template <class _Rep1, class _Period1, class _Rep2, class _Period2>
392inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
393typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
394operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
395  typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
396  return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
397}
398
399// Duration -
400
401template <class _Rep1, class _Period1, class _Rep2, class _Period2>
402inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
403typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
404operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
405  typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
406  return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
407}
408
409// Duration *
410
411template <class _Rep1,
412          class _Period,
413          class _Rep2,
414          __enable_if_t<is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value, int> = 0>
415inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
416operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) {
417  typedef typename common_type<_Rep1, _Rep2>::type _Cr;
418  typedef duration<_Cr, _Period> _Cd;
419  return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
420}
421
422template <class _Rep1,
423          class _Period,
424          class _Rep2,
425          __enable_if_t<is_convertible<const _Rep1&, typename common_type<_Rep1, _Rep2>::type>::value, int> = 0>
426inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
427operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) {
428  return __d * __s;
429}
430
431// Duration /
432
433template <class _Rep1,
434          class _Period,
435          class _Rep2,
436          __enable_if_t<!__is_duration_v<_Rep2> &&
437                            is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value,
438                        int> = 0>
439inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
440operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) {
441  typedef typename common_type<_Rep1, _Rep2>::type _Cr;
442  typedef duration<_Cr, _Period> _Cd;
443  return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
444}
445
446template <class _Rep1, class _Period1, class _Rep2, class _Period2>
447inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename common_type<_Rep1, _Rep2>::type
448operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
449  typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
450  return _Ct(__lhs).count() / _Ct(__rhs).count();
451}
452
453// Duration %
454
455template <class _Rep1,
456          class _Period,
457          class _Rep2,
458          __enable_if_t<!__is_duration_v<_Rep2> &&
459                            is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value,
460                        int> = 0>
461inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
462operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) {
463  typedef typename common_type<_Rep1, _Rep2>::type _Cr;
464  typedef duration<_Cr, _Period> _Cd;
465  return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
466}
467
468template <class _Rep1, class _Period1, class _Rep2, class _Period2>
469inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
470typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
471operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
472  typedef typename common_type<_Rep1, _Rep2>::type _Cr;
473  typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
474  return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
475}
476
477} // namespace chrono
478
479#if _LIBCPP_STD_VER >= 14
480// Suffixes for duration literals [time.duration.literals]
481inline namespace literals {
482inline namespace chrono_literals {
483
484_LIBCPP_HIDE_FROM_ABI constexpr chrono::hours operator""h(unsigned long long __h) {
485  return chrono::hours(static_cast<chrono::hours::rep>(__h));
486}
487
488_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, ratio<3600, 1>> operator""h(long double __h) {
489  return chrono::duration<long double, ratio<3600, 1>>(__h);
490}
491
492_LIBCPP_HIDE_FROM_ABI constexpr chrono::minutes operator""min(unsigned long long __m) {
493  return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
494}
495
496_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, ratio<60, 1>> operator""min(long double __m) {
497  return chrono::duration<long double, ratio<60, 1>>(__m);
498}
499
500_LIBCPP_HIDE_FROM_ABI constexpr chrono::seconds operator""s(unsigned long long __s) {
501  return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
502}
503
504_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double> operator""s(long double __s) {
505  return chrono::duration<long double>(__s);
506}
507
508_LIBCPP_HIDE_FROM_ABI constexpr chrono::milliseconds operator""ms(unsigned long long __ms) {
509  return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
510}
511
512_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, milli> operator""ms(long double __ms) {
513  return chrono::duration<long double, milli>(__ms);
514}
515
516_LIBCPP_HIDE_FROM_ABI constexpr chrono::microseconds operator""us(unsigned long long __us) {
517  return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
518}
519
520_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, micro> operator""us(long double __us) {
521  return chrono::duration<long double, micro>(__us);
522}
523
524_LIBCPP_HIDE_FROM_ABI constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) {
525  return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
526}
527
528_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, nano> operator""ns(long double __ns) {
529  return chrono::duration<long double, nano>(__ns);
530}
531
532} // namespace chrono_literals
533} // namespace literals
534
535namespace chrono { // hoist the literals into namespace std::chrono
536using namespace literals::chrono_literals;
537} // namespace chrono
538
539#endif // _LIBCPP_STD_VER >= 14
540
541_LIBCPP_END_NAMESPACE_STD
542
543_LIBCPP_POP_MACROS
544
545#endif // _LIBCPP___CHRONO_DURATION_H