blob: 9229234ce55a84bb63fa6877506aeecaf79040f4 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- chrono ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_CHRONO
12#define _LIBCPP_CHRONO
13
14/*
15 chrono synopsis
16
17namespace std
18{
19namespace chrono
20{
21
22template <class ToDuration, class Rep, class Period>
Howard Hinnant473f8382012-07-13 19:17:27 +000023constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000024ToDuration
25duration_cast(const duration<Rep, Period>& fd);
26
27template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
28
29template <class Rep>
30struct duration_values
31{
32public:
Howard Hinnant473f8382012-07-13 19:17:27 +000033 static constexpr Rep zero();
34 static constexpr Rep max();
35 static constexpr Rep min();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036};
37
38// duration
39
40template <class Rep, class Period = ratio<1>>
41class duration
42{
43 static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
44 static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
45 static_assert(Period::num > 0, "duration period must be positive");
46public:
47 typedef Rep rep;
48 typedef Period period;
49
Howard Hinnant473f8382012-07-13 19:17:27 +000050 constexpr duration() = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000051 template <class Rep2>
Howard Hinnant473f8382012-07-13 19:17:27 +000052 constexpr explicit duration(const Rep2& r,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000053 typename enable_if
54 <
55 is_convertible<Rep2, rep>::value &&
56 (treat_as_floating_point<rep>::value ||
57 !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
58 >::type* = 0);
59
60 // conversions
61 template <class Rep2, class Period2>
Howard Hinnant473f8382012-07-13 19:17:27 +000062 constexpr duration(const duration<Rep2, Period2>& d,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000063 typename enable_if
64 <
65 treat_as_floating_point<rep>::value ||
66 ratio_divide<Period2, period>::type::den == 1
67 >::type* = 0);
68
69 // observer
70
Howard Hinnant473f8382012-07-13 19:17:27 +000071 constexpr rep count() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072
73 // arithmetic
74
Howard Hinnant473f8382012-07-13 19:17:27 +000075 constexpr duration operator+() const;
76 constexpr duration operator-() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000077 duration& operator++();
78 duration operator++(int);
79 duration& operator--();
80 duration operator--(int);
81
82 duration& operator+=(const duration& d);
83 duration& operator-=(const duration& d);
84
85 duration& operator*=(const rep& rhs);
86 duration& operator/=(const rep& rhs);
87
88 // special values
89
Howard Hinnant473f8382012-07-13 19:17:27 +000090 static constexpr duration zero();
91 static constexpr duration min();
92 static constexpr duration max();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000093};
94
95typedef duration<long long, nano> nanoseconds;
96typedef duration<long long, micro> microseconds;
97typedef duration<long long, milli> milliseconds;
98typedef duration<long long > seconds;
99typedef duration< long, ratio< 60> > minutes;
100typedef duration< long, ratio<3600> > hours;
101
102template <class Clock, class Duration = typename Clock::duration>
103class time_point
104{
105public:
106 typedef Clock clock;
107 typedef Duration duration;
108 typedef typename duration::rep rep;
109 typedef typename duration::period period;
110private:
111 duration d_; // exposition only
112
113public:
Marshall Clow832b3042013-07-31 19:32:19 +0000114 time_point(); // has value "epoch" // constexpr in C++14
115 explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000116
117 // conversions
118 template <class Duration2>
Marshall Clow832b3042013-07-31 19:32:19 +0000119 time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120
121 // observer
122
Marshall Clow832b3042013-07-31 19:32:19 +0000123 duration time_since_epoch() const; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000124
125 // arithmetic
126
127 time_point& operator+=(const duration& d);
128 time_point& operator-=(const duration& d);
129
130 // special values
131
132 static constexpr time_point min();
133 static constexpr time_point max();
134};
135
136} // chrono
137
138// common_type traits
139template <class Rep1, class Period1, class Rep2, class Period2>
140 struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
141
142template <class Clock, class Duration1, class Duration2>
143 struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
144
145namespace chrono {
146
147// duration arithmetic
148template <class Rep1, class Period1, class Rep2, class Period2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000149 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000150 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
151 operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
152template <class Rep1, class Period1, class Rep2, class Period2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000153 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000154 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
155 operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
156template <class Rep1, class Period, class Rep2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000157 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000158 duration<typename common_type<Rep1, Rep2>::type, Period>
159 operator*(const duration<Rep1, Period>& d, const Rep2& s);
160template <class Rep1, class Period, class Rep2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000161 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000162 duration<typename common_type<Rep1, Rep2>::type, Period>
163 operator*(const Rep1& s, const duration<Rep2, Period>& d);
164template <class Rep1, class Period, class Rep2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000165 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000166 duration<typename common_type<Rep1, Rep2>::type, Period>
167 operator/(const duration<Rep1, Period>& d, const Rep2& s);
168template <class Rep1, class Period1, class Rep2, class Period2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000169 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000170 typename common_type<Rep1, Rep2>::type
171 operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
172
173// duration comparisons
174template <class Rep1, class Period1, class Rep2, class Period2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000175 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176 bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
177template <class Rep1, class Period1, class Rep2, class Period2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000178 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000179 bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
180template <class Rep1, class Period1, class Rep2, class Period2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000181 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000182 bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
183template <class Rep1, class Period1, class Rep2, class Period2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000184 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000185 bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
186template <class Rep1, class Period1, class Rep2, class Period2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000187 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000188 bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
189template <class Rep1, class Period1, class Rep2, class Period2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000190 constexpr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000191 bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
192
193// duration_cast
194template <class ToDuration, class Rep, class Period>
195 ToDuration duration_cast(const duration<Rep, Period>& d);
196
Marshall Clow832b3042013-07-31 19:32:19 +0000197// time_point arithmetic (all constexpr in C++14)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000198template <class Clock, class Duration1, class Rep2, class Period2>
199 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
200 operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
201template <class Rep1, class Period1, class Clock, class Duration2>
202 time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
203 operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
204template <class Clock, class Duration1, class Rep2, class Period2>
205 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
206 operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
207template <class Clock, class Duration1, class Duration2>
208 typename common_type<Duration1, Duration2>::type
209 operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
210
Marshall Clow832b3042013-07-31 19:32:19 +0000211// time_point comparisons (all constexpr in C++14)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000212template <class Clock, class Duration1, class Duration2>
213 bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
214template <class Clock, class Duration1, class Duration2>
215 bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
216template <class Clock, class Duration1, class Duration2>
217 bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
218template <class Clock, class Duration1, class Duration2>
219 bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
220template <class Clock, class Duration1, class Duration2>
221 bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
222template <class Clock, class Duration1, class Duration2>
223 bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
224
Marshall Clow832b3042013-07-31 19:32:19 +0000225// time_point_cast (constexpr in C++14)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000226
227template <class ToDuration, class Clock, class Duration>
228 time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
229
230// Clocks
231
232class system_clock
233{
234public:
235 typedef microseconds duration;
236 typedef duration::rep rep;
237 typedef duration::period period;
238 typedef chrono::time_point<system_clock> time_point;
Marshall Clow832b3042013-07-31 19:32:19 +0000239 static const bool is_steady = false; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000240
Howard Hinnant756a1762011-05-28 18:34:36 +0000241 static time_point now() noexcept;
242 static time_t to_time_t (const time_point& __t) noexcept;
243 static time_point from_time_t(time_t __t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000244};
245
Howard Hinnantf8f85212010-11-20 19:16:30 +0000246class steady_clock
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000247{
248public:
249 typedef nanoseconds duration;
250 typedef duration::rep rep;
251 typedef duration::period period;
Howard Hinnantf8f85212010-11-20 19:16:30 +0000252 typedef chrono::time_point<steady_clock, duration> time_point;
Marshall Clow832b3042013-07-31 19:32:19 +0000253 static const bool is_steady = true; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000254
Howard Hinnant756a1762011-05-28 18:34:36 +0000255 static time_point now() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256};
257
Howard Hinnantf8f85212010-11-20 19:16:30 +0000258typedef steady_clock high_resolution_clock;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000259
260} // chrono
261
Marshall Clowf1820382013-07-24 21:18:14 +0000262constexpr chrono::hours operator "" h(unsigned long long); // C++14
263constexpr chrono::duration<unspecified , ratio<3600,1>> operator "" h(long double); // C++14
264constexpr chrono::minutes operator "" min(unsigned long long); // C++14
265constexpr chrono::duration<unspecified , ratio<60,1>> operator "" min(long double); // C++14
266constexpr chrono::seconds operator "" s(unsigned long long); // C++14
267constexpr chrono::duration<unspecified > operator "" s(long double); // C++14
268constexpr chrono::milliseconds operator "" ms(unsigned long long); // C++14
269constexpr chrono::duration<unspecified , milli> operator "" ms(long double); // C++14
270constexpr chrono::microseconds operator "" us(unsigned long long); // C++14
271constexpr chrono::duration<unspecified , micro> operator "" us(long double); // C++14
272constexpr chrono::nanoseconds operator "" ns(unsigned long long); // C++14
273constexpr chrono::duration<unspecified , nano> operator "" ns(long double); // C++14
274
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000275} // std
276*/
277
278#include <__config>
279#include <ctime>
280#include <type_traits>
281#include <ratio>
282#include <limits>
283
Howard Hinnant66c6f972011-11-29 16:45:27 +0000284#include <__undef_min_max>
285
Howard Hinnant08e17472011-10-17 20:05:10 +0000286#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000287#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000288#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000289
290_LIBCPP_BEGIN_NAMESPACE_STD
291
292namespace chrono
293{
294
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000295template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS_ONLY duration;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296
Howard Hinnantd8bc09b2010-05-18 17:32:30 +0000297template <class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000298struct __is_duration : false_type {};
299
300template <class _Rep, class _Period>
301struct __is_duration<duration<_Rep, _Period> > : true_type {};
302
303template <class _Rep, class _Period>
304struct __is_duration<const duration<_Rep, _Period> > : true_type {};
305
306template <class _Rep, class _Period>
307struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
308
309template <class _Rep, class _Period>
310struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
311
312} // chrono
313
314template <class _Rep1, class _Period1, class _Rep2, class _Period2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000315struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::duration<_Rep1, _Period1>,
316 chrono::duration<_Rep2, _Period2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317{
318 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
319 typename __ratio_gcd<_Period1, _Period2>::type> type;
320};
321
322namespace chrono {
323
324// duration_cast
325
326template <class _FromDuration, class _ToDuration,
327 class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
328 bool = _Period::num == 1,
329 bool = _Period::den == 1>
330struct __duration_cast;
331
332template <class _FromDuration, class _ToDuration, class _Period>
333struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
334{
Howard Hinnant473f8382012-07-13 19:17:27 +0000335 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336 _ToDuration operator()(const _FromDuration& __fd) const
337 {
338 return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
339 }
340};
341
342template <class _FromDuration, class _ToDuration, class _Period>
343struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
344{
Howard Hinnant473f8382012-07-13 19:17:27 +0000345 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346 _ToDuration operator()(const _FromDuration& __fd) const
347 {
348 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
349 return _ToDuration(static_cast<typename _ToDuration::rep>(
350 static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
351 }
352};
353
354template <class _FromDuration, class _ToDuration, class _Period>
355struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
356{
Howard Hinnant473f8382012-07-13 19:17:27 +0000357 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358 _ToDuration operator()(const _FromDuration& __fd) const
359 {
360 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
361 return _ToDuration(static_cast<typename _ToDuration::rep>(
362 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
363 }
364};
365
366template <class _FromDuration, class _ToDuration, class _Period>
367struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
368{
Howard Hinnant473f8382012-07-13 19:17:27 +0000369 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370 _ToDuration operator()(const _FromDuration& __fd) const
371 {
372 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
373 return _ToDuration(static_cast<typename _ToDuration::rep>(
374 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
375 / static_cast<_Ct>(_Period::den)));
376 }
377};
378
379template <class _ToDuration, class _Rep, class _Period>
380inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000381_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382typename enable_if
383<
384 __is_duration<_ToDuration>::value,
385 _ToDuration
386>::type
387duration_cast(const duration<_Rep, _Period>& __fd)
388{
389 return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
390}
391
Howard Hinnant422a53f2010-09-21 21:28:23 +0000392template <class _Rep>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000393struct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394
395template <class _Rep>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000396struct _LIBCPP_TYPE_VIS_ONLY duration_values
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397{
398public:
Howard Hinnant473f8382012-07-13 19:17:27 +0000399 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);}
400 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() {return numeric_limits<_Rep>::max();}
401 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402};
403
404// duration
405
406template <class _Rep, class _Period>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000407class _LIBCPP_TYPE_VIS_ONLY duration
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408{
409 static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
410 static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
411 static_assert(_Period::num > 0, "duration period must be positive");
Howard Hinnant713f4db2013-08-31 16:51:56 +0000412
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
425 template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
426 struct __mul // __overflow == false
427 {
428 static const intmax_t value = _Xp * _Yp;
429 };
430
431 template <intmax_t _Xp, intmax_t _Yp>
432 struct __mul<_Xp, _Yp, true>
433 {
434 static const intmax_t value = 1;
435 };
436
437 public:
438 static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
439 typedef ratio<__mul<__n1, __d2, !value>::value,
440 __mul<__n2, __d1, !value>::value> type;
441 };
442
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443public:
444 typedef _Rep rep;
445 typedef _Period period;
446private:
447 rep __rep_;
448public:
449
Marshall Clow832b3042013-07-31 19:32:19 +0000450 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
451#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
Marshall Clow832b3042013-07-31 19:32:19 +0000452 duration() = default;
Marshall Clow07774732013-07-31 19:39:37 +0000453#else
454 duration() {}
Marshall Clow832b3042013-07-31 19:32:19 +0000455#endif
456
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457 template <class _Rep2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000458 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459 explicit duration(const _Rep2& __r,
460 typename enable_if
461 <
462 is_convertible<_Rep2, rep>::value &&
463 (treat_as_floating_point<rep>::value ||
464 !treat_as_floating_point<_Rep2>::value)
465 >::type* = 0)
466 : __rep_(__r) {}
467
468 // conversions
469 template <class _Rep2, class _Period2>
Howard Hinnant473f8382012-07-13 19:17:27 +0000470 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471 duration(const duration<_Rep2, _Period2>& __d,
472 typename enable_if
473 <
Howard Hinnant713f4db2013-08-31 16:51:56 +0000474 __no_overflow<_Period2, period>::value && (
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475 treat_as_floating_point<rep>::value ||
Howard Hinnant713f4db2013-08-31 16:51:56 +0000476 (__no_overflow<_Period2, period>::type::den == 1 &&
477 !treat_as_floating_point<_Rep2>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478 >::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000479 : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000480
481 // observer
482
Howard Hinnant473f8382012-07-13 19:17:27 +0000483 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484
485 // arithmetic
486
Howard Hinnant473f8382012-07-13 19:17:27 +0000487 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;}
488 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489 _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;}
490 _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);}
491 _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;}
492 _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);}
493
494 _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
495 _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
496
497 _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
498 _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
499 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
500 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
501
502 // special values
503
Howard Hinnant473f8382012-07-13 19:17:27 +0000504 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
505 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values<rep>::min());}
506 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values<rep>::max());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000507};
508
509typedef duration<long long, nano> nanoseconds;
510typedef duration<long long, micro> microseconds;
511typedef duration<long long, milli> milliseconds;
512typedef duration<long long > seconds;
513typedef duration< long, ratio< 60> > minutes;
514typedef duration< long, ratio<3600> > hours;
515
516// Duration ==
517
518template <class _LhsDuration, class _RhsDuration>
519struct __duration_eq
520{
Howard Hinnant473f8382012-07-13 19:17:27 +0000521 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantb9d9fb42013-06-28 18:09:35 +0000522 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523 {
524 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
525 return _Ct(__lhs).count() == _Ct(__rhs).count();
526 }
527};
528
529template <class _LhsDuration>
530struct __duration_eq<_LhsDuration, _LhsDuration>
531{
Howard Hinnant473f8382012-07-13 19:17:27 +0000532 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantb9d9fb42013-06-28 18:09:35 +0000533 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534 {return __lhs.count() == __rhs.count();}
535};
536
537template <class _Rep1, class _Period1, class _Rep2, class _Period2>
538inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000539_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540bool
541operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
542{
543 return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
544}
545
546// Duration !=
547
548template <class _Rep1, class _Period1, class _Rep2, class _Period2>
549inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000550_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551bool
552operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
553{
554 return !(__lhs == __rhs);
555}
556
557// Duration <
558
559template <class _LhsDuration, class _RhsDuration>
560struct __duration_lt
561{
Howard Hinnant473f8382012-07-13 19:17:27 +0000562 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantb9d9fb42013-06-28 18:09:35 +0000563 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564 {
565 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
566 return _Ct(__lhs).count() < _Ct(__rhs).count();
567 }
568};
569
570template <class _LhsDuration>
571struct __duration_lt<_LhsDuration, _LhsDuration>
572{
Howard Hinnant473f8382012-07-13 19:17:27 +0000573 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantb9d9fb42013-06-28 18:09:35 +0000574 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000575 {return __lhs.count() < __rhs.count();}
576};
577
578template <class _Rep1, class _Period1, class _Rep2, class _Period2>
579inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000580_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581bool
582operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
583{
584 return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
585}
586
587// Duration >
588
589template <class _Rep1, class _Period1, class _Rep2, class _Period2>
590inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000591_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000592bool
593operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
594{
595 return __rhs < __lhs;
596}
597
598// Duration <=
599
600template <class _Rep1, class _Period1, class _Rep2, class _Period2>
601inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000602_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000603bool
604operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
605{
606 return !(__rhs < __lhs);
607}
608
609// Duration >=
610
611template <class _Rep1, class _Period1, class _Rep2, class _Period2>
612inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000613_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000614bool
615operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
616{
617 return !(__lhs < __rhs);
618}
619
620// Duration +
621
622template <class _Rep1, class _Period1, class _Rep2, class _Period2>
623inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000624_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000625typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
626operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
627{
Howard Hinnant473f8382012-07-13 19:17:27 +0000628 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
629 return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630}
631
632// Duration -
633
634template <class _Rep1, class _Period1, class _Rep2, class _Period2>
635inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000636_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
638operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
639{
Howard Hinnant473f8382012-07-13 19:17:27 +0000640 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
641 return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000642}
643
644// Duration *
645
646template <class _Rep1, class _Period, class _Rep2>
647inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000648_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649typename enable_if
650<
651 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
652 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
653>::type
654operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
655{
656 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
Howard Hinnant473f8382012-07-13 19:17:27 +0000657 typedef duration<_Cr, _Period> _Cd;
658 return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659}
660
661template <class _Rep1, class _Period, class _Rep2>
662inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000663_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000664typename enable_if
665<
666 is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
667 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
668>::type
669operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
670{
671 return __d * __s;
672}
673
674// Duration /
675
676template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
677struct __duration_divide_result
678{
679};
680
681template <class _Duration, class _Rep2,
682 bool = is_convertible<_Rep2,
683 typename common_type<typename _Duration::rep, _Rep2>::type>::value>
684struct __duration_divide_imp
685{
686};
687
688template <class _Rep1, class _Period, class _Rep2>
689struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
690{
691 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
692};
693
694template <class _Rep1, class _Period, class _Rep2>
695struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
696 : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
697{
698};
699
700template <class _Rep1, class _Period, class _Rep2>
701inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000702_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
704operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
705{
706 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
Howard Hinnant473f8382012-07-13 19:17:27 +0000707 typedef duration<_Cr, _Period> _Cd;
708 return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000709}
710
711template <class _Rep1, class _Period1, class _Rep2, class _Period2>
712inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000713_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714typename common_type<_Rep1, _Rep2>::type
715operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
716{
717 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
718 return _Ct(__lhs).count() / _Ct(__rhs).count();
719}
720
721// Duration %
722
723template <class _Rep1, class _Period, class _Rep2>
724inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000725_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
727operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
728{
729 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
Howard Hinnant473f8382012-07-13 19:17:27 +0000730 typedef duration<_Cr, _Period> _Cd;
731 return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732}
733
734template <class _Rep1, class _Period1, class _Rep2, class _Period2>
735inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant473f8382012-07-13 19:17:27 +0000736_LIBCPP_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
738operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
739{
Howard Hinnant473f8382012-07-13 19:17:27 +0000740 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
741 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
742 return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743}
744
745//////////////////////////////////////////////////////////
746///////////////////// time_point /////////////////////////
747//////////////////////////////////////////////////////////
748
749template <class _Clock, class _Duration = typename _Clock::duration>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000750class _LIBCPP_TYPE_VIS_ONLY time_point
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000751{
752 static_assert(__is_duration<_Duration>::value,
753 "Second template parameter of time_point must be a std::chrono::duration");
754public:
755 typedef _Clock clock;
756 typedef _Duration duration;
757 typedef typename duration::rep rep;
758 typedef typename duration::period period;
759private:
760 duration __d_;
761
762public:
Marshall Clow832b3042013-07-31 19:32:19 +0000763 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
764 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765
766 // conversions
767 template <class _Duration2>
Marshall Clow832b3042013-07-31 19:32:19 +0000768 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000769 time_point(const time_point<clock, _Duration2>& t,
770 typename enable_if
771 <
772 is_convertible<_Duration2, duration>::value
773 >::type* = 0)
774 : __d_(t.time_since_epoch()) {}
775
776 // observer
777
Marshall Clow832b3042013-07-31 19:32:19 +0000778 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779
780 // arithmetic
781
Howard Hinnant171771a2013-07-08 21:06:38 +0000782 _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
783 _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784
785 // special values
786
Howard Hinnant473f8382012-07-13 19:17:27 +0000787 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());}
788 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000789};
790
791} // chrono
792
793template <class _Clock, class _Duration1, class _Duration2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000794struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::time_point<_Clock, _Duration1>,
795 chrono::time_point<_Clock, _Duration2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000796{
797 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
798};
799
800namespace chrono {
801
802template <class _ToDuration, class _Clock, class _Duration>
Marshall Clow832b3042013-07-31 19:32:19 +0000803inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804time_point<_Clock, _ToDuration>
805time_point_cast(const time_point<_Clock, _Duration>& __t)
806{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000807 return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808}
809
810// time_point ==
811
812template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow832b3042013-07-31 19:32:19 +0000813inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000814bool
815operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
816{
817 return __lhs.time_since_epoch() == __rhs.time_since_epoch();
818}
819
820// time_point !=
821
822template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow832b3042013-07-31 19:32:19 +0000823inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000824bool
825operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
826{
827 return !(__lhs == __rhs);
828}
829
830// time_point <
831
832template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow832b3042013-07-31 19:32:19 +0000833inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000834bool
835operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
836{
837 return __lhs.time_since_epoch() < __rhs.time_since_epoch();
838}
839
840// time_point >
841
842template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow832b3042013-07-31 19:32:19 +0000843inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000844bool
845operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
846{
847 return __rhs < __lhs;
848}
849
850// time_point <=
851
852template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow832b3042013-07-31 19:32:19 +0000853inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854bool
855operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
856{
857 return !(__rhs < __lhs);
858}
859
860// time_point >=
861
862template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow832b3042013-07-31 19:32:19 +0000863inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864bool
865operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
866{
867 return !(__lhs < __rhs);
868}
869
870// time_point operator+(time_point x, duration y);
871
872template <class _Clock, class _Duration1, class _Rep2, class _Period2>
Marshall Clow832b3042013-07-31 19:32:19 +0000873inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
875operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
876{
877 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
Marshall Clow832b3042013-07-31 19:32:19 +0000878 return _Tr (__lhs.time_since_epoch() + __rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879}
880
881// time_point operator+(duration x, time_point y);
882
883template <class _Rep1, class _Period1, class _Clock, class _Duration2>
Marshall Clow832b3042013-07-31 19:32:19 +0000884inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000885time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
886operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
887{
888 return __rhs + __lhs;
889}
890
891// time_point operator-(time_point x, duration y);
892
893template <class _Clock, class _Duration1, class _Rep2, class _Period2>
Marshall Clow832b3042013-07-31 19:32:19 +0000894inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
896operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
897{
898 return __lhs + (-__rhs);
899}
900
901// duration operator-(time_point x, time_point y);
902
903template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow832b3042013-07-31 19:32:19 +0000904inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905typename common_type<_Duration1, _Duration2>::type
906operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
907{
908 return __lhs.time_since_epoch() - __rhs.time_since_epoch();
909}
910
911//////////////////////////////////////////////////////////
912/////////////////////// clocks ///////////////////////////
913//////////////////////////////////////////////////////////
914
Howard Hinnant83eade62013-03-06 23:30:19 +0000915class _LIBCPP_TYPE_VIS system_clock
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916{
917public:
918 typedef microseconds duration;
919 typedef duration::rep rep;
920 typedef duration::period period;
921 typedef chrono::time_point<system_clock> time_point;
Marshall Clow832b3042013-07-31 19:32:19 +0000922 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000923
Howard Hinnant756a1762011-05-28 18:34:36 +0000924 static time_point now() _NOEXCEPT;
925 static time_t to_time_t (const time_point& __t) _NOEXCEPT;
926 static time_point from_time_t(time_t __t) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927};
928
Jonathan Roelofsc5780652014-09-02 21:14:38 +0000929#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
Howard Hinnant83eade62013-03-06 23:30:19 +0000930class _LIBCPP_TYPE_VIS steady_clock
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000931{
932public:
933 typedef nanoseconds duration;
934 typedef duration::rep rep;
935 typedef duration::period period;
Howard Hinnantf8f85212010-11-20 19:16:30 +0000936 typedef chrono::time_point<steady_clock, duration> time_point;
Marshall Clow832b3042013-07-31 19:32:19 +0000937 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938
Howard Hinnant756a1762011-05-28 18:34:36 +0000939 static time_point now() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000940};
941
Howard Hinnantf8f85212010-11-20 19:16:30 +0000942typedef steady_clock high_resolution_clock;
Jonathan Roelofsc5780652014-09-02 21:14:38 +0000943#else
944typedef system_clock high_resolution_clock;
945#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946
947} // chrono
948
Marshall Clow8d9dd7a2013-10-05 21:18:32 +0000949#if _LIBCPP_STD_VER > 11
950// Suffixes for duration literals [time.duration.literals]
951inline namespace literals
Marshall Clowf1820382013-07-24 21:18:14 +0000952{
953 inline namespace chrono_literals
954 {
955
Howard Hinnantab61b2c2013-08-07 19:39:48 +0000956 constexpr chrono::hours operator"" h(unsigned long long __h)
957 {
958 return chrono::hours(static_cast<chrono::hours::rep>(__h));
959 }
Marshall Clowf1820382013-07-24 21:18:14 +0000960
Howard Hinnantab61b2c2013-08-07 19:39:48 +0000961 constexpr chrono::duration<long double, ratio<3600,1>> operator"" h(long double __h)
962 {
963 return chrono::duration<long double, ratio<3600,1>>(__h);
964 }
Marshall Clowf1820382013-07-24 21:18:14 +0000965
966
Howard Hinnantab61b2c2013-08-07 19:39:48 +0000967 constexpr chrono::minutes operator"" min(unsigned long long __m)
968 {
969 return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
970 }
Marshall Clowf1820382013-07-24 21:18:14 +0000971
Howard Hinnantab61b2c2013-08-07 19:39:48 +0000972 constexpr chrono::duration<long double, ratio<60,1>> operator"" min(long double __m)
973 {
974 return chrono::duration<long double, ratio<60,1>> (__m);
975 }
Marshall Clowf1820382013-07-24 21:18:14 +0000976
977
Howard Hinnantab61b2c2013-08-07 19:39:48 +0000978 constexpr chrono::seconds operator"" s(unsigned long long __s)
979 {
980 return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
981 }
Marshall Clowf1820382013-07-24 21:18:14 +0000982
Howard Hinnantab61b2c2013-08-07 19:39:48 +0000983 constexpr chrono::duration<long double> operator"" s(long double __s)
984 {
985 return chrono::duration<long double> (__s);
986 }
Marshall Clowf1820382013-07-24 21:18:14 +0000987
988
Howard Hinnantab61b2c2013-08-07 19:39:48 +0000989 constexpr chrono::milliseconds operator"" ms(unsigned long long __ms)
990 {
991 return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
992 }
Marshall Clowf1820382013-07-24 21:18:14 +0000993
Howard Hinnantab61b2c2013-08-07 19:39:48 +0000994 constexpr chrono::duration<long double, milli> operator"" ms(long double __ms)
995 {
996 return chrono::duration<long double, milli>(__ms);
997 }
Marshall Clowf1820382013-07-24 21:18:14 +0000998
999
Howard Hinnantab61b2c2013-08-07 19:39:48 +00001000 constexpr chrono::microseconds operator"" us(unsigned long long __us)
1001 {
1002 return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
1003 }
Marshall Clowf1820382013-07-24 21:18:14 +00001004
Howard Hinnantab61b2c2013-08-07 19:39:48 +00001005 constexpr chrono::duration<long double, micro> operator"" us(long double __us)
1006 {
1007 return chrono::duration<long double, micro> (__us);
1008 }
1009
Marshall Clowf1820382013-07-24 21:18:14 +00001010
Howard Hinnantab61b2c2013-08-07 19:39:48 +00001011 constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns)
1012 {
1013 return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
1014 }
Marshall Clowf1820382013-07-24 21:18:14 +00001015
Howard Hinnantab61b2c2013-08-07 19:39:48 +00001016 constexpr chrono::duration<long double, nano> operator"" ns(long double __ns)
1017 {
1018 return chrono::duration<long double, nano> (__ns);
1019 }
Marshall Clowf1820382013-07-24 21:18:14 +00001020
1021}}
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00001022
1023namespace chrono { // hoist the literals into namespace std::chrono
1024 using namespace literals::chrono_literals;
1025}
1026
Marshall Clowf1820382013-07-24 21:18:14 +00001027#endif
1028
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001029_LIBCPP_END_NAMESPACE_STD
1030
1031#endif // _LIBCPP_CHRONO