blob: 9fb774317daba8a934404f02cea133ee884f2a9a [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- chrono ----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-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 Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +000023constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +000033 static constexpr Rep zero();
34 static constexpr Rep max();
35 static constexpr Rep min();
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +000050 constexpr duration() = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +000051 template <class Rep2>
Howard Hinnantcf3143c2012-07-13 19:17:27 +000052 constexpr explicit duration(const Rep2& r,
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +000062 constexpr duration(const duration<Rep2, Period2>& d,
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +000071 constexpr rep count() const;
Howard Hinnantc51e1022010-05-11 19:42:16 +000072
73 // arithmetic
74
Howard Hinnantcf3143c2012-07-13 19:17:27 +000075 constexpr duration operator+() const;
76 constexpr duration operator-() const;
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +000090 static constexpr duration zero();
91 static constexpr duration min();
92 static constexpr duration max();
Howard Hinnantc51e1022010-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 Clow5c459c92013-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 Hinnantc51e1022010-05-11 19:42:16 +0000116
117 // conversions
118 template <class Duration2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000119 time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120
121 // observer
122
Marshall Clow5c459c92013-07-31 19:32:19 +0000123 duration time_since_epoch() const; // constexpr in C++14
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000149 constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000153 constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000157 constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000161 constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000165 constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000169 constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000175 constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000178 constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000181 constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000184 constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000187 constexpr
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000190 constexpr
Howard Hinnantc51e1022010-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 Clow5c459c92013-07-31 19:32:19 +0000197// time_point arithmetic (all constexpr in C++14)
Howard Hinnantc51e1022010-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 Clow5c459c92013-07-31 19:32:19 +0000211// time_point comparisons (all constexpr in C++14)
Howard Hinnantc51e1022010-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 Clow5c459c92013-07-31 19:32:19 +0000225// time_point_cast (constexpr in C++14)
Howard Hinnantc51e1022010-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 Clow5c459c92013-07-31 19:32:19 +0000239 static const bool is_steady = false; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240
Howard Hinnantaa54ac42011-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 Hinnantc51e1022010-05-11 19:42:16 +0000244};
245
Howard Hinnantc8dbd222010-11-20 19:16:30 +0000246class steady_clock
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247{
248public:
249 typedef nanoseconds duration;
250 typedef duration::rep rep;
251 typedef duration::period period;
Howard Hinnantc8dbd222010-11-20 19:16:30 +0000252 typedef chrono::time_point<steady_clock, duration> time_point;
Marshall Clow5c459c92013-07-31 19:32:19 +0000253 static const bool is_steady = true; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254
Howard Hinnantaa54ac42011-05-28 18:34:36 +0000255 static time_point now() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256};
257
Howard Hinnantc8dbd222010-11-20 19:16:30 +0000258typedef steady_clock high_resolution_clock;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259
260} // chrono
261
Marshall Cloweb41e5c2013-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 Hinnantc51e1022010-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 Hinnantc5a5fbd2011-11-29 16:45:27 +0000284#include <__undef_min_max>
285
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000286#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000288#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289
290_LIBCPP_BEGIN_NAMESPACE_STD
291
292namespace chrono
293{
294
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000295template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS_ONLY duration;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296
Howard Hinnantf39463b2010-05-18 17:32:30 +0000297template <class _Tp>
Howard Hinnantc51e1022010-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 Hinnanta37d3cf2013-08-12 18:38:34 +0000315struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::duration<_Rep1, _Period1>,
316 chrono::duration<_Rep2, _Period2> >
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000335 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000345 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000357 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000369 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-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 Hinnantcf3143c2012-07-13 19:17:27 +0000381_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-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 Hinnant874ad9a2010-09-21 21:28:23 +0000392template <class _Rep>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000393struct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394
395template <class _Rep>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000396struct _LIBCPP_TYPE_VIS_ONLY duration_values
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397{
398public:
Howard Hinnantcf3143c2012-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 Hinnantc51e1022010-05-11 19:42:16 +0000402};
403
404// duration
405
406template <class _Rep, class _Period>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000407class _LIBCPP_TYPE_VIS_ONLY duration
Howard Hinnantc51e1022010-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");
412public:
413 typedef _Rep rep;
414 typedef _Period period;
415private:
416 rep __rep_;
417public:
418
Marshall Clow5c459c92013-07-31 19:32:19 +0000419 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
420#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
Marshall Clow5c459c92013-07-31 19:32:19 +0000421 duration() = default;
Marshall Clow3dbcf132013-07-31 19:39:37 +0000422#else
423 duration() {}
Marshall Clow5c459c92013-07-31 19:32:19 +0000424#endif
425
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426 template <class _Rep2>
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000427 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 explicit duration(const _Rep2& __r,
429 typename enable_if
430 <
431 is_convertible<_Rep2, rep>::value &&
432 (treat_as_floating_point<rep>::value ||
433 !treat_as_floating_point<_Rep2>::value)
434 >::type* = 0)
435 : __rep_(__r) {}
436
437 // conversions
438 template <class _Rep2, class _Period2>
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000439 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000440 duration(const duration<_Rep2, _Period2>& __d,
441 typename enable_if
442 <
443 treat_as_floating_point<rep>::value ||
444 (ratio_divide<_Period2, period>::type::den == 1 &&
445 !treat_as_floating_point<_Rep2>::value)
446 >::type* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000447 : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448
449 // observer
450
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000451 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452
453 // arithmetic
454
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000455 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;}
456 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457 _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;}
458 _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);}
459 _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;}
460 _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);}
461
462 _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
463 _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
464
465 _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
466 _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
467 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
468 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
469
470 // special values
471
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000472 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
473 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values<rep>::min());}
474 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values<rep>::max());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475};
476
477typedef duration<long long, nano> nanoseconds;
478typedef duration<long long, micro> microseconds;
479typedef duration<long long, milli> milliseconds;
480typedef duration<long long > seconds;
481typedef duration< long, ratio< 60> > minutes;
482typedef duration< long, ratio<3600> > hours;
483
484// Duration ==
485
486template <class _LhsDuration, class _RhsDuration>
487struct __duration_eq
488{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000489 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant12967fb2013-06-28 18:09:35 +0000490 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491 {
492 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
493 return _Ct(__lhs).count() == _Ct(__rhs).count();
494 }
495};
496
497template <class _LhsDuration>
498struct __duration_eq<_LhsDuration, _LhsDuration>
499{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000500 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant12967fb2013-06-28 18:09:35 +0000501 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502 {return __lhs.count() == __rhs.count();}
503};
504
505template <class _Rep1, class _Period1, class _Rep2, class _Period2>
506inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000507_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508bool
509operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
510{
511 return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
512}
513
514// Duration !=
515
516template <class _Rep1, class _Period1, class _Rep2, class _Period2>
517inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000518_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519bool
520operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
521{
522 return !(__lhs == __rhs);
523}
524
525// Duration <
526
527template <class _LhsDuration, class _RhsDuration>
528struct __duration_lt
529{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000530 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant12967fb2013-06-28 18:09:35 +0000531 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532 {
533 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
534 return _Ct(__lhs).count() < _Ct(__rhs).count();
535 }
536};
537
538template <class _LhsDuration>
539struct __duration_lt<_LhsDuration, _LhsDuration>
540{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000541 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant12967fb2013-06-28 18:09:35 +0000542 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543 {return __lhs.count() < __rhs.count();}
544};
545
546template <class _Rep1, class _Period1, class _Rep2, class _Period2>
547inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000548_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549bool
550operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
551{
552 return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
553}
554
555// Duration >
556
557template <class _Rep1, class _Period1, class _Rep2, class _Period2>
558inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000559_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560bool
561operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
562{
563 return __rhs < __lhs;
564}
565
566// Duration <=
567
568template <class _Rep1, class _Period1, class _Rep2, class _Period2>
569inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000570_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000571bool
572operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
573{
574 return !(__rhs < __lhs);
575}
576
577// Duration >=
578
579template <class _Rep1, class _Period1, class _Rep2, class _Period2>
580inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000581_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000582bool
583operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
584{
585 return !(__lhs < __rhs);
586}
587
588// Duration +
589
590template <class _Rep1, class _Period1, class _Rep2, class _Period2>
591inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000592_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
594operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
595{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000596 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
597 return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000598}
599
600// Duration -
601
602template <class _Rep1, class _Period1, class _Rep2, class _Period2>
603inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000604_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000605typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
606operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
607{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000608 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
609 return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610}
611
612// Duration *
613
614template <class _Rep1, class _Period, class _Rep2>
615inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000616_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617typename enable_if
618<
619 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
620 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
621>::type
622operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
623{
624 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000625 typedef duration<_Cr, _Period> _Cd;
626 return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000627}
628
629template <class _Rep1, class _Period, class _Rep2>
630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000631_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000632typename enable_if
633<
634 is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
635 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
636>::type
637operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
638{
639 return __d * __s;
640}
641
642// Duration /
643
644template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
645struct __duration_divide_result
646{
647};
648
649template <class _Duration, class _Rep2,
650 bool = is_convertible<_Rep2,
651 typename common_type<typename _Duration::rep, _Rep2>::type>::value>
652struct __duration_divide_imp
653{
654};
655
656template <class _Rep1, class _Period, class _Rep2>
657struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
658{
659 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
660};
661
662template <class _Rep1, class _Period, class _Rep2>
663struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
664 : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
665{
666};
667
668template <class _Rep1, class _Period, class _Rep2>
669inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000670_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
672operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
673{
674 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000675 typedef duration<_Cr, _Period> _Cd;
676 return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677}
678
679template <class _Rep1, class _Period1, class _Rep2, class _Period2>
680inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000681_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682typename common_type<_Rep1, _Rep2>::type
683operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
684{
685 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
686 return _Ct(__lhs).count() / _Ct(__rhs).count();
687}
688
689// Duration %
690
691template <class _Rep1, class _Period, class _Rep2>
692inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000693_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000694typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
695operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
696{
697 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000698 typedef duration<_Cr, _Period> _Cd;
699 return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000700}
701
702template <class _Rep1, class _Period1, class _Rep2, class _Period2>
703inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000704_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
706operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
707{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000708 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
709 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
710 return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000711}
712
713//////////////////////////////////////////////////////////
714///////////////////// time_point /////////////////////////
715//////////////////////////////////////////////////////////
716
717template <class _Clock, class _Duration = typename _Clock::duration>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000718class _LIBCPP_TYPE_VIS_ONLY time_point
Howard Hinnantc51e1022010-05-11 19:42:16 +0000719{
720 static_assert(__is_duration<_Duration>::value,
721 "Second template parameter of time_point must be a std::chrono::duration");
722public:
723 typedef _Clock clock;
724 typedef _Duration duration;
725 typedef typename duration::rep rep;
726 typedef typename duration::period period;
727private:
728 duration __d_;
729
730public:
Marshall Clow5c459c92013-07-31 19:32:19 +0000731 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
732 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733
734 // conversions
735 template <class _Duration2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000736 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737 time_point(const time_point<clock, _Duration2>& t,
738 typename enable_if
739 <
740 is_convertible<_Duration2, duration>::value
741 >::type* = 0)
742 : __d_(t.time_since_epoch()) {}
743
744 // observer
745
Marshall Clow5c459c92013-07-31 19:32:19 +0000746 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000747
748 // arithmetic
749
Howard Hinnantecc7ba92013-07-08 21:06:38 +0000750 _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
751 _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000752
753 // special values
754
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000755 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());}
756 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757};
758
759} // chrono
760
761template <class _Clock, class _Duration1, class _Duration2>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000762struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::time_point<_Clock, _Duration1>,
763 chrono::time_point<_Clock, _Duration2> >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000764{
765 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
766};
767
768namespace chrono {
769
770template <class _ToDuration, class _Clock, class _Duration>
Marshall Clow5c459c92013-07-31 19:32:19 +0000771inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772time_point<_Clock, _ToDuration>
773time_point_cast(const time_point<_Clock, _Duration>& __t)
774{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000775 return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776}
777
778// time_point ==
779
780template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000781inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782bool
783operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
784{
785 return __lhs.time_since_epoch() == __rhs.time_since_epoch();
786}
787
788// time_point !=
789
790template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000791inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792bool
793operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
794{
795 return !(__lhs == __rhs);
796}
797
798// time_point <
799
800template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000801inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802bool
803operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
804{
805 return __lhs.time_since_epoch() < __rhs.time_since_epoch();
806}
807
808// time_point >
809
810template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000811inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812bool
813operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
814{
815 return __rhs < __lhs;
816}
817
818// time_point <=
819
820template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000821inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822bool
823operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
824{
825 return !(__rhs < __lhs);
826}
827
828// time_point >=
829
830template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000831inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000832bool
833operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
834{
835 return !(__lhs < __rhs);
836}
837
838// time_point operator+(time_point x, duration y);
839
840template <class _Clock, class _Duration1, class _Rep2, class _Period2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000841inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
843operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
844{
845 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
Marshall Clow5c459c92013-07-31 19:32:19 +0000846 return _Tr (__lhs.time_since_epoch() + __rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000847}
848
849// time_point operator+(duration x, time_point y);
850
851template <class _Rep1, class _Period1, class _Clock, class _Duration2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000852inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000853time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
854operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
855{
856 return __rhs + __lhs;
857}
858
859// time_point operator-(time_point x, duration y);
860
861template <class _Clock, class _Duration1, class _Rep2, class _Period2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000862inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
864operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
865{
866 return __lhs + (-__rhs);
867}
868
869// duration operator-(time_point x, time_point y);
870
871template <class _Clock, class _Duration1, class _Duration2>
Marshall Clow5c459c92013-07-31 19:32:19 +0000872inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000873typename common_type<_Duration1, _Duration2>::type
874operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
875{
876 return __lhs.time_since_epoch() - __rhs.time_since_epoch();
877}
878
879//////////////////////////////////////////////////////////
880/////////////////////// clocks ///////////////////////////
881//////////////////////////////////////////////////////////
882
Howard Hinnant8331b762013-03-06 23:30:19 +0000883class _LIBCPP_TYPE_VIS system_clock
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884{
885public:
886 typedef microseconds duration;
887 typedef duration::rep rep;
888 typedef duration::period period;
889 typedef chrono::time_point<system_clock> time_point;
Marshall Clow5c459c92013-07-31 19:32:19 +0000890 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891
Howard Hinnantaa54ac42011-05-28 18:34:36 +0000892 static time_point now() _NOEXCEPT;
893 static time_t to_time_t (const time_point& __t) _NOEXCEPT;
894 static time_point from_time_t(time_t __t) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895};
896
Howard Hinnant8331b762013-03-06 23:30:19 +0000897class _LIBCPP_TYPE_VIS steady_clock
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898{
899public:
900 typedef nanoseconds duration;
901 typedef duration::rep rep;
902 typedef duration::period period;
Howard Hinnantc8dbd222010-11-20 19:16:30 +0000903 typedef chrono::time_point<steady_clock, duration> time_point;
Marshall Clow5c459c92013-07-31 19:32:19 +0000904 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905
Howard Hinnantaa54ac42011-05-28 18:34:36 +0000906 static time_point now() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907};
908
Howard Hinnantc8dbd222010-11-20 19:16:30 +0000909typedef steady_clock high_resolution_clock;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910
911} // chrono
912
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000913#if _LIBCPP_STD_VER > 11
914// Literal suffixes for chrono types
915// inline // Deviation from N3690.
916// We believe the inline to be a defect and have submitted an LWG issue.
917// An LWG issue number has not yet been assigned.
918namespace literals
919{
920 inline namespace chrono_literals
921 {
922
Howard Hinnant5c167562013-08-07 19:39:48 +0000923 constexpr chrono::hours operator"" h(unsigned long long __h)
924 {
925 return chrono::hours(static_cast<chrono::hours::rep>(__h));
926 }
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000927
Howard Hinnant5c167562013-08-07 19:39:48 +0000928 constexpr chrono::duration<long double, ratio<3600,1>> operator"" h(long double __h)
929 {
930 return chrono::duration<long double, ratio<3600,1>>(__h);
931 }
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000932
933
Howard Hinnant5c167562013-08-07 19:39:48 +0000934 constexpr chrono::minutes operator"" min(unsigned long long __m)
935 {
936 return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
937 }
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000938
Howard Hinnant5c167562013-08-07 19:39:48 +0000939 constexpr chrono::duration<long double, ratio<60,1>> operator"" min(long double __m)
940 {
941 return chrono::duration<long double, ratio<60,1>> (__m);
942 }
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000943
944
Howard Hinnant5c167562013-08-07 19:39:48 +0000945 constexpr chrono::seconds operator"" s(unsigned long long __s)
946 {
947 return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
948 }
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000949
Howard Hinnant5c167562013-08-07 19:39:48 +0000950 constexpr chrono::duration<long double> operator"" s(long double __s)
951 {
952 return chrono::duration<long double> (__s);
953 }
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000954
955
Howard Hinnant5c167562013-08-07 19:39:48 +0000956 constexpr chrono::milliseconds operator"" ms(unsigned long long __ms)
957 {
958 return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
959 }
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000960
Howard Hinnant5c167562013-08-07 19:39:48 +0000961 constexpr chrono::duration<long double, milli> operator"" ms(long double __ms)
962 {
963 return chrono::duration<long double, milli>(__ms);
964 }
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000965
966
Howard Hinnant5c167562013-08-07 19:39:48 +0000967 constexpr chrono::microseconds operator"" us(unsigned long long __us)
968 {
969 return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
970 }
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000971
Howard Hinnant5c167562013-08-07 19:39:48 +0000972 constexpr chrono::duration<long double, micro> operator"" us(long double __us)
973 {
974 return chrono::duration<long double, micro> (__us);
975 }
976
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000977
Howard Hinnant5c167562013-08-07 19:39:48 +0000978 constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns)
979 {
980 return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
981 }
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000982
Howard Hinnant5c167562013-08-07 19:39:48 +0000983 constexpr chrono::duration<long double, nano> operator"" ns(long double __ns)
984 {
985 return chrono::duration<long double, nano> (__ns);
986 }
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000987
988}}
989#endif
990
Howard Hinnantc51e1022010-05-11 19:42:16 +0000991_LIBCPP_END_NAMESPACE_STD
992
993#endif // _LIBCPP_CHRONO