blob: 219e20e73112add9d57bcbb3cdf35e009b9f372c [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:
114 time_point(); // has value "epoch"
115 explicit time_point(const duration& d); // same as time_point() + d
116
117 // conversions
118 template <class Duration2>
119 time_point(const time_point<clock, Duration2>& t);
120
121 // observer
122
123 duration time_since_epoch() const;
124
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
197// time_point arithmetic
198template <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
211// time_point comparisons
212template <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
225// time_point_cast
226
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;
Howard Hinnantc8dbd222010-11-20 19:16:30 +0000239 static const bool is_steady = false;
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;
253 static const bool is_steady = true;
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 Hinnant8331b762013-03-06 23:30:19 +0000295template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS 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 Hinnant8331b762013-03-06 23:30:19 +0000315struct _LIBCPP_TYPE_VIS common_type<chrono::duration<_Rep1, _Period1>,
Howard Hinnant874ad9a2010-09-21 21:28:23 +0000316 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 Hinnant8331b762013-03-06 23:30:19 +0000393struct _LIBCPP_TYPE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394
395template <class _Rep>
Howard Hinnant8331b762013-03-06 23:30:19 +0000396struct _LIBCPP_TYPE_VIS 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 Hinnant8331b762013-03-06 23:30:19 +0000407class _LIBCPP_TYPE_VIS 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
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000419 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration() {} // = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420 template <class _Rep2>
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000421 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422 explicit duration(const _Rep2& __r,
423 typename enable_if
424 <
425 is_convertible<_Rep2, rep>::value &&
426 (treat_as_floating_point<rep>::value ||
427 !treat_as_floating_point<_Rep2>::value)
428 >::type* = 0)
429 : __rep_(__r) {}
430
431 // conversions
432 template <class _Rep2, class _Period2>
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000433 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434 duration(const duration<_Rep2, _Period2>& __d,
435 typename enable_if
436 <
437 treat_as_floating_point<rep>::value ||
438 (ratio_divide<_Period2, period>::type::den == 1 &&
439 !treat_as_floating_point<_Rep2>::value)
440 >::type* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000441 : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442
443 // observer
444
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000445 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446
447 // arithmetic
448
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000449 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;}
450 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451 _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;}
452 _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);}
453 _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;}
454 _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);}
455
456 _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
457 _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
458
459 _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
460 _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
461 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
462 _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
463
464 // special values
465
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000466 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
467 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values<rep>::min());}
468 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values<rep>::max());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469};
470
471typedef duration<long long, nano> nanoseconds;
472typedef duration<long long, micro> microseconds;
473typedef duration<long long, milli> milliseconds;
474typedef duration<long long > seconds;
475typedef duration< long, ratio< 60> > minutes;
476typedef duration< long, ratio<3600> > hours;
477
478// Duration ==
479
480template <class _LhsDuration, class _RhsDuration>
481struct __duration_eq
482{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000483 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant12967fb2013-06-28 18:09:35 +0000484 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485 {
486 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
487 return _Ct(__lhs).count() == _Ct(__rhs).count();
488 }
489};
490
491template <class _LhsDuration>
492struct __duration_eq<_LhsDuration, _LhsDuration>
493{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000494 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant12967fb2013-06-28 18:09:35 +0000495 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496 {return __lhs.count() == __rhs.count();}
497};
498
499template <class _Rep1, class _Period1, class _Rep2, class _Period2>
500inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000501_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502bool
503operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
504{
505 return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
506}
507
508// Duration !=
509
510template <class _Rep1, class _Period1, class _Rep2, class _Period2>
511inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000512_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513bool
514operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
515{
516 return !(__lhs == __rhs);
517}
518
519// Duration <
520
521template <class _LhsDuration, class _RhsDuration>
522struct __duration_lt
523{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000524 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant12967fb2013-06-28 18:09:35 +0000525 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526 {
527 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
528 return _Ct(__lhs).count() < _Ct(__rhs).count();
529 }
530};
531
532template <class _LhsDuration>
533struct __duration_lt<_LhsDuration, _LhsDuration>
534{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000535 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant12967fb2013-06-28 18:09:35 +0000536 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537 {return __lhs.count() < __rhs.count();}
538};
539
540template <class _Rep1, class _Period1, class _Rep2, class _Period2>
541inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000542_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543bool
544operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
545{
546 return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
547}
548
549// Duration >
550
551template <class _Rep1, class _Period1, class _Rep2, class _Period2>
552inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000553_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554bool
555operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
556{
557 return __rhs < __lhs;
558}
559
560// Duration <=
561
562template <class _Rep1, class _Period1, class _Rep2, class _Period2>
563inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000564_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565bool
566operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
567{
568 return !(__rhs < __lhs);
569}
570
571// Duration >=
572
573template <class _Rep1, class _Period1, class _Rep2, class _Period2>
574inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000575_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576bool
577operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
578{
579 return !(__lhs < __rhs);
580}
581
582// Duration +
583
584template <class _Rep1, class _Period1, class _Rep2, class _Period2>
585inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000586_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
588operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
589{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000590 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
591 return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592}
593
594// Duration -
595
596template <class _Rep1, class _Period1, class _Rep2, class _Period2>
597inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000598_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
600operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
601{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000602 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
603 return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604}
605
606// Duration *
607
608template <class _Rep1, class _Period, class _Rep2>
609inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000610_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611typename enable_if
612<
613 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
614 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
615>::type
616operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
617{
618 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000619 typedef duration<_Cr, _Period> _Cd;
620 return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621}
622
623template <class _Rep1, class _Period, class _Rep2>
624inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000625_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626typename enable_if
627<
628 is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
629 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
630>::type
631operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
632{
633 return __d * __s;
634}
635
636// Duration /
637
638template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
639struct __duration_divide_result
640{
641};
642
643template <class _Duration, class _Rep2,
644 bool = is_convertible<_Rep2,
645 typename common_type<typename _Duration::rep, _Rep2>::type>::value>
646struct __duration_divide_imp
647{
648};
649
650template <class _Rep1, class _Period, class _Rep2>
651struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
652{
653 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
654};
655
656template <class _Rep1, class _Period, class _Rep2>
657struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
658 : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
659{
660};
661
662template <class _Rep1, class _Period, class _Rep2>
663inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000664_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
666operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
667{
668 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000669 typedef duration<_Cr, _Period> _Cd;
670 return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671}
672
673template <class _Rep1, class _Period1, class _Rep2, class _Period2>
674inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000675_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000676typename common_type<_Rep1, _Rep2>::type
677operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
678{
679 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
680 return _Ct(__lhs).count() / _Ct(__rhs).count();
681}
682
683// Duration %
684
685template <class _Rep1, class _Period, class _Rep2>
686inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000687_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000688typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
689operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
690{
691 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000692 typedef duration<_Cr, _Period> _Cd;
693 return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000694}
695
696template <class _Rep1, class _Period1, class _Rep2, class _Period2>
697inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000698_LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +0000699typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
700operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
701{
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000702 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
703 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
704 return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705}
706
707//////////////////////////////////////////////////////////
708///////////////////// time_point /////////////////////////
709//////////////////////////////////////////////////////////
710
711template <class _Clock, class _Duration = typename _Clock::duration>
Howard Hinnant8331b762013-03-06 23:30:19 +0000712class _LIBCPP_TYPE_VIS time_point
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713{
714 static_assert(__is_duration<_Duration>::value,
715 "Second template parameter of time_point must be a std::chrono::duration");
716public:
717 typedef _Clock clock;
718 typedef _Duration duration;
719 typedef typename duration::rep rep;
720 typedef typename duration::period period;
721private:
722 duration __d_;
723
724public:
725 _LIBCPP_INLINE_VISIBILITY time_point() : __d_(duration::zero()) {}
726 _LIBCPP_INLINE_VISIBILITY explicit time_point(const duration& __d) : __d_(__d) {}
727
728 // conversions
729 template <class _Duration2>
730 _LIBCPP_INLINE_VISIBILITY
731 time_point(const time_point<clock, _Duration2>& t,
732 typename enable_if
733 <
734 is_convertible<_Duration2, duration>::value
735 >::type* = 0)
736 : __d_(t.time_since_epoch()) {}
737
738 // observer
739
740 _LIBCPP_INLINE_VISIBILITY duration time_since_epoch() const {return __d_;}
741
742 // arithmetic
743
Howard Hinnantecc7ba92013-07-08 21:06:38 +0000744 _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
745 _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746
747 // special values
748
Howard Hinnantcf3143c2012-07-13 19:17:27 +0000749 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());}
750 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751};
752
753} // chrono
754
755template <class _Clock, class _Duration1, class _Duration2>
Howard Hinnant8331b762013-03-06 23:30:19 +0000756struct _LIBCPP_TYPE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
Howard Hinnant874ad9a2010-09-21 21:28:23 +0000757 chrono::time_point<_Clock, _Duration2> >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000758{
759 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
760};
761
762namespace chrono {
763
764template <class _ToDuration, class _Clock, class _Duration>
765inline _LIBCPP_INLINE_VISIBILITY
766time_point<_Clock, _ToDuration>
767time_point_cast(const time_point<_Clock, _Duration>& __t)
768{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000769 return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000770}
771
772// time_point ==
773
774template <class _Clock, class _Duration1, class _Duration2>
775inline _LIBCPP_INLINE_VISIBILITY
776bool
777operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
778{
779 return __lhs.time_since_epoch() == __rhs.time_since_epoch();
780}
781
782// time_point !=
783
784template <class _Clock, class _Duration1, class _Duration2>
785inline _LIBCPP_INLINE_VISIBILITY
786bool
787operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
788{
789 return !(__lhs == __rhs);
790}
791
792// time_point <
793
794template <class _Clock, class _Duration1, class _Duration2>
795inline _LIBCPP_INLINE_VISIBILITY
796bool
797operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
798{
799 return __lhs.time_since_epoch() < __rhs.time_since_epoch();
800}
801
802// time_point >
803
804template <class _Clock, class _Duration1, class _Duration2>
805inline _LIBCPP_INLINE_VISIBILITY
806bool
807operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
808{
809 return __rhs < __lhs;
810}
811
812// time_point <=
813
814template <class _Clock, class _Duration1, class _Duration2>
815inline _LIBCPP_INLINE_VISIBILITY
816bool
817operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
818{
819 return !(__rhs < __lhs);
820}
821
822// time_point >=
823
824template <class _Clock, class _Duration1, class _Duration2>
825inline _LIBCPP_INLINE_VISIBILITY
826bool
827operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
828{
829 return !(__lhs < __rhs);
830}
831
832// time_point operator+(time_point x, duration y);
833
834template <class _Clock, class _Duration1, class _Rep2, class _Period2>
835inline _LIBCPP_INLINE_VISIBILITY
836time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
837operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
838{
839 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
840 _Tr __r(__lhs.time_since_epoch());
841 __r += __rhs;
842 return __r;
843}
844
845// time_point operator+(duration x, time_point y);
846
847template <class _Rep1, class _Period1, class _Clock, class _Duration2>
848inline _LIBCPP_INLINE_VISIBILITY
849time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
850operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
851{
852 return __rhs + __lhs;
853}
854
855// time_point operator-(time_point x, duration y);
856
857template <class _Clock, class _Duration1, class _Rep2, class _Period2>
858inline _LIBCPP_INLINE_VISIBILITY
859time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
860operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
861{
862 return __lhs + (-__rhs);
863}
864
865// duration operator-(time_point x, time_point y);
866
867template <class _Clock, class _Duration1, class _Duration2>
868inline _LIBCPP_INLINE_VISIBILITY
869typename common_type<_Duration1, _Duration2>::type
870operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
871{
872 return __lhs.time_since_epoch() - __rhs.time_since_epoch();
873}
874
875//////////////////////////////////////////////////////////
876/////////////////////// clocks ///////////////////////////
877//////////////////////////////////////////////////////////
878
Howard Hinnant8331b762013-03-06 23:30:19 +0000879class _LIBCPP_TYPE_VIS system_clock
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880{
881public:
882 typedef microseconds duration;
883 typedef duration::rep rep;
884 typedef duration::period period;
885 typedef chrono::time_point<system_clock> time_point;
Howard Hinnantc8dbd222010-11-20 19:16:30 +0000886 static const bool is_steady = false;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887
Howard Hinnantaa54ac42011-05-28 18:34:36 +0000888 static time_point now() _NOEXCEPT;
889 static time_t to_time_t (const time_point& __t) _NOEXCEPT;
890 static time_point from_time_t(time_t __t) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891};
892
Howard Hinnant8331b762013-03-06 23:30:19 +0000893class _LIBCPP_TYPE_VIS steady_clock
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894{
895public:
896 typedef nanoseconds duration;
897 typedef duration::rep rep;
898 typedef duration::period period;
Howard Hinnantc8dbd222010-11-20 19:16:30 +0000899 typedef chrono::time_point<steady_clock, duration> time_point;
900 static const bool is_steady = true;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901
Howard Hinnantaa54ac42011-05-28 18:34:36 +0000902 static time_point now() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903};
904
Howard Hinnantc8dbd222010-11-20 19:16:30 +0000905typedef steady_clock high_resolution_clock;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906
907} // chrono
908
Marshall Cloweb41e5c2013-07-24 21:18:14 +0000909#if _LIBCPP_STD_VER > 11
910// Literal suffixes for chrono types
911// inline // Deviation from N3690.
912// We believe the inline to be a defect and have submitted an LWG issue.
913// An LWG issue number has not yet been assigned.
914namespace literals
915{
916 inline namespace chrono_literals
917 {
918
919 constexpr chrono::hours operator"" h(unsigned long long __h)
920 {
921 return chrono::hours(static_cast<chrono::hours::rep>(__h));
922 }
923
924 constexpr chrono::duration<long double, ratio<3600,1>> operator"" h(long double __h)
925 {
926 return chrono::duration<long double, ratio<3600,1>>(__h);
927 }
928
929
930 constexpr chrono::minutes operator"" min(unsigned long long __m)
931 {
932 return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
933 }
934
935 constexpr chrono::duration<long double, ratio<60,1>> operator"" min(long double __m)
936 {
937 return chrono::duration<long double, ratio<60,1>> (__m);
938 }
939
940
941 constexpr chrono::seconds operator"" s(unsigned long long __s)
942 {
943 return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
944 }
945
946 constexpr chrono::duration<long double> operator"" s(long double __s)
947 {
948 return chrono::duration<long double> (__s);
949 }
950
951
952 constexpr chrono::milliseconds operator"" ms(unsigned long long __ms)
953 {
954 return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
955 }
956
957 constexpr chrono::duration<long double, milli> operator"" ms(long double __ms)
958 {
959 return chrono::duration<long double, milli>(__ms);
960 }
961
962
963 constexpr chrono::microseconds operator"" us(unsigned long long __us)
964 {
965 return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
966 }
967
968 constexpr chrono::duration<long double, micro> operator"" us(long double __us)
969 {
970 return chrono::duration<long double, micro> (__us);
971 }
972
973
974 constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns)
975 {
976 return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
977 }
978
979 constexpr chrono::duration<long double, nano> operator"" ns(long double __ns)
980 {
981 return chrono::duration<long double, nano> (__ns);
982 }
983
984}}
985#endif
986
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987_LIBCPP_END_NAMESPACE_STD
988
989#endif // _LIBCPP_CHRONO