2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===---------------------------- chrono ----------------------------------===//
|
|
|
|
//
|
2010-05-12 05:36:01 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
2010-11-17 06:09:02 +08:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_CHRONO
|
|
|
|
#define _LIBCPP_CHRONO
|
|
|
|
|
|
|
|
/*
|
|
|
|
chrono synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
namespace chrono
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class ToDuration, class Rep, class Period>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
ToDuration
|
|
|
|
duration_cast(const duration<Rep, Period>& fd);
|
|
|
|
|
|
|
|
template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
|
|
|
|
|
|
|
|
template <class Rep>
|
|
|
|
struct duration_values
|
|
|
|
{
|
|
|
|
public:
|
2012-07-14 03:17:27 +08:00
|
|
|
static constexpr Rep zero();
|
|
|
|
static constexpr Rep max();
|
|
|
|
static constexpr Rep min();
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// duration
|
|
|
|
|
|
|
|
template <class Rep, class Period = ratio<1>>
|
|
|
|
class 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");
|
|
|
|
public:
|
|
|
|
typedef Rep rep;
|
|
|
|
typedef Period period;
|
|
|
|
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr duration() = default;
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class Rep2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr explicit duration(const Rep2& r,
|
2010-05-12 03:42:16 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<Rep2, rep>::value &&
|
|
|
|
(treat_as_floating_point<rep>::value ||
|
|
|
|
!treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
|
|
|
|
>::type* = 0);
|
|
|
|
|
|
|
|
// conversions
|
|
|
|
template <class Rep2, class Period2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr duration(const duration<Rep2, Period2>& d,
|
2010-05-12 03:42:16 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
treat_as_floating_point<rep>::value ||
|
|
|
|
ratio_divide<Period2, period>::type::den == 1
|
|
|
|
>::type* = 0);
|
|
|
|
|
|
|
|
// observer
|
|
|
|
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr rep count() const;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// arithmetic
|
|
|
|
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr duration operator+() const;
|
|
|
|
constexpr duration operator-() const;
|
2010-05-12 03:42:16 +08:00
|
|
|
duration& operator++();
|
|
|
|
duration operator++(int);
|
|
|
|
duration& operator--();
|
|
|
|
duration operator--(int);
|
|
|
|
|
|
|
|
duration& operator+=(const duration& d);
|
|
|
|
duration& operator-=(const duration& d);
|
|
|
|
|
|
|
|
duration& operator*=(const rep& rhs);
|
|
|
|
duration& operator/=(const rep& rhs);
|
|
|
|
|
|
|
|
// special values
|
|
|
|
|
2012-07-14 03:17:27 +08:00
|
|
|
static constexpr duration zero();
|
|
|
|
static constexpr duration min();
|
|
|
|
static constexpr duration max();
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef duration<long long, nano> nanoseconds;
|
|
|
|
typedef duration<long long, micro> microseconds;
|
|
|
|
typedef duration<long long, milli> milliseconds;
|
|
|
|
typedef duration<long long > seconds;
|
|
|
|
typedef duration< long, ratio< 60> > minutes;
|
|
|
|
typedef duration< long, ratio<3600> > hours;
|
|
|
|
|
|
|
|
template <class Clock, class Duration = typename Clock::duration>
|
|
|
|
class time_point
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef Clock clock;
|
|
|
|
typedef Duration duration;
|
|
|
|
typedef typename duration::rep rep;
|
|
|
|
typedef typename duration::period period;
|
|
|
|
private:
|
|
|
|
duration d_; // exposition only
|
|
|
|
|
|
|
|
public:
|
2013-08-01 03:32:19 +08:00
|
|
|
time_point(); // has value "epoch" // constexpr in C++14
|
|
|
|
explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// conversions
|
|
|
|
template <class Duration2>
|
2013-08-01 03:32:19 +08:00
|
|
|
time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// observer
|
|
|
|
|
2013-08-01 03:32:19 +08:00
|
|
|
duration time_since_epoch() const; // constexpr in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// arithmetic
|
|
|
|
|
|
|
|
time_point& operator+=(const duration& d);
|
|
|
|
time_point& operator-=(const duration& d);
|
|
|
|
|
|
|
|
// special values
|
|
|
|
|
|
|
|
static constexpr time_point min();
|
|
|
|
static constexpr time_point max();
|
|
|
|
};
|
|
|
|
|
|
|
|
} // chrono
|
|
|
|
|
|
|
|
// common_type traits
|
|
|
|
template <class Rep1, class Period1, class Rep2, class Period2>
|
|
|
|
struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
|
|
|
|
|
|
|
|
template <class Clock, class Duration1, class Duration2>
|
|
|
|
struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
|
|
|
|
|
|
|
|
namespace chrono {
|
|
|
|
|
|
|
|
// duration arithmetic
|
|
|
|
template <class Rep1, class Period1, class Rep2, class Period2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
|
|
|
|
operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
|
|
template <class Rep1, class Period1, class Rep2, class Period2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
|
|
|
|
operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
|
|
template <class Rep1, class Period, class Rep2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
duration<typename common_type<Rep1, Rep2>::type, Period>
|
|
|
|
operator*(const duration<Rep1, Period>& d, const Rep2& s);
|
|
|
|
template <class Rep1, class Period, class Rep2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
duration<typename common_type<Rep1, Rep2>::type, Period>
|
|
|
|
operator*(const Rep1& s, const duration<Rep2, Period>& d);
|
|
|
|
template <class Rep1, class Period, class Rep2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
duration<typename common_type<Rep1, Rep2>::type, Period>
|
|
|
|
operator/(const duration<Rep1, Period>& d, const Rep2& s);
|
|
|
|
template <class Rep1, class Period1, class Rep2, class Period2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
typename common_type<Rep1, Rep2>::type
|
|
|
|
operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
|
|
|
|
|
|
// duration comparisons
|
|
|
|
template <class Rep1, class Period1, class Rep2, class Period2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
|
|
template <class Rep1, class Period1, class Rep2, class Period2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
|
|
template <class Rep1, class Period1, class Rep2, class Period2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
|
|
template <class Rep1, class Period1, class Rep2, class Period2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
|
|
template <class Rep1, class Period1, class Rep2, class Period2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
|
|
template <class Rep1, class Period1, class Rep2, class Period2>
|
2012-07-14 03:17:27 +08:00
|
|
|
constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
|
|
|
|
|
|
// duration_cast
|
|
|
|
template <class ToDuration, class Rep, class Period>
|
|
|
|
ToDuration duration_cast(const duration<Rep, Period>& d);
|
|
|
|
|
2013-08-01 03:32:19 +08:00
|
|
|
// time_point arithmetic (all constexpr in C++14)
|
2010-05-12 03:42:16 +08:00
|
|
|
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);
|
|
|
|
template <class Rep1, class Period1, class Clock, class Duration2>
|
|
|
|
time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
|
|
|
|
operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
|
2013-08-01 03:32:19 +08:00
|
|
|
// time_point comparisons (all constexpr in C++14)
|
2010-05-12 03:42:16 +08:00
|
|
|
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>
|
|
|
|
bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
|
|
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>
|
|
|
|
bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
|
|
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>
|
|
|
|
bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
|
|
|
2013-08-01 03:32:19 +08:00
|
|
|
// time_point_cast (constexpr in C++14)
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class ToDuration, class Clock, class Duration>
|
|
|
|
time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
|
|
|
|
|
|
|
|
// Clocks
|
|
|
|
|
|
|
|
class system_clock
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef microseconds duration;
|
|
|
|
typedef duration::rep rep;
|
|
|
|
typedef duration::period period;
|
|
|
|
typedef chrono::time_point<system_clock> time_point;
|
2013-08-01 03:32:19 +08:00
|
|
|
static const bool is_steady = false; // constexpr in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-05-29 02:34:36 +08:00
|
|
|
static time_point now() noexcept;
|
|
|
|
static time_t to_time_t (const time_point& __t) noexcept;
|
|
|
|
static time_point from_time_t(time_t __t) noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-11-21 03:16:30 +08:00
|
|
|
class steady_clock
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef nanoseconds duration;
|
|
|
|
typedef duration::rep rep;
|
|
|
|
typedef duration::period period;
|
2010-11-21 03:16:30 +08:00
|
|
|
typedef chrono::time_point<steady_clock, duration> time_point;
|
2013-08-01 03:32:19 +08:00
|
|
|
static const bool is_steady = true; // constexpr in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-05-29 02:34:36 +08:00
|
|
|
static time_point now() noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-11-21 03:16:30 +08:00
|
|
|
typedef steady_clock high_resolution_clock;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
} // chrono
|
|
|
|
|
2013-07-25 05:18:14 +08:00
|
|
|
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
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
} // std
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <ctime>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <ratio>
|
|
|
|
#include <limits>
|
|
|
|
|
2011-11-30 00:45:27 +08:00
|
|
|
#include <__undef_min_max>
|
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2010-05-12 03:42:16 +08:00
|
|
|
#pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
|
|
|
namespace chrono
|
|
|
|
{
|
|
|
|
|
2013-08-13 02:38:34 +08:00
|
|
|
template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS_ONLY duration;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-05-19 01:32:30 +08:00
|
|
|
template <class _Tp>
|
2010-05-12 03:42:16 +08:00
|
|
|
struct __is_duration : false_type {};
|
|
|
|
|
|
|
|
template <class _Rep, class _Period>
|
|
|
|
struct __is_duration<duration<_Rep, _Period> > : true_type {};
|
|
|
|
|
|
|
|
template <class _Rep, class _Period>
|
|
|
|
struct __is_duration<const duration<_Rep, _Period> > : true_type {};
|
|
|
|
|
|
|
|
template <class _Rep, class _Period>
|
|
|
|
struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
|
|
|
|
|
|
|
|
template <class _Rep, class _Period>
|
|
|
|
struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
|
|
|
|
|
|
|
|
} // chrono
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
2013-08-13 02:38:34 +08:00
|
|
|
struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::duration<_Rep1, _Period1>,
|
|
|
|
chrono::duration<_Rep2, _Period2> >
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
|
|
|
|
typename __ratio_gcd<_Period1, _Period2>::type> type;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace chrono {
|
|
|
|
|
|
|
|
// duration_cast
|
|
|
|
|
|
|
|
template <class _FromDuration, class _ToDuration,
|
|
|
|
class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
|
|
|
|
bool = _Period::num == 1,
|
|
|
|
bool = _Period::den == 1>
|
|
|
|
struct __duration_cast;
|
|
|
|
|
|
|
|
template <class _FromDuration, class _ToDuration, class _Period>
|
|
|
|
struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
|
|
|
|
{
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
_ToDuration operator()(const _FromDuration& __fd) const
|
|
|
|
{
|
|
|
|
return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _FromDuration, class _ToDuration, class _Period>
|
|
|
|
struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
|
|
|
|
{
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
_ToDuration operator()(const _FromDuration& __fd) const
|
|
|
|
{
|
|
|
|
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
|
|
|
|
return _ToDuration(static_cast<typename _ToDuration::rep>(
|
|
|
|
static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _FromDuration, class _ToDuration, class _Period>
|
|
|
|
struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
|
|
|
|
{
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
_ToDuration operator()(const _FromDuration& __fd) const
|
|
|
|
{
|
|
|
|
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
|
|
|
|
return _ToDuration(static_cast<typename _ToDuration::rep>(
|
|
|
|
static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _FromDuration, class _ToDuration, class _Period>
|
|
|
|
struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
|
|
|
|
{
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
_ToDuration operator()(const _FromDuration& __fd) const
|
|
|
|
{
|
|
|
|
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
|
|
|
|
return _ToDuration(static_cast<typename _ToDuration::rep>(
|
|
|
|
static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
|
|
|
|
/ static_cast<_Ct>(_Period::den)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _ToDuration, class _Rep, class _Period>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
__is_duration<_ToDuration>::value,
|
|
|
|
_ToDuration
|
|
|
|
>::type
|
|
|
|
duration_cast(const duration<_Rep, _Period>& __fd)
|
|
|
|
{
|
|
|
|
return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
|
|
|
|
}
|
|
|
|
|
2010-09-22 05:28:23 +08:00
|
|
|
template <class _Rep>
|
2013-08-13 02:38:34 +08:00
|
|
|
struct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Rep>
|
2013-08-13 02:38:34 +08:00
|
|
|
struct _LIBCPP_TYPE_VIS_ONLY duration_values
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() {return numeric_limits<_Rep>::max();}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// duration
|
|
|
|
|
|
|
|
template <class _Rep, class _Period>
|
2013-08-13 02:38:34 +08:00
|
|
|
class _LIBCPP_TYPE_VIS_ONLY duration
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
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");
|
2013-09-01 00:51:56 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
|
|
|
typedef _Rep rep;
|
|
|
|
typedef _Period period;
|
|
|
|
private:
|
|
|
|
rep __rep_;
|
|
|
|
public:
|
|
|
|
|
2013-08-01 03:32:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
|
|
|
#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
|
|
|
|
duration() = default;
|
2013-08-01 03:39:37 +08:00
|
|
|
#else
|
|
|
|
duration() {}
|
2013-08-01 03:32:19 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Rep2>
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit duration(const _Rep2& __r,
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Rep2, rep>::value &&
|
|
|
|
(treat_as_floating_point<rep>::value ||
|
|
|
|
!treat_as_floating_point<_Rep2>::value)
|
|
|
|
>::type* = 0)
|
|
|
|
: __rep_(__r) {}
|
|
|
|
|
|
|
|
// conversions
|
|
|
|
template <class _Rep2, class _Period2>
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
duration(const duration<_Rep2, _Period2>& __d,
|
|
|
|
typename enable_if
|
|
|
|
<
|
2013-09-01 00:51:56 +08:00
|
|
|
__no_overflow<_Period2, period>::value && (
|
2010-05-12 03:42:16 +08:00
|
|
|
treat_as_floating_point<rep>::value ||
|
2013-09-01 00:51:56 +08:00
|
|
|
(__no_overflow<_Period2, period>::type::den == 1 &&
|
|
|
|
!treat_as_floating_point<_Rep2>::value))
|
2010-05-12 03:42:16 +08:00
|
|
|
>::type* = 0)
|
2011-07-01 05:18:19 +08:00
|
|
|
: __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// observer
|
|
|
|
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// arithmetic
|
|
|
|
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);}
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
|
|
|
|
|
|
|
|
// special values
|
|
|
|
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values<rep>::min());}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values<rep>::max());}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef duration<long long, nano> nanoseconds;
|
|
|
|
typedef duration<long long, micro> microseconds;
|
|
|
|
typedef duration<long long, milli> milliseconds;
|
|
|
|
typedef duration<long long > seconds;
|
|
|
|
typedef duration< long, ratio< 60> > minutes;
|
|
|
|
typedef duration< long, ratio<3600> > hours;
|
|
|
|
|
|
|
|
// Duration ==
|
|
|
|
|
|
|
|
template <class _LhsDuration, class _RhsDuration>
|
|
|
|
struct __duration_eq
|
|
|
|
{
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2013-06-29 02:09:35 +08:00
|
|
|
bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
|
|
|
|
return _Ct(__lhs).count() == _Ct(__rhs).count();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _LhsDuration>
|
|
|
|
struct __duration_eq<_LhsDuration, _LhsDuration>
|
|
|
|
{
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2013-06-29 02:09:35 +08:00
|
|
|
bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __lhs.count() == __rhs.count();}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
|
|
|
|
{
|
|
|
|
return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duration !=
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
|
|
|
|
{
|
|
|
|
return !(__lhs == __rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duration <
|
|
|
|
|
|
|
|
template <class _LhsDuration, class _RhsDuration>
|
|
|
|
struct __duration_lt
|
|
|
|
{
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2013-06-29 02:09:35 +08:00
|
|
|
bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
|
|
|
|
return _Ct(__lhs).count() < _Ct(__rhs).count();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _LhsDuration>
|
|
|
|
struct __duration_lt<_LhsDuration, _LhsDuration>
|
|
|
|
{
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2013-06-29 02:09:35 +08:00
|
|
|
bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __lhs.count() < __rhs.count();}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
|
|
|
|
{
|
|
|
|
return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duration >
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
|
|
|
|
{
|
|
|
|
return __rhs < __lhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duration <=
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
|
|
|
|
{
|
|
|
|
return !(__rhs < __lhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duration >=
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
|
|
|
|
{
|
|
|
|
return !(__lhs < __rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duration +
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
|
|
|
|
operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
|
|
|
|
{
|
2012-07-14 03:17:27 +08:00
|
|
|
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
|
|
|
|
return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Duration -
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
|
|
|
|
operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
|
|
|
|
{
|
2012-07-14 03:17:27 +08:00
|
|
|
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
|
|
|
|
return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Duration *
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period, class _Rep2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
|
|
|
|
duration<typename common_type<_Rep1, _Rep2>::type, _Period>
|
|
|
|
>::type
|
|
|
|
operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
|
|
|
|
{
|
|
|
|
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
|
2012-07-14 03:17:27 +08:00
|
|
|
typedef duration<_Cr, _Period> _Cd;
|
|
|
|
return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period, class _Rep2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
|
|
|
|
duration<typename common_type<_Rep1, _Rep2>::type, _Period>
|
|
|
|
>::type
|
|
|
|
operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
|
|
|
|
{
|
|
|
|
return __d * __s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duration /
|
|
|
|
|
|
|
|
template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
|
|
|
|
struct __duration_divide_result
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Duration, class _Rep2,
|
|
|
|
bool = is_convertible<_Rep2,
|
|
|
|
typename common_type<typename _Duration::rep, _Rep2>::type>::value>
|
|
|
|
struct __duration_divide_imp
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period, class _Rep2>
|
|
|
|
struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
|
|
|
|
{
|
|
|
|
typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period, class _Rep2>
|
|
|
|
struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
|
|
|
|
: __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period, class _Rep2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
|
|
|
|
operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
|
|
|
|
{
|
|
|
|
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
|
2012-07-14 03:17:27 +08:00
|
|
|
typedef duration<_Cr, _Period> _Cd;
|
|
|
|
return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duration %
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period, class _Rep2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
|
|
|
|
operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
|
|
|
|
{
|
|
|
|
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
|
2012-07-14 03:17:27 +08:00
|
|
|
typedef duration<_Cr, _Period> _Cd;
|
|
|
|
return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2010-05-12 03:42:16 +08:00
|
|
|
typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
|
|
|
|
operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
|
|
|
|
{
|
2012-07-14 03:17:27 +08:00
|
|
|
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
|
|
|
|
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
|
|
|
|
return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
///////////////////// time_point /////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
template <class _Clock, class _Duration = typename _Clock::duration>
|
2013-08-13 02:38:34 +08:00
|
|
|
class _LIBCPP_TYPE_VIS_ONLY time_point
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
static_assert(__is_duration<_Duration>::value,
|
|
|
|
"Second template parameter of time_point must be a std::chrono::duration");
|
|
|
|
public:
|
|
|
|
typedef _Clock clock;
|
|
|
|
typedef _Duration duration;
|
|
|
|
typedef typename duration::rep rep;
|
|
|
|
typedef typename duration::period period;
|
|
|
|
private:
|
|
|
|
duration __d_;
|
|
|
|
|
|
|
|
public:
|
2013-08-01 03:32:19 +08:00
|
|
|
_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) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// conversions
|
|
|
|
template <class _Duration2>
|
2013-08-01 03:32:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
time_point(const time_point<clock, _Duration2>& t,
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Duration2, duration>::value
|
|
|
|
>::type* = 0)
|
|
|
|
: __d_(t.time_since_epoch()) {}
|
|
|
|
|
|
|
|
// observer
|
|
|
|
|
2013-08-01 03:32:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// arithmetic
|
|
|
|
|
2013-07-09 05:06:38 +08:00
|
|
|
_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;}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// special values
|
|
|
|
|
2012-07-14 03:17:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // chrono
|
|
|
|
|
|
|
|
template <class _Clock, class _Duration1, class _Duration2>
|
2013-08-13 02:38:34 +08:00
|
|
|
struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::time_point<_Clock, _Duration1>,
|
|
|
|
chrono::time_point<_Clock, _Duration2> >
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace chrono {
|
|
|
|
|
|
|
|
template <class _ToDuration, class _Clock, class _Duration>
|
2013-08-01 03:32:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
time_point<_Clock, _ToDuration>
|
|
|
|
time_point_cast(const time_point<_Clock, _Duration>& __t)
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// time_point ==
|
|
|
|
|
|
|
|
template <class _Clock, class _Duration1, class _Duration2>
|
2013-08-01 03:32:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
|
|
|
|
{
|
|
|
|
return __lhs.time_since_epoch() == __rhs.time_since_epoch();
|
|
|
|
}
|
|
|
|
|
|
|
|
// time_point !=
|
|
|
|
|
|
|
|
template <class _Clock, class _Duration1, class _Duration2>
|
2013-08-01 03:32:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
|
|
|
|
{
|
|
|
|
return !(__lhs == __rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// time_point <
|
|
|
|
|
|
|
|
template <class _Clock, class _Duration1, class _Duration2>
|
2013-08-01 03:32:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
|
|
|
|
{
|
|
|
|
return __lhs.time_since_epoch() < __rhs.time_since_epoch();
|
|
|
|
}
|
|
|
|
|
|
|
|
// time_point >
|
|
|
|
|
|
|
|
template <class _Clock, class _Duration1, class _Duration2>
|
2013-08-01 03:32:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
|
|
|
|
{
|
|
|
|
return __rhs < __lhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
// time_point <=
|
|
|
|
|
|
|
|
template <class _Clock, class _Duration1, class _Duration2>
|
2013-08-01 03:32:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
|
|
|
|
{
|
|
|
|
return !(__rhs < __lhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// time_point >=
|
|
|
|
|
|
|
|
template <class _Clock, class _Duration1, class _Duration2>
|
2013-08-01 03:32:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
|
|
|
|
{
|
|
|
|
return !(__lhs < __rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// time_point operator+(time_point x, duration y);
|
|
|
|
|
|
|
|
template <class _Clock, class _Duration1, class _Rep2, class _Period2>
|
2013-08-01 03:32:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
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;
|
2013-08-01 03:32:19 +08:00
|
|
|
return _Tr (__lhs.time_since_epoch() + __rhs);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// time_point operator+(duration x, time_point y);
|
|
|
|
|
|
|
|
template <class _Rep1, class _Period1, class _Clock, class _Duration2>
|
2013-08-01 03:32:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// time_point operator-(time_point x, duration y);
|
|
|
|
|
|
|
|
template <class _Clock, class _Duration1, class _Rep2, class _Period2>
|
2013-08-01 03:32:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// duration operator-(time_point x, time_point y);
|
|
|
|
|
|
|
|
template <class _Clock, class _Duration1, class _Duration2>
|
2013-08-01 03:32:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
typename common_type<_Duration1, _Duration2>::type
|
|
|
|
operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
|
|
|
|
{
|
|
|
|
return __lhs.time_since_epoch() - __rhs.time_since_epoch();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
/////////////////////// clocks ///////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
|
2013-03-07 07:30:19 +08:00
|
|
|
class _LIBCPP_TYPE_VIS system_clock
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef microseconds duration;
|
|
|
|
typedef duration::rep rep;
|
|
|
|
typedef duration::period period;
|
|
|
|
typedef chrono::time_point<system_clock> time_point;
|
2013-08-01 03:32:19 +08:00
|
|
|
static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-05-29 02:34:36 +08:00
|
|
|
static time_point now() _NOEXCEPT;
|
|
|
|
static time_t to_time_t (const time_point& __t) _NOEXCEPT;
|
|
|
|
static time_point from_time_t(time_t __t) _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2013-03-07 07:30:19 +08:00
|
|
|
class _LIBCPP_TYPE_VIS steady_clock
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef nanoseconds duration;
|
|
|
|
typedef duration::rep rep;
|
|
|
|
typedef duration::period period;
|
2010-11-21 03:16:30 +08:00
|
|
|
typedef chrono::time_point<steady_clock, duration> time_point;
|
2013-08-01 03:32:19 +08:00
|
|
|
static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-05-29 02:34:36 +08:00
|
|
|
static time_point now() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-11-21 03:16:30 +08:00
|
|
|
typedef steady_clock high_resolution_clock;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
} // chrono
|
|
|
|
|
2013-10-06 05:18:32 +08:00
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
// Suffixes for duration literals [time.duration.literals]
|
|
|
|
inline namespace literals
|
2013-07-25 05:18:14 +08:00
|
|
|
{
|
|
|
|
inline namespace chrono_literals
|
|
|
|
{
|
|
|
|
|
2013-08-08 03:39:48 +08:00
|
|
|
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);
|
|
|
|
}
|
2013-07-25 05:18:14 +08:00
|
|
|
|
|
|
|
}}
|
2013-10-06 05:18:32 +08:00
|
|
|
|
|
|
|
namespace chrono { // hoist the literals into namespace std::chrono
|
|
|
|
using namespace literals::chrono_literals;
|
|
|
|
}
|
|
|
|
|
2013-07-25 05:18:14 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
|
|
|
#endif // _LIBCPP_CHRONO
|