// <chrono> -*- C++ -*-
-// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
#pragma GCC system_header
#ifndef __GXX_EXPERIMENTAL_CXX0X__
-# include <c++0x_warning.h>
+# include <bits/c++0x_warning.h>
#else
-#ifdef _GLIBCXX_INCLUDE_AS_TR1
-# error C++0x header cannot be included from TR1 header
-#endif
-
#include <ratio>
#include <type_traits>
#include <limits>
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
-namespace std
+namespace std _GLIBCXX_VISIBILITY(default)
{
/**
* @defgroup chrono Time
*/
namespace chrono
{
+ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+
template<typename _Rep, typename _Period = ratio<1>>
struct duration;
- template<typename _Clock, typename _Duration = typename _Clock::duration>
+ template<typename _Clock, typename _Dur = typename _Clock::duration>
struct time_point;
+
+ _GLIBCXX_END_NAMESPACE_VERSION
}
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
// 20.8.2.3 specialization of common_type (for duration)
template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2>
struct common_type<chrono::duration<_Rep1, _Period1>,
- chrono::duration<_Rep2, _Period2>>
+ chrono::duration<_Rep2, _Period2>>
{
- typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
- ratio<__static_gcd<_Period1::num, _Period2::num>::value,
- (_Period1::den / __static_gcd<_Period1::den, _Period2::den>::value)
- * _Period2::den>> type;
+ private:
+ typedef __static_gcd<_Period1::num, _Period2::num> __gcd_num;
+ typedef __static_gcd<_Period1::den, _Period2::den> __gcd_den;
+ typedef typename common_type<_Rep1, _Rep2>::type __cr;
+ typedef ratio<__gcd_num::value,
+ (_Period1::den / __gcd_den::value) * _Period2::den> __r;
+
+ public:
+ typedef chrono::duration<__cr, __r> type;
};
-
+
// 20.8.2.3 specialization of common_type (for time_point)
- template<typename _Clock, typename _Duration1, typename _Duration2>
- struct common_type<chrono::time_point<_Clock, _Duration1>,
- chrono::time_point<_Clock, _Duration2>>
+ template<typename _Clock, typename _Dur1, typename _Dur2>
+ struct common_type<chrono::time_point<_Clock, _Dur1>,
+ chrono::time_point<_Clock, _Dur2>>
{
- typedef chrono::time_point<_Clock,
- typename common_type<_Duration1, _Duration2>::type> type;
+ private:
+ typedef typename common_type<_Dur1, _Dur2>::type __ct;
+
+ public:
+ typedef chrono::time_point<_Clock, __ct> type;
};
+_GLIBCXX_END_NAMESPACE_VERSION
- namespace chrono
+ namespace chrono
{
+ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+
// Primary template for duration_cast impl.
- template<typename _ToDuration, typename _CF, typename _CR,
- bool _NumIsOne = false, bool _DenIsOne = false>
+ template<typename _ToDur, typename _CF, typename _CR,
+ bool _NumIsOne = false, bool _DenIsOne = false>
struct __duration_cast_impl
{
- template<typename _Rep, typename _Period>
- static _ToDuration __cast(const duration<_Rep, _Period>& __d)
- {
- return _ToDuration(static_cast<
- typename _ToDuration::rep>(static_cast<_CR>(__d.count())
- * static_cast<_CR>(_CF::num)
- / static_cast<_CR>(_CF::den)));
- }
+ template<typename _Rep, typename _Period>
+ static constexpr _ToDur
+ __cast(const duration<_Rep, _Period>& __d)
+ {
+ typedef typename _ToDur::rep __to_rep;
+ return _ToDur(static_cast<__to_rep>(static_cast<_CR>(__d.count())
+ * static_cast<_CR>(_CF::num)
+ / static_cast<_CR>(_CF::den)));
+ }
};
- template<typename _ToDuration, typename _CF, typename _CR>
- struct __duration_cast_impl<_ToDuration, _CF, _CR, true, true>
+ template<typename _ToDur, typename _CF, typename _CR>
+ struct __duration_cast_impl<_ToDur, _CF, _CR, true, true>
{
- template<typename _Rep, typename _Period>
- static _ToDuration __cast(const duration<_Rep, _Period>& __d)
- {
- return _ToDuration(
- static_cast<typename _ToDuration::rep>(__d.count()));
- }
+ template<typename _Rep, typename _Period>
+ static constexpr _ToDur
+ __cast(const duration<_Rep, _Period>& __d)
+ {
+ typedef typename _ToDur::rep __to_rep;
+ return _ToDur(static_cast<__to_rep>(__d.count()));
+ }
};
- template<typename _ToDuration, typename _CF, typename _CR>
- struct __duration_cast_impl<_ToDuration, _CF, _CR, true, false>
+ template<typename _ToDur, typename _CF, typename _CR>
+ struct __duration_cast_impl<_ToDur, _CF, _CR, true, false>
{
- template<typename _Rep, typename _Period>
- static _ToDuration __cast(const duration<_Rep, _Period>& __d)
- {
- return _ToDuration(static_cast<typename _ToDuration::rep>(
- static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den)));
- }
+ template<typename _Rep, typename _Period>
+ static constexpr _ToDur
+ __cast(const duration<_Rep, _Period>& __d)
+ {
+ typedef typename _ToDur::rep __to_rep;
+ return _ToDur(static_cast<__to_rep>(
+ static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den)));
+ }
};
- template<typename _ToDuration, typename _CF, typename _CR>
- struct __duration_cast_impl<_ToDuration, _CF, _CR, false, true>
+ template<typename _ToDur, typename _CF, typename _CR>
+ struct __duration_cast_impl<_ToDur, _CF, _CR, false, true>
{
- template<typename _Rep, typename _Period>
- static _ToDuration __cast(const duration<_Rep, _Period>& __d)
- {
- return _ToDuration(static_cast<typename _ToDuration::rep>(
- static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num)));
- }
+ template<typename _Rep, typename _Period>
+ static constexpr _ToDur
+ __cast(const duration<_Rep, _Period>& __d)
+ {
+ typedef typename _ToDur::rep __to_rep;
+ return _ToDur(static_cast<__to_rep>(
+ static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num)));
+ }
};
template<typename _Tp>
{ };
/// duration_cast
- template<typename _ToDuration, typename _Rep, typename _Period>
- inline typename enable_if<__is_duration<_ToDuration>::value,
- _ToDuration>::type
+ template<typename _ToDur, typename _Rep, typename _Period>
+ inline constexpr typename enable_if<__is_duration<_ToDur>::value,
+ _ToDur>::type
duration_cast(const duration<_Rep, _Period>& __d)
{
- typedef typename
- ratio_divide<_Period, typename _ToDuration::period>::type __cf;
- typedef typename
- common_type<typename _ToDuration::rep, _Rep, intmax_t>::type __cr;
-
- return __duration_cast_impl<_ToDuration, __cf, __cr,
- __cf::num == 1, __cf::den == 1>::__cast(__d);
+ typedef typename _ToDur::period __to_period;
+ typedef typename _ToDur::rep __to_rep;
+ typedef ratio_divide<_Period, __to_period> __r_div;
+ typedef typename __r_div::type __cf;
+ typedef typename common_type<__to_rep, _Rep, intmax_t>::type
+ __cr;
+ typedef __duration_cast_impl<_ToDur, __cf, __cr,
+ __cf::num == 1, __cf::den == 1> __dc;
+ return __dc::__cast(__d);
}
/// treat_as_floating_point
template<typename _Rep>
struct duration_values
{
- static const _Rep
- zero()
- { return _Rep(0); }
-
- static const _Rep
- max()
- { return numeric_limits<_Rep>::max(); }
-
- static const _Rep
- min()
- { return numeric_limits<_Rep>::min(); }
+ static constexpr _Rep
+ zero()
+ { return _Rep(0); }
+
+ static constexpr _Rep
+ max()
+ { return numeric_limits<_Rep>::max(); }
+
+ static constexpr _Rep
+ min()
+ { return numeric_limits<_Rep>::lowest(); }
};
template<typename T>
template<typename _Rep, typename _Period>
struct duration
{
+ typedef _Rep rep;
+ typedef _Period period;
+
static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration");
- static_assert(__is_ratio<_Period>::value,
+ static_assert(__is_ratio<_Period>::value,
"period must be a specialization of ratio");
- static_assert(_Period::num > 0, "period must be positive");
-
- typedef _Rep rep;
- typedef _Period period;
-
- // 20.8.3.1 construction / copy / destroy
- duration() = default;
-
- template<typename _Rep2, typename = typename
+ static_assert(_Period::num > 0, "period must be positive");
+
+ // 20.8.3.1 construction / copy / destroy
+ constexpr duration() : __r() { }
+
+ constexpr duration(const duration&) = default;
+
+ template<typename _Rep2, typename = typename
enable_if<is_convertible<_Rep2, rep>::value
&& (treat_as_floating_point<rep>::value
|| !treat_as_floating_point<_Rep2>::value)>::type>
- explicit duration(const _Rep2& __rep)
- : __r(static_cast<rep>(__rep)) { }
+ constexpr explicit duration(const _Rep2& __rep)
+ : __r(static_cast<rep>(__rep)) { }
- template<typename _Rep2, typename _Period2, typename = typename
- enable_if<treat_as_floating_point<rep>::value
+ template<typename _Rep2, typename _Period2, typename = typename
+ enable_if<treat_as_floating_point<rep>::value
|| (ratio_divide<_Period2, period>::type::den == 1
&& !treat_as_floating_point<_Rep2>::value)>::type>
- duration(const duration<_Rep2, _Period2>& __d)
- : __r(duration_cast<duration>(__d).count()) { }
+ constexpr duration(const duration<_Rep2, _Period2>& __d)
+ : __r(duration_cast<duration>(__d).count()) { }
~duration() = default;
- duration(const duration&) = default;
duration& operator=(const duration&) = default;
- // 20.8.3.2 observer
- rep
- count() const
- { return __r; }
-
- // 20.8.3.3 arithmetic
- duration
- operator+() const
- { return *this; }
-
- duration
- operator-() const
- { return duration(-__r); }
-
- duration&
- operator++()
- {
- ++__r;
- return *this;
- }
-
- duration
- operator++(int)
- { return duration(__r++); }
-
- duration&
- operator--()
- {
- --__r;
- return *this;
- }
-
- duration
- operator--(int)
- { return duration(__r--); }
-
- duration&
- operator+=(const duration& __d)
- {
- __r += __d.count();
- return *this;
- }
-
- duration&
- operator-=(const duration& __d)
- {
- __r -= __d.count();
- return *this;
- }
-
- duration&
- operator*=(const rep& __rhs)
- {
- __r *= __rhs;
- return *this;
- }
-
- duration&
- operator/=(const rep& __rhs)
- {
- __r /= __rhs;
- return *this;
- }
+ // 20.8.3.2 observer
+ constexpr rep
+ count() const
+ { return __r; }
+
+ // 20.8.3.3 arithmetic
+ constexpr duration
+ operator+() const
+ { return *this; }
+
+ constexpr duration
+ operator-() const
+ { return duration(-__r); }
+
+ duration&
+ operator++()
+ {
+ ++__r;
+ return *this;
+ }
+
+ duration
+ operator++(int)
+ { return duration(__r++); }
+
+ duration&
+ operator--()
+ {
+ --__r;
+ return *this;
+ }
+
+ duration
+ operator--(int)
+ { return duration(__r--); }
+
+ duration&
+ operator+=(const duration& __d)
+ {
+ __r += __d.count();
+ return *this;
+ }
+
+ duration&
+ operator-=(const duration& __d)
+ {
+ __r -= __d.count();
+ return *this;
+ }
+
+ duration&
+ operator*=(const rep& __rhs)
+ {
+ __r *= __rhs;
+ return *this;
+ }
+
+ duration&
+ operator/=(const rep& __rhs)
+ {
+ __r /= __rhs;
+ return *this;
+ }
// DR 934.
template<typename _Rep2 = rep>
return *this;
}
- // 20.8.3.4 special values
- // TODO: These should be constexprs.
- static const duration
- zero()
- { return duration(duration_values<rep>::zero()); }
+ // 20.8.3.4 special values
+ static constexpr duration
+ zero()
+ { return duration(duration_values<rep>::zero()); }
- static const duration
- min()
- { return duration(duration_values<rep>::min()); }
-
- static const duration
- max()
- { return duration(duration_values<rep>::max()); }
+ static constexpr duration
+ min()
+ { return duration(duration_values<rep>::min()); }
+
+ static constexpr duration
+ max()
+ { return duration(duration_values<rep>::max()); }
private:
- rep __r;
+ rep __r;
};
template<typename _Rep1, typename _Period1,
- typename _Rep2, typename _Period2>
- inline typename common_type<duration<_Rep1, _Period1>,
- duration<_Rep2, _Period2>>::type
- operator+(const duration<_Rep1, _Period1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
+ typename _Rep2, typename _Period2>
+ inline constexpr typename common_type<duration<_Rep1, _Period1>,
+ duration<_Rep2, _Period2>>::type
+ operator+(const duration<_Rep1, _Period1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
{
- typedef typename common_type<duration<_Rep1, _Period1>,
- duration<_Rep2, _Period2>>::type __ct;
- return __ct(__lhs) += __rhs;
+ typedef duration<_Rep1, _Period1> __dur1;
+ typedef duration<_Rep2, _Period2> __dur2;
+ typedef typename common_type<__dur1,__dur2>::type __cd;
+ return __cd(__cd(__lhs).count() + __cd(__rhs).count());
}
- template<typename _Rep1, typename _Period1,
- typename _Rep2, typename _Period2>
- inline typename common_type<duration<_Rep1, _Period1>,
- duration<_Rep2, _Period2>>::type
- operator-(const duration<_Rep1, _Period1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
+ template<typename _Rep1, typename _Period1,
+ typename _Rep2, typename _Period2>
+ inline constexpr typename common_type<duration<_Rep1, _Period1>,
+ duration<_Rep2, _Period2>>::type
+ operator-(const duration<_Rep1, _Period1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
{
- typedef typename common_type<duration<_Rep1, _Period1>,
- duration<_Rep2, _Period2>>::type __ct;
- return __ct(__lhs) -= __rhs;
+ typedef duration<_Rep1, _Period1> __dur1;
+ typedef duration<_Rep2, _Period2> __dur2;
+ typedef typename common_type<__dur1,__dur2>::type __cd;
+ return __cd(__cd(__lhs).count() - __cd(__rhs).count());
}
template<typename _Rep1, typename _Rep2, bool =
template<typename _Rep1, typename _Rep2>
struct __common_rep_type<_Rep1, _Rep2, true>
- { typedef typename common_type<_Rep1, _Rep2>::type type; };
+ { typedef typename common_type<_Rep1, _Rep2>::type type; };
template<typename _Rep1, typename _Period, typename _Rep2>
- inline duration<typename __common_rep_type<_Rep1, _Rep2>::type, _Period>
+ inline constexpr
+ duration<typename __common_rep_type<_Rep1, _Rep2>::type, _Period>
operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
{
- typedef typename common_type<_Rep1, _Rep2>::type __cr;
- return duration<__cr, _Period>(__d) *= __s;
+ typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
+ __cd;
+ return __cd(__cd(__d).count() * __s);
}
template<typename _Rep1, typename _Period, typename _Rep2>
- inline duration<typename __common_rep_type<_Rep2, _Rep1>::type, _Period>
+ inline constexpr
+ duration<typename __common_rep_type<_Rep2, _Rep1>::type, _Period>
operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
{ return __d * __s; }
-
+
template<typename _Rep1, typename _Period, typename _Rep2>
- inline duration<typename __common_rep_type<_Rep1, typename
+ inline constexpr duration<typename __common_rep_type<_Rep1, typename
enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period>
operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
{
- typedef typename common_type<_Rep1, _Rep2>::type __cr;
- return duration<__cr, _Period>(__d) /= __s;
+ typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
+ __cd;
+ return __cd(__cd(__d).count() / __s);
}
template<typename _Rep1, typename _Period1,
typename _Rep2, typename _Period2>
- inline typename common_type<_Rep1, _Rep2>::type
- operator/(const duration<_Rep1, _Period1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
+ inline constexpr typename common_type<_Rep1, _Rep2>::type
+ operator/(const duration<_Rep1, _Period1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
{
- typedef typename common_type<duration<_Rep1, _Period1>,
- duration<_Rep2, _Period2>>::type __ct;
- return __ct(__lhs).count() / __ct(__rhs).count();
+ typedef duration<_Rep1, _Period1> __dur1;
+ typedef duration<_Rep2, _Period2> __dur2;
+ typedef typename common_type<__dur1,__dur2>::type __cd;
+ return __cd(__lhs).count() / __cd(__rhs).count();
}
// DR 934.
template<typename _Rep1, typename _Period, typename _Rep2>
- inline duration<typename __common_rep_type<_Rep1, typename
+ inline constexpr duration<typename __common_rep_type<_Rep1, typename
enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period>
operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
{
- typedef typename common_type<_Rep1, _Rep2>::type __cr;
- return duration<__cr, _Period>(__d) %= __s;
+ typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period>
+ __cd;
+ return __cd(__cd(__d).count() % __s);
}
template<typename _Rep1, typename _Period1,
typename _Rep2, typename _Period2>
- inline typename common_type<duration<_Rep1, _Period1>,
- duration<_Rep2, _Period2>>::type
- operator%(const duration<_Rep1, _Period1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
+ inline constexpr typename common_type<duration<_Rep1, _Period1>,
+ duration<_Rep2, _Period2>>::type
+ operator%(const duration<_Rep1, _Period1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
{
- typedef typename common_type<duration<_Rep1, _Period1>,
- duration<_Rep2, _Period2>>::type __ct;
- return __ct(__lhs) %= __rhs;
+ typedef duration<_Rep1, _Period1> __dur1;
+ typedef duration<_Rep2, _Period2> __dur2;
+ typedef typename common_type<__dur1,__dur2>::type __cd;
+ return __cd(__cd(__lhs).count() % __cd(__rhs).count());
}
// comparisons
template<typename _Rep1, typename _Period1,
- typename _Rep2, typename _Period2>
- inline bool
- operator==(const duration<_Rep1, _Period1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
+ typename _Rep2, typename _Period2>
+ inline constexpr bool
+ operator==(const duration<_Rep1, _Period1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
{
- typedef typename common_type<duration<_Rep1, _Period1>,
- duration<_Rep2, _Period2>>::type __ct;
- return __ct(__lhs).count() == __ct(__rhs).count();
+ typedef duration<_Rep1, _Period1> __dur1;
+ typedef duration<_Rep2, _Period2> __dur2;
+ typedef typename common_type<__dur1,__dur2>::type __ct;
+ return __ct(__lhs).count() == __ct(__rhs).count();
}
template<typename _Rep1, typename _Period1,
- typename _Rep2, typename _Period2>
- inline bool
- operator<(const duration<_Rep1, _Period1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
+ typename _Rep2, typename _Period2>
+ inline constexpr bool
+ operator<(const duration<_Rep1, _Period1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
{
- typedef typename common_type<duration<_Rep1, _Period1>,
- duration<_Rep2, _Period2>>::type __ct;
- return __ct(__lhs).count() < __ct(__rhs).count();
+ typedef duration<_Rep1, _Period1> __dur1;
+ typedef duration<_Rep2, _Period2> __dur2;
+ typedef typename common_type<__dur1,__dur2>::type __ct;
+ return __ct(__lhs).count() < __ct(__rhs).count();
}
template<typename _Rep1, typename _Period1,
- typename _Rep2, typename _Period2>
- inline bool
- operator!=(const duration<_Rep1, _Period1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
+ typename _Rep2, typename _Period2>
+ inline constexpr bool
+ operator!=(const duration<_Rep1, _Period1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
{ return !(__lhs == __rhs); }
template<typename _Rep1, typename _Period1,
- typename _Rep2, typename _Period2>
- inline bool
- operator<=(const duration<_Rep1, _Period1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
+ typename _Rep2, typename _Period2>
+ inline constexpr bool
+ operator<=(const duration<_Rep1, _Period1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
{ return !(__rhs < __lhs); }
template<typename _Rep1, typename _Period1,
- typename _Rep2, typename _Period2>
- inline bool
- operator>(const duration<_Rep1, _Period1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
+ typename _Rep2, typename _Period2>
+ inline constexpr bool
+ operator>(const duration<_Rep1, _Period1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
{ return __rhs < __lhs; }
- template<typename _Rep1, typename _Period1,
- typename _Rep2, typename _Period2>
- inline bool
- operator>=(const duration<_Rep1, _Period1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
+ template<typename _Rep1, typename _Period1,
+ typename _Rep2, typename _Period2>
+ inline constexpr bool
+ operator>=(const duration<_Rep1, _Period1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
{ return !(__lhs < __rhs); }
/// nanoseconds
- typedef duration<int64_t, nano> nanoseconds;
+ typedef duration<int64_t, nano> nanoseconds;
/// microseconds
- typedef duration<int64_t, micro> microseconds;
+ typedef duration<int64_t, micro> microseconds;
/// milliseconds
- typedef duration<int64_t, milli> milliseconds;
-
+ typedef duration<int64_t, milli> milliseconds;
+
/// seconds
- typedef duration<int64_t > seconds;
+ typedef duration<int64_t> seconds;
/// minutes
- typedef duration<int, ratio< 60>> minutes;
+ typedef duration<int, ratio< 60>> minutes;
/// hours
- typedef duration<int, ratio<3600>> hours;
+ typedef duration<int, ratio<3600>> hours;
/// time_point
- template<typename _Clock, typename _Duration>
+ template<typename _Clock, typename _Dur>
struct time_point
{
- typedef _Clock clock;
- typedef _Duration duration;
- typedef typename duration::rep rep;
- typedef typename duration::period period;
+ typedef _Clock clock;
+ typedef _Dur duration;
+ typedef typename duration::rep rep;
+ typedef typename duration::period period;
- time_point() : __d(duration::zero())
+ constexpr time_point() : __d(duration::zero())
{ }
- explicit time_point(const duration& __dur)
- : __d(duration::zero() + __dur)
+ constexpr explicit time_point(const duration& __dur)
+ : __d(__dur)
{ }
// conversions
- template<typename _Duration2>
- time_point(const time_point<clock, _Duration2>& __t)
+ template<typename _Dur2>
+ constexpr time_point(const time_point<clock, _Dur2>& __t)
: __d(__t.time_since_epoch())
{ }
// observer
- duration
+ constexpr duration
time_since_epoch() const
{ return __d; }
-
+
// arithmetic
time_point&
operator+=(const duration& __dur)
__d += __dur;
return *this;
}
-
+
time_point&
operator-=(const duration& __dur)
{
__d -= __dur;
return *this;
}
-
+
// special values
- // TODO: These should be constexprs.
- static const time_point
+ static constexpr time_point
min()
{ return time_point(duration::min()); }
-
- static const time_point
+
+ static constexpr time_point
max()
{ return time_point(duration::max()); }
-
+
private:
duration __d;
};
-
+
/// time_point_cast
- template<typename _ToDuration, typename _Clock, typename _Duration>
- inline typename enable_if<__is_duration<_ToDuration>::value,
- time_point<_Clock, _ToDuration>>::type
- time_point_cast(const time_point<_Clock, _Duration>& __t)
+ template<typename _ToDur, typename _Clock, typename _Dur>
+ inline constexpr typename enable_if<__is_duration<_ToDur>::value,
+ time_point<_Clock, _ToDur>>::type
+ time_point_cast(const time_point<_Clock, _Dur>& __t)
{
- return time_point<_Clock, _ToDuration>(
- duration_cast<_ToDuration>(__t.time_since_epoch()));
+ typedef time_point<_Clock, _ToDur> __time_point;
+ return __time_point(duration_cast<_ToDur>(__t.time_since_epoch()));
}
- template<typename _Clock, typename _Duration1,
- typename _Rep2, typename _Period2>
- inline time_point<_Clock,
- typename common_type<_Duration1, duration<_Rep2, _Period2>>::type>
- operator+(const time_point<_Clock, _Duration1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
+ template<typename _Clock, typename _Dur1,
+ typename _Rep2, typename _Period2>
+ inline constexpr time_point<_Clock,
+ typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
+ operator+(const time_point<_Clock, _Dur1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
{
- typedef time_point<_Clock,
- typename common_type<_Duration1,
- duration<_Rep2, _Period2>>::type> __ct;
- return __ct(__lhs) += __rhs;
+ typedef duration<_Rep2, _Period2> __dur2;
+ typedef typename common_type<_Dur1,__dur2>::type __ct;
+ typedef time_point<_Clock, __ct> __time_point;
+ return __time_point(__lhs.time_since_epoch() + __rhs);
}
template<typename _Rep1, typename _Period1,
- typename _Clock, typename _Duration2>
- inline time_point<_Clock,
- typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
- operator+(const duration<_Rep1, _Period1>& __lhs,
- const time_point<_Clock, _Duration2>& __rhs)
- { return __rhs + __lhs; }
-
- template<typename _Clock, typename _Duration1,
- typename _Rep2, typename _Period2>
- inline time_point<_Clock,
- typename common_type<_Duration1, duration<_Rep2, _Period2>>::type>
- operator-(const time_point<_Clock, _Duration1>& __lhs,
- const duration<_Rep2, _Period2>& __rhs)
- { return __lhs + (-__rhs); }
-
- template<typename _Clock, typename _Duration1, typename _Duration2>
- inline typename common_type<_Duration1, _Duration2>::type
- operator-(const time_point<_Clock, _Duration1>& __lhs,
- const time_point<_Clock, _Duration2>& __rhs)
+ typename _Clock, typename _Dur2>
+ inline constexpr time_point<_Clock,
+ typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
+ operator+(const duration<_Rep1, _Period1>& __lhs,
+ const time_point<_Clock, _Dur2>& __rhs)
+ {
+ typedef duration<_Rep1, _Period1> __dur1;
+ typedef typename common_type<__dur1,_Dur2>::type __ct;
+ typedef time_point<_Clock, __ct> __time_point;
+ return __time_point(__rhs.time_since_epoch() + __lhs);
+ }
+
+ template<typename _Clock, typename _Dur1,
+ typename _Rep2, typename _Period2>
+ inline constexpr time_point<_Clock,
+ typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
+ operator-(const time_point<_Clock, _Dur1>& __lhs,
+ const duration<_Rep2, _Period2>& __rhs)
+ {
+ typedef duration<_Rep2, _Period2> __dur2;
+ typedef typename common_type<_Dur1,__dur2>::type __ct;
+ typedef time_point<_Clock, __ct> __time_point;
+ return __time_point(__lhs.time_since_epoch() -__rhs);
+ }
+
+ template<typename _Clock, typename _Dur1, typename _Dur2>
+ inline constexpr typename common_type<_Dur1, _Dur2>::type
+ operator-(const time_point<_Clock, _Dur1>& __lhs,
+ const time_point<_Clock, _Dur2>& __rhs)
{ return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
- template<typename _Clock, typename _Duration1, typename _Duration2>
- inline bool
- operator==(const time_point<_Clock, _Duration1>& __lhs,
- const time_point<_Clock, _Duration2>& __rhs)
+ template<typename _Clock, typename _Dur1, typename _Dur2>
+ inline constexpr bool
+ operator==(const time_point<_Clock, _Dur1>& __lhs,
+ const time_point<_Clock, _Dur2>& __rhs)
{ return __lhs.time_since_epoch() == __rhs.time_since_epoch(); }
- template<typename _Clock, typename _Duration1, typename _Duration2>
- inline bool
- operator!=(const time_point<_Clock, _Duration1>& __lhs,
- const time_point<_Clock, _Duration2>& __rhs)
+ template<typename _Clock, typename _Dur1, typename _Dur2>
+ inline constexpr bool
+ operator!=(const time_point<_Clock, _Dur1>& __lhs,
+ const time_point<_Clock, _Dur2>& __rhs)
{ return !(__lhs == __rhs); }
- template<typename _Clock, typename _Duration1, typename _Duration2>
- inline bool
- operator<(const time_point<_Clock, _Duration1>& __lhs,
- const time_point<_Clock, _Duration2>& __rhs)
+ template<typename _Clock, typename _Dur1, typename _Dur2>
+ inline constexpr bool
+ operator<(const time_point<_Clock, _Dur1>& __lhs,
+ const time_point<_Clock, _Dur2>& __rhs)
{ return __lhs.time_since_epoch() < __rhs.time_since_epoch(); }
- template<typename _Clock, typename _Duration1, typename _Duration2>
- inline bool
- operator<=(const time_point<_Clock, _Duration1>& __lhs,
- const time_point<_Clock, _Duration2>& __rhs)
+ template<typename _Clock, typename _Dur1, typename _Dur2>
+ inline constexpr bool
+ operator<=(const time_point<_Clock, _Dur1>& __lhs,
+ const time_point<_Clock, _Dur2>& __rhs)
{ return !(__rhs < __lhs); }
- template<typename _Clock, typename _Duration1, typename _Duration2>
- inline bool
- operator>(const time_point<_Clock, _Duration1>& __lhs,
- const time_point<_Clock, _Duration2>& __rhs)
+ template<typename _Clock, typename _Dur1, typename _Dur2>
+ inline constexpr bool
+ operator>(const time_point<_Clock, _Dur1>& __lhs,
+ const time_point<_Clock, _Dur2>& __rhs)
{ return __rhs < __lhs; }
- template<typename _Clock, typename _Duration1, typename _Duration2>
- inline bool
- operator>=(const time_point<_Clock, _Duration1>& __lhs,
- const time_point<_Clock, _Duration2>& __rhs)
+ template<typename _Clock, typename _Dur1, typename _Dur2>
+ inline constexpr bool
+ operator>=(const time_point<_Clock, _Dur1>& __lhs,
+ const time_point<_Clock, _Dur2>& __rhs)
{ return !(__lhs < __rhs); }
/// system_clock
struct system_clock
{
#ifdef _GLIBCXX_USE_CLOCK_REALTIME
- typedef chrono::nanoseconds duration;
+ typedef chrono::nanoseconds duration;
#elif defined(_GLIBCXX_USE_GETTIMEOFDAY)
- typedef chrono::microseconds duration;
+ typedef chrono::microseconds duration;
#else
- typedef chrono::seconds duration;
+ typedef chrono::seconds duration;
#endif
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<system_clock, duration> time_point;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<system_clock, duration> time_point;
- static const bool is_monotonic = false;
+ static_assert(system_clock::duration::min()
+ < system_clock::duration::zero(),
+ "a clock's minimum duration cannot be less than its epoch");
+
+ static constexpr bool is_steady = false;
static time_point
now() throw ();
static std::time_t
to_time_t(const time_point& __t)
{
- return std::time_t(
- duration_cast<chrono::seconds>(__t.time_since_epoch()).count());
+ return std::time_t(duration_cast<chrono::seconds>
+ (__t.time_since_epoch()).count());
}
static time_point
from_time_t(std::time_t __t)
- {
- return time_point_cast<system_clock::duration>(
- chrono::time_point<system_clock, chrono::seconds>(
- chrono::seconds(__t)));
+ {
+ typedef chrono::time_point<system_clock, seconds> __from;
+ return time_point_cast<system_clock::duration>
+ (__from(chrono::seconds(__t)));
}
-
- // TODO: requires constexpr
- /*
- static_assert(
- system_clock::duration::min() <
- system_clock::duration::zero(),
- "a clock's minimum duration cannot be less than its epoch");
- */
};
#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC
- /// monotonic_clock
- struct monotonic_clock
+ /// steady_clock
+ struct steady_clock
{
- typedef chrono::nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<monotonic_clock, duration> time_point;
+ typedef chrono::nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<steady_clock, duration> time_point;
- static const bool is_monotonic = true;
+ static constexpr bool is_steady = true;
static time_point
now();
};
#else
- typedef system_clock monotonic_clock;
+ typedef system_clock steady_clock;
#endif
typedef system_clock high_resolution_clock;
+
+ _GLIBCXX_END_NAMESPACE_VERSION
} // namespace chrono
// @} group chrono
-} // namespace std
+} // namespace
#endif //_GLIBCXX_USE_C99_STDINT_TR1