|
libstdc++
|
00001 // <chrono> -*- C++ -*- 00002 00003 // Copyright (C) 2008-2015 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file include/chrono 00026 * This is a Standard C++ Library header. 00027 */ 00028 00029 #ifndef _GLIBCXX_CHRONO 00030 #define _GLIBCXX_CHRONO 1 00031 00032 #pragma GCC system_header 00033 00034 #if __cplusplus < 201103L 00035 # include <bits/c++0x_warning.h> 00036 #else 00037 00038 #include <ratio> 00039 #include <type_traits> 00040 #include <limits> 00041 #include <ctime> 00042 #include <bits/parse_numbers.h> // for literals support. 00043 00044 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 00045 00046 namespace std _GLIBCXX_VISIBILITY(default) 00047 { 00048 /** 00049 * @defgroup chrono Time 00050 * @ingroup utilities 00051 * 00052 * Classes and functions for time. 00053 * @{ 00054 */ 00055 00056 /** @namespace std::chrono 00057 * @brief ISO C++ 2011 entities sub-namespace for time and date. 00058 */ 00059 namespace chrono 00060 { 00061 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00062 00063 template<typename _Rep, typename _Period = ratio<1>> 00064 struct duration; 00065 00066 template<typename _Clock, typename _Dur = typename _Clock::duration> 00067 struct time_point; 00068 00069 _GLIBCXX_END_NAMESPACE_VERSION 00070 } 00071 00072 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00073 00074 // 20.11.4.3 specialization of common_type (for duration, sfinae-friendly) 00075 00076 template<typename _CT, typename _Period1, typename _Period2> 00077 struct __duration_common_type_wrapper 00078 { 00079 private: 00080 typedef __static_gcd<_Period1::num, _Period2::num> __gcd_num; 00081 typedef __static_gcd<_Period1::den, _Period2::den> __gcd_den; 00082 typedef typename _CT::type __cr; 00083 typedef ratio<__gcd_num::value, 00084 (_Period1::den / __gcd_den::value) * _Period2::den> __r; 00085 public: 00086 typedef __success_type<chrono::duration<__cr, __r>> type; 00087 }; 00088 00089 template<typename _Period1, typename _Period2> 00090 struct __duration_common_type_wrapper<__failure_type, _Period1, _Period2> 00091 { typedef __failure_type type; }; 00092 00093 template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> 00094 struct common_type<chrono::duration<_Rep1, _Period1>, 00095 chrono::duration<_Rep2, _Period2>> 00096 : public __duration_common_type_wrapper<typename __member_type_wrapper< 00097 common_type<_Rep1, _Rep2>>::type, _Period1, _Period2>::type 00098 { }; 00099 00100 // 20.11.4.3 specialization of common_type (for time_point, sfinae-friendly) 00101 00102 template<typename _CT, typename _Clock> 00103 struct __timepoint_common_type_wrapper 00104 { 00105 typedef __success_type<chrono::time_point<_Clock, typename _CT::type>> 00106 type; 00107 }; 00108 00109 template<typename _Clock> 00110 struct __timepoint_common_type_wrapper<__failure_type, _Clock> 00111 { typedef __failure_type type; }; 00112 00113 template<typename _Clock, typename _Duration1, typename _Duration2> 00114 struct common_type<chrono::time_point<_Clock, _Duration1>, 00115 chrono::time_point<_Clock, _Duration2>> 00116 : public __timepoint_common_type_wrapper<typename __member_type_wrapper< 00117 common_type<_Duration1, _Duration2>>::type, _Clock>::type 00118 { }; 00119 00120 _GLIBCXX_END_NAMESPACE_VERSION 00121 00122 namespace chrono 00123 { 00124 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00125 00126 // Primary template for duration_cast impl. 00127 template<typename _ToDur, typename _CF, typename _CR, 00128 bool _NumIsOne = false, bool _DenIsOne = false> 00129 struct __duration_cast_impl 00130 { 00131 template<typename _Rep, typename _Period> 00132 static constexpr _ToDur 00133 __cast(const duration<_Rep, _Period>& __d) 00134 { 00135 typedef typename _ToDur::rep __to_rep; 00136 return _ToDur(static_cast<__to_rep>(static_cast<_CR>(__d.count()) 00137 * static_cast<_CR>(_CF::num) 00138 / static_cast<_CR>(_CF::den))); 00139 } 00140 }; 00141 00142 template<typename _ToDur, typename _CF, typename _CR> 00143 struct __duration_cast_impl<_ToDur, _CF, _CR, true, true> 00144 { 00145 template<typename _Rep, typename _Period> 00146 static constexpr _ToDur 00147 __cast(const duration<_Rep, _Period>& __d) 00148 { 00149 typedef typename _ToDur::rep __to_rep; 00150 return _ToDur(static_cast<__to_rep>(__d.count())); 00151 } 00152 }; 00153 00154 template<typename _ToDur, typename _CF, typename _CR> 00155 struct __duration_cast_impl<_ToDur, _CF, _CR, true, false> 00156 { 00157 template<typename _Rep, typename _Period> 00158 static constexpr _ToDur 00159 __cast(const duration<_Rep, _Period>& __d) 00160 { 00161 typedef typename _ToDur::rep __to_rep; 00162 return _ToDur(static_cast<__to_rep>( 00163 static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den))); 00164 } 00165 }; 00166 00167 template<typename _ToDur, typename _CF, typename _CR> 00168 struct __duration_cast_impl<_ToDur, _CF, _CR, false, true> 00169 { 00170 template<typename _Rep, typename _Period> 00171 static constexpr _ToDur 00172 __cast(const duration<_Rep, _Period>& __d) 00173 { 00174 typedef typename _ToDur::rep __to_rep; 00175 return _ToDur(static_cast<__to_rep>( 00176 static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num))); 00177 } 00178 }; 00179 00180 template<typename _Tp> 00181 struct __is_duration 00182 : std::false_type 00183 { }; 00184 00185 template<typename _Rep, typename _Period> 00186 struct __is_duration<duration<_Rep, _Period>> 00187 : std::true_type 00188 { }; 00189 00190 /// duration_cast 00191 template<typename _ToDur, typename _Rep, typename _Period> 00192 constexpr typename enable_if<__is_duration<_ToDur>::value, 00193 _ToDur>::type 00194 duration_cast(const duration<_Rep, _Period>& __d) 00195 { 00196 typedef typename _ToDur::period __to_period; 00197 typedef typename _ToDur::rep __to_rep; 00198 typedef ratio_divide<_Period, __to_period> __cf; 00199 typedef typename common_type<__to_rep, _Rep, intmax_t>::type 00200 __cr; 00201 typedef __duration_cast_impl<_ToDur, __cf, __cr, 00202 __cf::num == 1, __cf::den == 1> __dc; 00203 return __dc::__cast(__d); 00204 } 00205 00206 /// treat_as_floating_point 00207 template<typename _Rep> 00208 struct treat_as_floating_point 00209 : is_floating_point<_Rep> 00210 { }; 00211 00212 /// duration_values 00213 template<typename _Rep> 00214 struct duration_values 00215 { 00216 static constexpr _Rep 00217 zero() 00218 { return _Rep(0); } 00219 00220 static constexpr _Rep 00221 max() 00222 { return numeric_limits<_Rep>::max(); } 00223 00224 static constexpr _Rep 00225 min() 00226 { return numeric_limits<_Rep>::lowest(); } 00227 }; 00228 00229 template<typename _Tp> 00230 struct __is_ratio 00231 : std::false_type 00232 { }; 00233 00234 template<intmax_t _Num, intmax_t _Den> 00235 struct __is_ratio<ratio<_Num, _Den>> 00236 : std::true_type 00237 { }; 00238 00239 /// duration 00240 template<typename _Rep, typename _Period> 00241 struct duration 00242 { 00243 typedef _Rep rep; 00244 typedef _Period period; 00245 00246 static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration"); 00247 static_assert(__is_ratio<_Period>::value, 00248 "period must be a specialization of ratio"); 00249 static_assert(_Period::num > 0, "period must be positive"); 00250 00251 // 20.11.5.1 construction / copy / destroy 00252 constexpr duration() = default; 00253 00254 // NB: Make constexpr implicit. This cannot be explicitly 00255 // constexpr, as any UDT that is not a literal type with a 00256 // constexpr copy constructor will be ill-formed. 00257 duration(const duration&) = default; 00258 00259 template<typename _Rep2, typename = typename 00260 enable_if<is_convertible<_Rep2, rep>::value 00261 && (treat_as_floating_point<rep>::value 00262 || !treat_as_floating_point<_Rep2>::value)>::type> 00263 constexpr explicit duration(const _Rep2& __rep) 00264 : __r(static_cast<rep>(__rep)) { } 00265 00266 template<typename _Rep2, typename _Period2, typename = typename 00267 enable_if<treat_as_floating_point<rep>::value 00268 || (ratio_divide<_Period2, period>::den == 1 00269 && !treat_as_floating_point<_Rep2>::value)>::type> 00270 constexpr duration(const duration<_Rep2, _Period2>& __d) 00271 : __r(duration_cast<duration>(__d).count()) { } 00272 00273 ~duration() = default; 00274 duration& operator=(const duration&) = default; 00275 00276 // 20.11.5.2 observer 00277 constexpr rep 00278 count() const 00279 { return __r; } 00280 00281 // 20.11.5.3 arithmetic 00282 constexpr duration 00283 operator+() const 00284 { return *this; } 00285 00286 constexpr duration 00287 operator-() const 00288 { return duration(-__r); } 00289 00290 duration& 00291 operator++() 00292 { 00293 ++__r; 00294 return *this; 00295 } 00296 00297 duration 00298 operator++(int) 00299 { return duration(__r++); } 00300 00301 duration& 00302 operator--() 00303 { 00304 --__r; 00305 return *this; 00306 } 00307 00308 duration 00309 operator--(int) 00310 { return duration(__r--); } 00311 00312 duration& 00313 operator+=(const duration& __d) 00314 { 00315 __r += __d.count(); 00316 return *this; 00317 } 00318 00319 duration& 00320 operator-=(const duration& __d) 00321 { 00322 __r -= __d.count(); 00323 return *this; 00324 } 00325 00326 duration& 00327 operator*=(const rep& __rhs) 00328 { 00329 __r *= __rhs; 00330 return *this; 00331 } 00332 00333 duration& 00334 operator/=(const rep& __rhs) 00335 { 00336 __r /= __rhs; 00337 return *this; 00338 } 00339 00340 // DR 934. 00341 template<typename _Rep2 = rep> 00342 typename enable_if<!treat_as_floating_point<_Rep2>::value, 00343 duration&>::type 00344 operator%=(const rep& __rhs) 00345 { 00346 __r %= __rhs; 00347 return *this; 00348 } 00349 00350 template<typename _Rep2 = rep> 00351 typename enable_if<!treat_as_floating_point<_Rep2>::value, 00352 duration&>::type 00353 operator%=(const duration& __d) 00354 { 00355 __r %= __d.count(); 00356 return *this; 00357 } 00358 00359 // 20.11.5.4 special values 00360 static constexpr duration 00361 zero() 00362 { return duration(duration_values<rep>::zero()); } 00363 00364 static constexpr duration 00365 min() 00366 { return duration(duration_values<rep>::min()); } 00367 00368 static constexpr duration 00369 max() 00370 { return duration(duration_values<rep>::max()); } 00371 00372 private: 00373 rep __r; 00374 }; 00375 00376 template<typename _Rep1, typename _Period1, 00377 typename _Rep2, typename _Period2> 00378 constexpr typename common_type<duration<_Rep1, _Period1>, 00379 duration<_Rep2, _Period2>>::type 00380 operator+(const duration<_Rep1, _Period1>& __lhs, 00381 const duration<_Rep2, _Period2>& __rhs) 00382 { 00383 typedef duration<_Rep1, _Period1> __dur1; 00384 typedef duration<_Rep2, _Period2> __dur2; 00385 typedef typename common_type<__dur1,__dur2>::type __cd; 00386 return __cd(__cd(__lhs).count() + __cd(__rhs).count()); 00387 } 00388 00389 template<typename _Rep1, typename _Period1, 00390 typename _Rep2, typename _Period2> 00391 constexpr typename common_type<duration<_Rep1, _Period1>, 00392 duration<_Rep2, _Period2>>::type 00393 operator-(const duration<_Rep1, _Period1>& __lhs, 00394 const duration<_Rep2, _Period2>& __rhs) 00395 { 00396 typedef duration<_Rep1, _Period1> __dur1; 00397 typedef duration<_Rep2, _Period2> __dur2; 00398 typedef typename common_type<__dur1,__dur2>::type __cd; 00399 return __cd(__cd(__lhs).count() - __cd(__rhs).count()); 00400 } 00401 00402 template<typename _Rep1, typename _Rep2, bool = 00403 is_convertible<_Rep2, 00404 typename common_type<_Rep1, _Rep2>::type>::value> 00405 struct __common_rep_type { }; 00406 00407 template<typename _Rep1, typename _Rep2> 00408 struct __common_rep_type<_Rep1, _Rep2, true> 00409 { typedef typename common_type<_Rep1, _Rep2>::type type; }; 00410 00411 template<typename _Rep1, typename _Period, typename _Rep2> 00412 constexpr 00413 duration<typename __common_rep_type<_Rep1, _Rep2>::type, _Period> 00414 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 00415 { 00416 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> 00417 __cd; 00418 return __cd(__cd(__d).count() * __s); 00419 } 00420 00421 template<typename _Rep1, typename _Rep2, typename _Period> 00422 constexpr 00423 duration<typename __common_rep_type<_Rep2, _Rep1>::type, _Period> 00424 operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) 00425 { return __d * __s; } 00426 00427 template<typename _Rep1, typename _Period, typename _Rep2> 00428 constexpr duration<typename __common_rep_type<_Rep1, typename 00429 enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period> 00430 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 00431 { 00432 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> 00433 __cd; 00434 return __cd(__cd(__d).count() / __s); 00435 } 00436 00437 template<typename _Rep1, typename _Period1, 00438 typename _Rep2, typename _Period2> 00439 constexpr typename common_type<_Rep1, _Rep2>::type 00440 operator/(const duration<_Rep1, _Period1>& __lhs, 00441 const duration<_Rep2, _Period2>& __rhs) 00442 { 00443 typedef duration<_Rep1, _Period1> __dur1; 00444 typedef duration<_Rep2, _Period2> __dur2; 00445 typedef typename common_type<__dur1,__dur2>::type __cd; 00446 return __cd(__lhs).count() / __cd(__rhs).count(); 00447 } 00448 00449 // DR 934. 00450 template<typename _Rep1, typename _Period, typename _Rep2> 00451 constexpr duration<typename __common_rep_type<_Rep1, typename 00452 enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period> 00453 operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 00454 { 00455 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> 00456 __cd; 00457 return __cd(__cd(__d).count() % __s); 00458 } 00459 00460 template<typename _Rep1, typename _Period1, 00461 typename _Rep2, typename _Period2> 00462 constexpr typename common_type<duration<_Rep1, _Period1>, 00463 duration<_Rep2, _Period2>>::type 00464 operator%(const duration<_Rep1, _Period1>& __lhs, 00465 const duration<_Rep2, _Period2>& __rhs) 00466 { 00467 typedef duration<_Rep1, _Period1> __dur1; 00468 typedef duration<_Rep2, _Period2> __dur2; 00469 typedef typename common_type<__dur1,__dur2>::type __cd; 00470 return __cd(__cd(__lhs).count() % __cd(__rhs).count()); 00471 } 00472 00473 // comparisons 00474 template<typename _Rep1, typename _Period1, 00475 typename _Rep2, typename _Period2> 00476 constexpr bool 00477 operator==(const duration<_Rep1, _Period1>& __lhs, 00478 const duration<_Rep2, _Period2>& __rhs) 00479 { 00480 typedef duration<_Rep1, _Period1> __dur1; 00481 typedef duration<_Rep2, _Period2> __dur2; 00482 typedef typename common_type<__dur1,__dur2>::type __ct; 00483 return __ct(__lhs).count() == __ct(__rhs).count(); 00484 } 00485 00486 template<typename _Rep1, typename _Period1, 00487 typename _Rep2, typename _Period2> 00488 constexpr bool 00489 operator<(const duration<_Rep1, _Period1>& __lhs, 00490 const duration<_Rep2, _Period2>& __rhs) 00491 { 00492 typedef duration<_Rep1, _Period1> __dur1; 00493 typedef duration<_Rep2, _Period2> __dur2; 00494 typedef typename common_type<__dur1,__dur2>::type __ct; 00495 return __ct(__lhs).count() < __ct(__rhs).count(); 00496 } 00497 00498 template<typename _Rep1, typename _Period1, 00499 typename _Rep2, typename _Period2> 00500 constexpr bool 00501 operator!=(const duration<_Rep1, _Period1>& __lhs, 00502 const duration<_Rep2, _Period2>& __rhs) 00503 { return !(__lhs == __rhs); } 00504 00505 template<typename _Rep1, typename _Period1, 00506 typename _Rep2, typename _Period2> 00507 constexpr bool 00508 operator<=(const duration<_Rep1, _Period1>& __lhs, 00509 const duration<_Rep2, _Period2>& __rhs) 00510 { return !(__rhs < __lhs); } 00511 00512 template<typename _Rep1, typename _Period1, 00513 typename _Rep2, typename _Period2> 00514 constexpr bool 00515 operator>(const duration<_Rep1, _Period1>& __lhs, 00516 const duration<_Rep2, _Period2>& __rhs) 00517 { return __rhs < __lhs; } 00518 00519 template<typename _Rep1, typename _Period1, 00520 typename _Rep2, typename _Period2> 00521 constexpr bool 00522 operator>=(const duration<_Rep1, _Period1>& __lhs, 00523 const duration<_Rep2, _Period2>& __rhs) 00524 { return !(__lhs < __rhs); } 00525 00526 /// nanoseconds 00527 typedef duration<int64_t, nano> nanoseconds; 00528 00529 /// microseconds 00530 typedef duration<int64_t, micro> microseconds; 00531 00532 /// milliseconds 00533 typedef duration<int64_t, milli> milliseconds; 00534 00535 /// seconds 00536 typedef duration<int64_t> seconds; 00537 00538 /// minutes 00539 typedef duration<int64_t, ratio< 60>> minutes; 00540 00541 /// hours 00542 typedef duration<int64_t, ratio<3600>> hours; 00543 00544 /// time_point 00545 template<typename _Clock, typename _Dur> 00546 struct time_point 00547 { 00548 typedef _Clock clock; 00549 typedef _Dur duration; 00550 typedef typename duration::rep rep; 00551 typedef typename duration::period period; 00552 00553 constexpr time_point() : __d(duration::zero()) 00554 { } 00555 00556 constexpr explicit time_point(const duration& __dur) 00557 : __d(__dur) 00558 { } 00559 00560 // conversions 00561 template<typename _Dur2, 00562 typename = _Require<is_convertible<_Dur2, _Dur>>> 00563 constexpr time_point(const time_point<clock, _Dur2>& __t) 00564 : __d(__t.time_since_epoch()) 00565 { } 00566 00567 // observer 00568 constexpr duration 00569 time_since_epoch() const 00570 { return __d; } 00571 00572 // arithmetic 00573 time_point& 00574 operator+=(const duration& __dur) 00575 { 00576 __d += __dur; 00577 return *this; 00578 } 00579 00580 time_point& 00581 operator-=(const duration& __dur) 00582 { 00583 __d -= __dur; 00584 return *this; 00585 } 00586 00587 // special values 00588 static constexpr time_point 00589 min() 00590 { return time_point(duration::min()); } 00591 00592 static constexpr time_point 00593 max() 00594 { return time_point(duration::max()); } 00595 00596 private: 00597 duration __d; 00598 }; 00599 00600 /// time_point_cast 00601 template<typename _ToDur, typename _Clock, typename _Dur> 00602 constexpr typename enable_if<__is_duration<_ToDur>::value, 00603 time_point<_Clock, _ToDur>>::type 00604 time_point_cast(const time_point<_Clock, _Dur>& __t) 00605 { 00606 typedef time_point<_Clock, _ToDur> __time_point; 00607 return __time_point(duration_cast<_ToDur>(__t.time_since_epoch())); 00608 } 00609 00610 template<typename _Clock, typename _Dur1, 00611 typename _Rep2, typename _Period2> 00612 constexpr time_point<_Clock, 00613 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type> 00614 operator+(const time_point<_Clock, _Dur1>& __lhs, 00615 const duration<_Rep2, _Period2>& __rhs) 00616 { 00617 typedef duration<_Rep2, _Period2> __dur2; 00618 typedef typename common_type<_Dur1,__dur2>::type __ct; 00619 typedef time_point<_Clock, __ct> __time_point; 00620 return __time_point(__lhs.time_since_epoch() + __rhs); 00621 } 00622 00623 template<typename _Rep1, typename _Period1, 00624 typename _Clock, typename _Dur2> 00625 constexpr time_point<_Clock, 00626 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type> 00627 operator+(const duration<_Rep1, _Period1>& __lhs, 00628 const time_point<_Clock, _Dur2>& __rhs) 00629 { 00630 typedef duration<_Rep1, _Period1> __dur1; 00631 typedef typename common_type<__dur1,_Dur2>::type __ct; 00632 typedef time_point<_Clock, __ct> __time_point; 00633 return __time_point(__rhs.time_since_epoch() + __lhs); 00634 } 00635 00636 template<typename _Clock, typename _Dur1, 00637 typename _Rep2, typename _Period2> 00638 constexpr time_point<_Clock, 00639 typename common_type<_Dur1, duration<_Rep2, _Period2>>::type> 00640 operator-(const time_point<_Clock, _Dur1>& __lhs, 00641 const duration<_Rep2, _Period2>& __rhs) 00642 { 00643 typedef duration<_Rep2, _Period2> __dur2; 00644 typedef typename common_type<_Dur1,__dur2>::type __ct; 00645 typedef time_point<_Clock, __ct> __time_point; 00646 return __time_point(__lhs.time_since_epoch() -__rhs); 00647 } 00648 00649 template<typename _Clock, typename _Dur1, typename _Dur2> 00650 constexpr typename common_type<_Dur1, _Dur2>::type 00651 operator-(const time_point<_Clock, _Dur1>& __lhs, 00652 const time_point<_Clock, _Dur2>& __rhs) 00653 { return __lhs.time_since_epoch() - __rhs.time_since_epoch(); } 00654 00655 template<typename _Clock, typename _Dur1, typename _Dur2> 00656 constexpr bool 00657 operator==(const time_point<_Clock, _Dur1>& __lhs, 00658 const time_point<_Clock, _Dur2>& __rhs) 00659 { return __lhs.time_since_epoch() == __rhs.time_since_epoch(); } 00660 00661 template<typename _Clock, typename _Dur1, typename _Dur2> 00662 constexpr bool 00663 operator!=(const time_point<_Clock, _Dur1>& __lhs, 00664 const time_point<_Clock, _Dur2>& __rhs) 00665 { return !(__lhs == __rhs); } 00666 00667 template<typename _Clock, typename _Dur1, typename _Dur2> 00668 constexpr bool 00669 operator<(const time_point<_Clock, _Dur1>& __lhs, 00670 const time_point<_Clock, _Dur2>& __rhs) 00671 { return __lhs.time_since_epoch() < __rhs.time_since_epoch(); } 00672 00673 template<typename _Clock, typename _Dur1, typename _Dur2> 00674 constexpr bool 00675 operator<=(const time_point<_Clock, _Dur1>& __lhs, 00676 const time_point<_Clock, _Dur2>& __rhs) 00677 { return !(__rhs < __lhs); } 00678 00679 template<typename _Clock, typename _Dur1, typename _Dur2> 00680 constexpr bool 00681 operator>(const time_point<_Clock, _Dur1>& __lhs, 00682 const time_point<_Clock, _Dur2>& __rhs) 00683 { return __rhs < __lhs; } 00684 00685 template<typename _Clock, typename _Dur1, typename _Dur2> 00686 constexpr bool 00687 operator>=(const time_point<_Clock, _Dur1>& __lhs, 00688 const time_point<_Clock, _Dur2>& __rhs) 00689 { return !(__lhs < __rhs); } 00690 00691 00692 // Clocks. 00693 00694 // Why nanosecond resolution as the default? 00695 // Why have std::system_clock always count in the higest 00696 // resolution (ie nanoseconds), even if on some OSes the low 3 00697 // or 9 decimal digits will be always zero? This allows later 00698 // implementations to change the system_clock::now() 00699 // implementation any time to provide better resolution without 00700 // changing function signature or units. 00701 00702 // To support the (forward) evolution of the library's defined 00703 // clocks, wrap inside inline namespace so that the current 00704 // defintions of system_clock, steady_clock, and 00705 // high_resolution_clock types are uniquely mangled. This way, new 00706 // code can use the latests clocks, while the library can contain 00707 // compatibility definitions for previous versions. At some 00708 // point, when these clocks settle down, the inlined namespaces 00709 // can be removed. XXX GLIBCXX_ABI Deprecated 00710 inline namespace _V2 { 00711 00712 /** 00713 * @brief System clock. 00714 * 00715 * Time returned represents wall time from the system-wide clock. 00716 */ 00717 struct system_clock 00718 { 00719 typedef chrono::nanoseconds duration; 00720 typedef duration::rep rep; 00721 typedef duration::period period; 00722 typedef chrono::time_point<system_clock, duration> time_point; 00723 00724 static_assert(system_clock::duration::min() 00725 < system_clock::duration::zero(), 00726 "a clock's minimum duration cannot be less than its epoch"); 00727 00728 static constexpr bool is_steady = false; 00729 00730 static time_point 00731 now() noexcept; 00732 00733 // Map to C API 00734 static std::time_t 00735 to_time_t(const time_point& __t) noexcept 00736 { 00737 return std::time_t(duration_cast<chrono::seconds> 00738 (__t.time_since_epoch()).count()); 00739 } 00740 00741 static time_point 00742 from_time_t(std::time_t __t) noexcept 00743 { 00744 typedef chrono::time_point<system_clock, seconds> __from; 00745 return time_point_cast<system_clock::duration> 00746 (__from(chrono::seconds(__t))); 00747 } 00748 }; 00749 00750 00751 /** 00752 * @brief Monotonic clock 00753 * 00754 * Time returned has the property of only increasing at a uniform rate. 00755 */ 00756 struct steady_clock 00757 { 00758 typedef chrono::nanoseconds duration; 00759 typedef duration::rep rep; 00760 typedef duration::period period; 00761 typedef chrono::time_point<steady_clock, duration> time_point; 00762 00763 static constexpr bool is_steady = true; 00764 00765 static time_point 00766 now() noexcept; 00767 }; 00768 00769 00770 /** 00771 * @brief Highest-resolution clock 00772 * 00773 * This is the clock "with the shortest tick period." Alias to 00774 * std::system_clock until higher-than-nanosecond definitions 00775 * become feasible. 00776 */ 00777 using high_resolution_clock = system_clock; 00778 00779 } // end inline namespace _V2 00780 00781 _GLIBCXX_END_NAMESPACE_VERSION 00782 } // namespace chrono 00783 00784 #if __cplusplus > 201103L 00785 00786 #define __cpp_lib_chrono_udls 201304 00787 00788 inline namespace literals 00789 { 00790 inline namespace chrono_literals 00791 { 00792 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00793 00794 template<typename _Rep, unsigned long long _Val> 00795 struct _Checked_integral_constant 00796 : integral_constant<_Rep, static_cast<_Rep>(_Val)> 00797 { 00798 static_assert(_Checked_integral_constant::value >= 0 00799 && _Checked_integral_constant::value == _Val, 00800 "literal value cannot be represented by duration type"); 00801 }; 00802 00803 template<typename _Dur, char... _Digits> 00804 constexpr _Dur __check_overflow() 00805 { 00806 using _Val = __parse_int::_Parse_int<_Digits...>; 00807 using _Rep = typename _Dur::rep; 00808 // TODO: should be simply integral_constant<_Rep, _Val::value> 00809 // but GCC doesn't reject narrowing conversions to _Rep. 00810 using _CheckedVal = _Checked_integral_constant<_Rep, _Val::value>; 00811 return _Dur{_CheckedVal::value}; 00812 } 00813 00814 constexpr chrono::duration<long double, ratio<3600,1>> 00815 operator""h(long double __hours) 00816 { return chrono::duration<long double, ratio<3600,1>>{__hours}; } 00817 00818 template <char... _Digits> 00819 constexpr chrono::hours 00820 operator""h() 00821 { return __check_overflow<chrono::hours, _Digits...>(); } 00822 00823 constexpr chrono::duration<long double, ratio<60,1>> 00824 operator""min(long double __mins) 00825 { return chrono::duration<long double, ratio<60,1>>{__mins}; } 00826 00827 template <char... _Digits> 00828 constexpr chrono::minutes 00829 operator""min() 00830 { return __check_overflow<chrono::minutes, _Digits...>(); } 00831 00832 constexpr chrono::duration<long double> 00833 operator""s(long double __secs) 00834 { return chrono::duration<long double>{__secs}; } 00835 00836 template <char... _Digits> 00837 constexpr chrono::seconds 00838 operator""s() 00839 { return __check_overflow<chrono::seconds, _Digits...>(); } 00840 00841 constexpr chrono::duration<long double, milli> 00842 operator""ms(long double __msecs) 00843 { return chrono::duration<long double, milli>{__msecs}; } 00844 00845 template <char... _Digits> 00846 constexpr chrono::milliseconds 00847 operator""ms() 00848 { return __check_overflow<chrono::milliseconds, _Digits...>(); } 00849 00850 constexpr chrono::duration<long double, micro> 00851 operator""us(long double __usecs) 00852 { return chrono::duration<long double, micro>{__usecs}; } 00853 00854 template <char... _Digits> 00855 constexpr chrono::microseconds 00856 operator""us() 00857 { return __check_overflow<chrono::microseconds, _Digits...>(); } 00858 00859 constexpr chrono::duration<long double, nano> 00860 operator""ns(long double __nsecs) 00861 { return chrono::duration<long double, nano>{__nsecs}; } 00862 00863 template <char... _Digits> 00864 constexpr chrono::nanoseconds 00865 operator""ns() 00866 { return __check_overflow<chrono::nanoseconds, _Digits...>(); } 00867 00868 _GLIBCXX_END_NAMESPACE_VERSION 00869 } // inline namespace chrono_literals 00870 } // inline namespace literals 00871 00872 namespace chrono 00873 { 00874 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00875 00876 using namespace literals::chrono_literals; 00877 00878 _GLIBCXX_END_NAMESPACE_VERSION 00879 } // namespace chrono 00880 00881 #endif // __cplusplus > 201103L 00882 00883 // @} group chrono 00884 } // namespace std 00885 00886 #endif //_GLIBCXX_USE_C99_STDINT_TR1 00887 00888 #endif // C++11 00889 00890 #endif //_GLIBCXX_CHRONO