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