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