summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/include/chrono
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libc++/include/chrono')
-rw-r--r--contrib/libc++/include/chrono215
1 files changed, 172 insertions, 43 deletions
diff --git a/contrib/libc++/include/chrono b/contrib/libc++/include/chrono
index 4ceb875..2c65eee 100644
--- a/contrib/libc++/include/chrono
+++ b/contrib/libc++/include/chrono
@@ -111,16 +111,16 @@ private:
duration d_; // exposition only
public:
- time_point(); // has value "epoch"
- explicit time_point(const duration& d); // same as time_point() + d
+ time_point(); // has value "epoch" // constexpr in C++14
+ explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14
// conversions
template <class Duration2>
- time_point(const time_point<clock, Duration2>& t);
+ time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
// observer
- duration time_since_epoch() const;
+ duration time_since_epoch() const; // constexpr in C++14
// arithmetic
@@ -194,7 +194,7 @@ template <class Rep1, class Period1, class Rep2, class Period2>
template <class ToDuration, class Rep, class Period>
ToDuration duration_cast(const duration<Rep, Period>& d);
-// time_point arithmetic
+// time_point arithmetic (all constexpr in C++14)
template <class Clock, class Duration1, class Rep2, class Period2>
time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
@@ -208,7 +208,7 @@ template <class Clock, class Duration1, class Duration2>
typename common_type<Duration1, Duration2>::type
operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
-// time_point comparisons
+// time_point comparisons (all constexpr in C++14)
template <class Clock, class Duration1, class Duration2>
bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
template <class Clock, class Duration1, class Duration2>
@@ -222,7 +222,7 @@ template <class Clock, class Duration1, class Duration2>
template <class Clock, class Duration1, class Duration2>
bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
-// time_point_cast
+// time_point_cast (constexpr in C++14)
template <class ToDuration, class Clock, class Duration>
time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
@@ -236,7 +236,7 @@ public:
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<system_clock> time_point;
- static const bool is_steady = false;
+ static const bool is_steady = false; // constexpr in C++14
static time_point now() noexcept;
static time_t to_time_t (const time_point& __t) noexcept;
@@ -250,7 +250,7 @@ public:
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<steady_clock, duration> time_point;
- static const bool is_steady = true;
+ static const bool is_steady = true; // constexpr in C++14
static time_point now() noexcept;
};
@@ -259,6 +259,19 @@ typedef steady_clock high_resolution_clock;
} // chrono
+constexpr chrono::hours operator "" h(unsigned long long); // C++14
+constexpr chrono::duration<unspecified , ratio<3600,1>> operator "" h(long double); // C++14
+constexpr chrono::minutes operator "" min(unsigned long long); // C++14
+constexpr chrono::duration<unspecified , ratio<60,1>> operator "" min(long double); // C++14
+constexpr chrono::seconds operator "" s(unsigned long long); // C++14
+constexpr chrono::duration<unspecified > operator "" s(long double); // C++14
+constexpr chrono::milliseconds operator "" ms(unsigned long long); // C++14
+constexpr chrono::duration<unspecified , milli> operator "" ms(long double); // C++14
+constexpr chrono::microseconds operator "" us(unsigned long long); // C++14
+constexpr chrono::duration<unspecified , micro> operator "" us(long double); // C++14
+constexpr chrono::nanoseconds operator "" ns(unsigned long long); // C++14
+constexpr chrono::duration<unspecified , nano> operator "" ns(long double); // C++14
+
} // std
*/
@@ -279,7 +292,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
-template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS duration;
+template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS_ONLY duration;
template <class _Tp>
struct __is_duration : false_type {};
@@ -299,8 +312,8 @@ struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
} // chrono
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-struct _LIBCPP_TYPE_VIS common_type<chrono::duration<_Rep1, _Period1>,
- chrono::duration<_Rep2, _Period2> >
+struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::duration<_Rep1, _Period1>,
+ chrono::duration<_Rep2, _Period2> >
{
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
typename __ratio_gcd<_Period1, _Period2>::type> type;
@@ -377,10 +390,10 @@ duration_cast(const duration<_Rep, _Period>& __fd)
}
template <class _Rep>
-struct _LIBCPP_TYPE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
+struct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {};
template <class _Rep>
-struct _LIBCPP_TYPE_VIS duration_values
+struct _LIBCPP_TYPE_VIS_ONLY duration_values
{
public:
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);}
@@ -391,11 +404,42 @@ public:
// duration
template <class _Rep, class _Period>
-class _LIBCPP_TYPE_VIS duration
+class _LIBCPP_TYPE_VIS_ONLY duration
{
static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
static_assert(_Period::num > 0, "duration period must be positive");
+
+ template <class _R1, class _R2>
+ struct __no_overflow
+ {
+ private:
+ static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
+ static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
+ static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
+ static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
+ static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
+ static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
+ static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
+
+ template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
+ struct __mul // __overflow == false
+ {
+ static const intmax_t value = _Xp * _Yp;
+ };
+
+ template <intmax_t _Xp, intmax_t _Yp>
+ struct __mul<_Xp, _Yp, true>
+ {
+ static const intmax_t value = 1;
+ };
+
+ public:
+ static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
+ typedef ratio<__mul<__n1, __d2, !value>::value,
+ __mul<__n2, __d1, !value>::value> type;
+ };
+
public:
typedef _Rep rep;
typedef _Period period;
@@ -403,7 +447,13 @@ private:
rep __rep_;
public:
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration() {} // = default;
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+ duration() = default;
+#else
+ duration() {}
+#endif
+
template <class _Rep2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
explicit duration(const _Rep2& __r,
@@ -421,9 +471,10 @@ public:
duration(const duration<_Rep2, _Period2>& __d,
typename enable_if
<
+ __no_overflow<_Period2, period>::value && (
treat_as_floating_point<rep>::value ||
- (ratio_divide<_Period2, period>::type::den == 1 &&
- !treat_as_floating_point<_Rep2>::value)
+ (__no_overflow<_Period2, period>::type::den == 1 &&
+ !treat_as_floating_point<_Rep2>::value))
>::type* = 0)
: __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
@@ -696,7 +747,7 @@ operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2
//////////////////////////////////////////////////////////
template <class _Clock, class _Duration = typename _Clock::duration>
-class _LIBCPP_TYPE_VIS time_point
+class _LIBCPP_TYPE_VIS_ONLY time_point
{
static_assert(__is_duration<_Duration>::value,
"Second template parameter of time_point must be a std::chrono::duration");
@@ -709,12 +760,12 @@ private:
duration __d_;
public:
- _LIBCPP_INLINE_VISIBILITY time_point() : __d_(duration::zero()) {}
- _LIBCPP_INLINE_VISIBILITY explicit time_point(const duration& __d) : __d_(__d) {}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
// conversions
template <class _Duration2>
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
time_point(const time_point<clock, _Duration2>& t,
typename enable_if
<
@@ -724,12 +775,12 @@ public:
// observer
- _LIBCPP_INLINE_VISIBILITY duration time_since_epoch() const {return __d_;}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
// arithmetic
- _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
- _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
+ _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
+ _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
// special values
@@ -740,8 +791,8 @@ public:
} // chrono
template <class _Clock, class _Duration1, class _Duration2>
-struct _LIBCPP_TYPE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
- chrono::time_point<_Clock, _Duration2> >
+struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::time_point<_Clock, _Duration1>,
+ chrono::time_point<_Clock, _Duration2> >
{
typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
};
@@ -749,7 +800,7 @@ struct _LIBCPP_TYPE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
namespace chrono {
template <class _ToDuration, class _Clock, class _Duration>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
time_point<_Clock, _ToDuration>
time_point_cast(const time_point<_Clock, _Duration>& __t)
{
@@ -759,7 +810,7 @@ time_point_cast(const time_point<_Clock, _Duration>& __t)
// time_point ==
template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
@@ -769,7 +820,7 @@ operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock,
// time_point !=
template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
@@ -779,7 +830,7 @@ operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock,
// time_point <
template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
@@ -789,7 +840,7 @@ operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock,
// time_point >
template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
@@ -799,7 +850,7 @@ operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock,
// time_point <=
template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
@@ -809,7 +860,7 @@ operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock,
// time_point >=
template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
@@ -819,20 +870,18 @@ operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock,
// time_point operator+(time_point x, duration y);
template <class _Clock, class _Duration1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
- _Tr __r(__lhs.time_since_epoch());
- __r += __rhs;
- return __r;
+ return _Tr (__lhs.time_since_epoch() + __rhs);
}
// time_point operator+(duration x, time_point y);
template <class _Rep1, class _Period1, class _Clock, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
@@ -842,7 +891,7 @@ operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Dura
// time_point operator-(time_point x, duration y);
template <class _Clock, class _Duration1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
@@ -852,7 +901,7 @@ operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Pe
// duration operator-(time_point x, time_point y);
template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename common_type<_Duration1, _Duration2>::type
operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
@@ -870,7 +919,7 @@ public:
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<system_clock> time_point;
- static const bool is_steady = false;
+ static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
static time_point now() _NOEXCEPT;
static time_t to_time_t (const time_point& __t) _NOEXCEPT;
@@ -884,7 +933,7 @@ public:
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<steady_clock, duration> time_point;
- static const bool is_steady = true;
+ static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
static time_point now() _NOEXCEPT;
};
@@ -893,6 +942,86 @@ typedef steady_clock high_resolution_clock;
} // chrono
+#if _LIBCPP_STD_VER > 11
+// Suffixes for duration literals [time.duration.literals]
+inline namespace literals
+{
+ inline namespace chrono_literals
+ {
+
+ constexpr chrono::hours operator"" h(unsigned long long __h)
+ {
+ return chrono::hours(static_cast<chrono::hours::rep>(__h));
+ }
+
+ constexpr chrono::duration<long double, ratio<3600,1>> operator"" h(long double __h)
+ {
+ return chrono::duration<long double, ratio<3600,1>>(__h);
+ }
+
+
+ constexpr chrono::minutes operator"" min(unsigned long long __m)
+ {
+ return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
+ }
+
+ constexpr chrono::duration<long double, ratio<60,1>> operator"" min(long double __m)
+ {
+ return chrono::duration<long double, ratio<60,1>> (__m);
+ }
+
+
+ constexpr chrono::seconds operator"" s(unsigned long long __s)
+ {
+ return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
+ }
+
+ constexpr chrono::duration<long double> operator"" s(long double __s)
+ {
+ return chrono::duration<long double> (__s);
+ }
+
+
+ constexpr chrono::milliseconds operator"" ms(unsigned long long __ms)
+ {
+ return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
+ }
+
+ constexpr chrono::duration<long double, milli> operator"" ms(long double __ms)
+ {
+ return chrono::duration<long double, milli>(__ms);
+ }
+
+
+ constexpr chrono::microseconds operator"" us(unsigned long long __us)
+ {
+ return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
+ }
+
+ constexpr chrono::duration<long double, micro> operator"" us(long double __us)
+ {
+ return chrono::duration<long double, micro> (__us);
+ }
+
+
+ constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns)
+ {
+ return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
+ }
+
+ constexpr chrono::duration<long double, nano> operator"" ns(long double __ns)
+ {
+ return chrono::duration<long double, nano> (__ns);
+ }
+
+}}
+
+namespace chrono { // hoist the literals into namespace std::chrono
+ using namespace literals::chrono_literals;
+}
+
+#endif
+
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CHRONO
OpenPOWER on IntegriCloud