<chrono>

[added with C++11]


common_type · duration · duration_cast · duration_values · high_resolution_clock · hours · microseconds · milliseconds · minutes · monotonic_clock · nanoseconds · operator+ · operator- · operator* · operator/ · operator== · operator!= · operator< · operator<= · operator> · operator>= · seconds · steady_clock · system_clock · time_point · time_point_cast · treat_as_floating_point


Include the standard header <chrono> to define various classes and template classes to represent time durations and time instants as well as several template functions for manipulating them in various ways.

namespace std {
    namespace chrono {

    // CLASS TEMPLATE duration
template<class Rep, class Period = ratio<1> >
    class duration;

    // duration ARITHMETIC
template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
        operator+(
            const duration<Rep1, Period1>& Left,
            const duration<Rep2, Period2>& Right);
template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
        operator-(
            const duration<Rep1, Period1>& Left,
            const duration<Rep2, Period2>& Right);
template<class Rep1, class Period1, class Rep2>
    constexpr duration<typename common_type<Rep1, Rep2>::type, Period1>
        operator*(
            const duration<Rep1, Period1>& Left,
            const Rep2& Right);
template<class Rep1, class Rep2, class Period2>
    constexpr duration<typename common_type<Rep1, Rep2>::type, Period>
        operator*(
            const Rep1& Left,
            const duration<Rep2, Period2>& Right);
template<class Rep1, class Period1, class Rep2>
    constexpr duration<typename common_type<Rep1, Rep2>::type, Period1>
        operator/(
            const duration<Rep1, Period1>& Dur,
            const Rep2& Div);
template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr typename common_type<Rep1, Rep2>::type
        operator/(
            const duration<Rep1, Period1>& Left,
            const duration<Rep2, Period2>& Right);

    // duration COMPARISONS
template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator==(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator!=(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator< (
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator<=(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator> (
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator>=(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);

    // duration CAST
template<class To, class Rep, class Period>
    constexpr To duration_cast(const duration<Rep, Period>& Dur);

    // PREDEFINED duration TYPES
typedef duration<i64-type,         nano> nanoseconds;
typedef duration<i55-type,        micro> microseconds;
typedef duration<i45-type,        milli> milliseconds;
typedef duration<i35-type              > seconds;
typedef duration<i29-type, ratio<  60> > minutes;
typedef duration<i23-type, ratio<3600> > hours;

    // CLASS TEMPLATE time_point
template<class Clock, class Duration = typename Clock::duration> class time_point;

    // time_point ARITHMETIC
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>& Time,
        const duration<Rep2, Period2>& Dur);
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>& Dur,
        const time_point<Clock, Duration2>& Time);
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>& Time,
        const duration<Rep2, Period2>& Duration);
template<class Clock, class Duration1, class Duration2>
    typename common_type<Duration1, Duration2>::type
    operator-(
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);

    // time_point COMPARISONS
template<class Clock, class Duration1, class Duration2>
    bool operator==(
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);
template<class Clock, class Duration1, class Duration2>
    bool operator!=(
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);
template<class Clock, class Duration1, class Duration2>
    bool operator< (
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);
template<class Clock, class Duration1, class Duration2>
    bool operator<=(
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);
template<class Clock, class Duration1, class Duration2>
    bool operator> (
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);
template<class Clock, class Duration1, class Duration2>
    bool operator>=(
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);

    // time_point CAST
template<class To, class Clock, class Duration>
    time_point<Clock, To> time_point_cast(const time_point<Clock, Duration>& t);

    // CLOCKS
class system_clock;
class monotonic_clock;  // retained
class steady_clock;
class high_resolution_clock;

    // CUSTOMIZATION TRAITS
template<class Rep> struct treat_as_floating_point;
template<class Rep> struct duration_values;

    }   // namespace chrono

    // common_type SPECIALIZATIONS
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 std

common_type

template<class Rep1, class Period1, class Rep2, class Period2>
    struct common_type<
        chrono::duration<Rep1, Period1>,
        chrono::duration<Rep2, Period2> >
        {
        typedef chrono::duration<
            typename common_type<Rep1, Rep2>::type, see below> type;
        };
template<class Clock, class Duration1, class Duration2>
    struct common_type<
        chrono::time_point<Clock, Duration1>,
        chrono::time_point<Clock, Duration2> >
        {
        typedef chrono::time_point<
            Clock, typename common_type<Duration1, Duration2>::type> type;
        };

The types describe specializations of template class common_type specialized for instantiations of duration and time_point.

duration


count · duration · max · min · operator+ · operator++ · operator+= · operator- · operator-- · operator-= · operator*= · operator/= · operator%= · period · rep · zero


template<class Rep, class Period = ratio<1> >
    class duration
    {
public:
    // TYPES
    typedef Rep rep;
    typedef Period period;

    // CONSTRUCT, COPY, DESTROY
    constexpr duration() = default;
    template<class Rep2>
        constexpr explicit duration(const Rep2& R);
    template<class Rep2, class Period2>
        constexpr duration(const duration<Rep2, Period2>& Dur);
    duration(const duration&) = default;
    duration& operator=(const duration& Right) = default;
    ~duration() = default;

    // OBSERVERS
    constexpr rep count() const;

    // ARITHMETIC OPERATIONS
    constexpr duration  operator+() const;
    constexpr duration  operator-() const;
    duration& operator++();
    duration  operator++(int);
    duration& operator--();
    duration  operator--(int);

    duration& operator+=(const duration& Dur);
    duration& operator-=(const duration& Dur);
    duration& operator*=(const rep& Mult);
    duration& operator/=(const rep& Div);
    duration& operator%=(const rep& Div);
    duration& operator%=(const duration& Div);

    // SPECIAL VALUES
    static constexpr duration zero();
    static constexpr duration min();
    static constexpr duration max();
    };

The template class describes a type that holds a time interval, that is, the elapsed time between two time points. The template argument Rep describes the type used to hold a count of the number of clock ticks in the interval and the template argument Period is an instantiation of ratio that describes the size of the interval that each tick represents.

duration::count

constexpr rep count() const;

The member function returns the number of clock ticks in the time interval.

duration

constexpr duration() = default;
template<class Rep2>
    constexpr explicit duration(const Rep2& R);
template<class Rep2, class Period2>
    constexpr duration(const duration<Rep2, Period2>& Dur);
duration(const duration&) = default;

The first constructor constructs an object that represents a time interval of zero clock ticks.

The second constructor constructs an object that represents a time interval of R clock ticks. To avoid roundoff of tick counts, it is an error to construct a duration object from a representation type Rep2 that can be treated as a floating-point type when the duration type's representation type Rep cannot be treated as a floating-point type.

The third constructor constructs an object that represents a time interval whose length is the same as the time interval represented by Dur. To avoid truncation of tick counts, it is an error to construct a duration object from another duration object whose type is incommensurable with the target type.

A duration type D1 is incommensurable with another duration type D2 if D2 cannot be treated as a floating-point type and ratio_divide<D1::period, D2::period>::type::den is not 1.

Unless treat_as_floating_point<Rep> holds true and treat_as_floating_point<Rep2> holds false, the template constructor duration(const Rep2& R) does not participate in overload resolution.

Unless treat_as_floating_point<Rep> holds true and treat_as_floating_point<Rep2>, or both ratio_divide<Period2, period>::den equals one and treat_as_floating_point<Rep2> holds false, the template constructor duration(const duration<Rep2, Period2>& Dur) does not participate in overload resolution.

duration::max

static constexpr duration max();

The static member function returns duration(duration_values<rep>::max()).

duration::min

static constexpr duration min();

The static member function returns duration(duration_values<rep>::min()).

duration::operator%=

duration& operator%=(const rep& Div);
duration& operator%=(const duration& Div);

The first member function reduces the stored tick count modulo Div and returns *this.

The second member function reduces the stored tick count modulo Div.count() and returns *this.

duration::operator+

constexpr duration operator+() const;

The member function returns *this.

duration::operator++

duration& operator++();
duration operator++(int);

The first member function increments the stored tick count and returns *this.

The second member function copies *this, increments the stored tick count in *this, and returns the copy.

duration::operator+=

duration& operator+=(const duration& Dur);

The member function adds Dur.count() to the stored tick count and returns *this.

duration::operator-

constexpr duration operator-() const;

The member function returns a copy of *this with a stored tick count that is the negation of the stored tick count in *this.

duration::operator--

duration& operator--();
duration operator--(int);

The first member function decrements the stored tick count and returns *this.

The second member function copies *this, decrements the stored tick count in *this, and returns the copy.

duration::operator-=

duration& operator-=(const duration& Dur);

The member function subtracts Dur.count() to the stored tick count and returns *this.

duration::operator*=

duration& operator*=(const rep& Mult);

The member function multiplies the stored tick count by Mult and returns *this.

duration::operator/=

duration& operator/=(const duration& Div);

The member function divides the stored tick count by Div and returns *this.

duration::period

typedef Period period;

The type is a synonym for the template parameter Period.

duration::rep

typedef Rep rep;

The type is a synonym for the template parameter Rep.

duration::zero

static constexpr duration zero();

The static member function returns duration(duration_values<rep>::zero()).

duration_cast

template<class To, class Rep, class Period>
    constexpr To duration_cast(const duration<Rep, Period>& Dur);

The template function returns a duration object of type To that represents the time interval Dur, truncated if necessary to fit in the target type.

Unless To is not an instantiation of duration, the template function does not participate in overload resolution.

duration_values

template<class Rep>
    struct duration_values
    {
    static constexpr Rep zero();
    static constexpr Rep min();
    static constexpr Rep max();
    };

The template class provides a few specific values of the template parameter Rep that are used by the class template duration. It can be specialized for a user-defined type that requires different code to create these values.

duration_values::max

static constexpr Rep max();

The static member function returns numeric_limits<Rep>::max().

When this template is specilized for a user-defined type, this value must be greater than zero().

duration_values::min

static constexpr Rep min();

The static member function returns numeric_limits<Rep>::lowest().

When this template is specilized for a user-defined type, this value must be less than or equal to zero().

duration_values::zero

static constexpr Rep zero();

The static member function returns Rep(0).

When this template is specilized for a user-defined type, this value must represent the additive identity.

high_resolution_clock


duration · is_monotonic · is_steady · now · period · rep · time_point


class high_resolution_clock
    {
    // TYPES
    typedef unspecified rep;
    typedef ratio<unspecified, unspecified> period;
    typedef chrono::duration<rep, period> duration;
    typedef chrono::time_point<high_resolution_clock> time_point;

    static const bool is_monotonic = unspecified; // retained
    static const bool is_steady = unspecified;

    // CURRENT TIME
    static time_point now() noexcept;
    };

The clock type provides a clock with a short tick period.

A clock type can be used to obtain the current time. The type embodies an instantiation of the class template chrono::duration and the class template chrono::time_point, and defines a static member function now() that returns the time. It has the following member typedefs:

A clock type has the following static data members:

A clock type has the following static member function:

A clock is monotonic if the value returned by a call to its member function now() that happens before another call to its member function now() is always less than or equal to the value returned by the second call.

A clock is steady if the value returned by a call to its member function now() that happens before another call to its member function now() is always less than or equal to the value returned by the second call, and if the time between clock ticks is constant. A steady clock is a monotonic clock.

high_resolution_clock::duration

typedef chrono::duration<rep, period> duration;

The type is a synonym for chrono::duration<rep, period>.

high_resolution_clock::is_monotonic

static const bool is_monotonic = unspecified;

The static data member holds true if the clock type is monotonic, otherwise false.

high_resolution_clock::is_steady

static const bool is_steady = unspecified;

The static data member holds true if the clock type is steady, otherwise false.

high_resolution_clock::now

static time_point now() noexcept;

The static member function returns the current time.

high_resolution_clock::period

typedef ratio<unspecified, unspecified> period;

The type is a synonym for the ratio instantiation that defines the tick period of the clock.

high_resolution_clock::rep

typedef unspecified rep;

The type is a synonym for the arithmetic type that represents the tick count in the nested type duration.

high_resolution_clock::time_point

typedef chrono::time_point<high_resolution_clock> time_point;

The type is a synonym for the time_point instantiation that now() returns.

hours

typedef chrono::duration<i23-type, ratio<3600> > hours;

The type is a synonym for a duration type with a tick period of one hour. i23-type is an implementation-specific integral type with at least 23 bits.

microseconds

typedef duration<i55-type, micro> microseconds;

The type is a synonym for a duration type with a tick period of one microsecond. i55-type is an implementation-specific integral type with at least 55 bits.

milliseconds

typedef duration<i45-type, milli> milliseconds;

The type is a synonym for a duration type with a tick period of one millisecond. i45-type is an implementation-specific integral type with at least 45 bits.

minutes

typedef duration<i29-type, ratio<60>
>minutes;

The type is a synonym for a duration type with a tick period of one minute. i29-type is an implementation-specific integral type with at least 29 bits.

monotonic_clock


duration · is_monotonic · is_steady · now · period · rep · time_point


class monotonic_clock
    {
    // TYPES
    typedef unspecified rep;
    typedef ratio<unspecified, unspecified> period;
    typedef chrono::duration<rep, period> duration;
    typedef chrono::time_point<monotonic_clock> time_point;

    static const bool is_monotonic = true;
    static const bool is_steady = unspecified;

    // CURRENT TIME
    static time_point now() noexcept;
    };

The clock type provides a monotonic clock. Implementations are not required to provide an instance of this type; if it is provided and system_clock is monotonic, it can be a synonym for system_clock.

monotonic_clock::duration

typedef chrono::duration<rep, period> duration;

The type is a synonym for chrono::duration<rep, period>.

monotonic_clock::is_monotonic

static const bool is_monotonic = true;

The static data member holds true.

monotonic_clock::is_steady

static const bool is_steady = unspecified;

The static data member holds true only if the clock is steady.

monotonic_clock::now

static time_point now() noexcept;

The static member function returns the current time.

monotonic_clock::period

typedef ratio<unspecified, unspecified> period;

The type is a synonym for the ratio instantiation that defines the tick period of the clock.

monotonic_clock::rep

typedef see below rep;

The type is a synonym for the arithmetic type that represents the tick count in the nested type duration.

monotonic_clock::time_point

typedef chrono::time_point<monotonic_clock> time_point;

The type is a synonym for the time_point instantiation that now() returns.

nanoseconds

typedef duration<i64-type, nano> nanoseconds;

The type is a synonym for a duration type with a tick period of one nanosecond. i64-type is an implementation-specific integral type with at least 64 bits.

operator%

template<class Rep1, class Period1, class Rep2>
    constexpr duration<typename common_type<Rep1, Rep2>::type, Period1>
    operator%(
        const duration<Rep1, Period1>& Dur,
        const Rep2& Div);
template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr typename common_type<Rep1, Rep2>::type
    operator%(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);

The first template function returns an object whose type is an instantiation of chrono::duration and represents a time interval whose length is the length of the time interval represented by Dur modulo Div.

The second template function returns a value that represents the time interval Left modulo the time interval Right.

Unless is_convertible<Rep2, common_type<Rep1, Rep2>> holds true, and Rep2 is not an instantiation of duration, the first template operator does not participate in overload resolution.

operator+

template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
    operator+(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Clock, class Duration1, class Rep2, class Period2>
    constexpr time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
    operator+(
        const time_point<Clock, Duration1>& Time,
        const duration<Rep2, Period2>& Dur);
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>& Dur,
        const time_point<Clock, Duration2>& Time);

The first template function returns an object that is an instantiation of chrono::duration and represents a time interval equal to the sum of the time intervals represented by its two arguments.

The second and third template functions each return an object that is an instantiation of chrono::time_point and represents a point in time that is displaced by the time interval represented by Dur from the point in time represented by Time.

operator-

template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
    operator-(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Clock, class Duration1, class Rep2, class Period2>
    constexpr time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
    operator-(
        const time_point<Clock, Duration1>& Time,
        const duration<Rep2, Period2>& Dur);
template<class Clock, class Duration1, class Duration2>
    typename common_type<Duration1, Duration2>::type
    operator-(
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);

The first template function returns an object that is an instantiation of chrono::duration and represents a time interval equal to the difference between the time intervals represented by its two arguments.

The second template function returns an object whose type is an instantiation of chrono::time_point and represents a point in time that is displaced by the negation of the time interval represented by Dur from the point in time represented by Time.

The third template function returns an object whose type is an instantiation of chrono::duration and represents the time interval between the two time points Left and Right.

operator*

template<class Rep1, class Period1, class Rep2>
    constexpr duration<typename common_type<Rep1, Rep2>::type, Period1>
    operator*(const duration<Rep1, Period1>& Dur, const Rep2& Mult);
template<class Rep1, class Rep2, class Period2>
    constexpr duration<typename common_type<Rep1, Rep2>::type, Period2>
    operator*(const Rep1& Mult, const duration<Rep2, Period2>& Dur);

The template functions each return an object whose type is an instantiation of chrono::duration and represents a time interval whose length is the length of the time interval represented by Dur multiplied by Mult.

Unless is_convertible<Rep2, common_type<Rep1, Rep2>> holds true, the first template operator does not participate in overload resolution.

Unless is_convertible<Rep1, common_type<Rep1, Rep2>> holds true, the second template operator does not participate in overload resolution.

operator/

template<class Rep1, class Period1, class Rep2>
    constexpr duration<typename common_type<Rep1, Rep2>::type, Period1>
    operator/(
        const duration<Rep1, Period1>& Dur,
        const Rep2& Div);
template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr typename common_type<Rep1, Rep2>::type
    operator/(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);

The first template function returns an object whose type is an instantiation of chrono::duration and represents a time interval whose length is the length of the time interval represented by Dur divided by Div.

The second template function returns a value that represents the ratio of the lengths of the two time intervals Left and Right.

Unless is_convertible<Rep2, common_type<Rep1, Rep2>> holds true, and Rep2 is not an instantiation of duration, the first template operator does not participate in overload resolution.

operator==

template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator==(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Clock, class Duration1, class Duration2>
    bool operator==(
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);

The first template function returns true only if its arguments represent time intervals with the same length. The second template function returns true only if its arguments represent the same point in time.

operator!=

template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator!=(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Clock, class Duration1, class Duration2>
    bool operator!=(
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);

The template functions each return !(Left == Right).

operator<

template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator< (
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Clock, class Duration1, class Duration2>
    bool operator< (
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);

The first template function returns true only if the length of the time interval represented by Left is less than the length of the time interval represented by Right. The second template function returns true only if the time point represented by Left precedes the time point represented by Right.

operator<=

template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator<=(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Clock, class Duration1, class Duration2>
    bool operator<=(
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);

The two template function each return !(Right < Left)

operator>

template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator> (
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Clock, class Duration1, class Duration2>
    bool operator> (
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);

The two template function each return Right < Left

operator>=

template<class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator>=(
        const duration<Rep1, Period1>& Left,
        const duration<Rep2, Period2>& Right);
template<class Clock, class Duration1, class Duration2>
    bool operator>=(
        const time_point<Clock, Duration1>& Left,
        const time_point<Clock, Duration2>& Right);

The two template function each return !(Left < Right)

seconds

typedef duration<i35-type> seconds;

The type is a synonym for a duration type with a tick period of one second. i35-type is an implementation-specific integral type with at least 35 bits.

steady_clock


duration · is_monotonic · is_steady · now · period · rep · time_point


class steady_clock
    {
    // TYPES
    typedef unspecified rep;
    typedef ratio<unspecified, unspecified> period;
    typedef chrono::duration<rep, period> duration;
    typedef chrono::time_point<steady_clock> time_point;

    static const bool is_monotonic = true;
    static const bool is_steady = true;

    // CURRENT TIME
    static time_point now() noexcept;
    };

The clock type provides a steady clock. Implementations are not required to provide an instance of this type; if it is provided and system_clock is steady, it can be a synonym for system_clock.

steady_clock::duration

typedef chrono::duration<rep, period> duration;

The type is a synonym for chrono::duration<rep, period>.

steady_clock::is_monotonic

static const bool is_monotonic = true;

The static data member holds true.

steady_clock::is_steady

static const bool is_steady = true;

The static data member holds true.

steady_clock::now

static time_point now() noexcept;

The static member function returns the current time.

steady_clock::period

typedef ratio<unspecified, unspecified> period;

The type is a synonym for the ratio instantiation that defines the tick period of the clock.

steady_clock::rep

typedef see below rep;

The type is a synonym for the arithmetic type that represents the tick count in the nested type duration.

steady_clock::time_point

typedef chrono::time_point<steady_clock> time_point;

The type is a synonym for the time_point instantiation that now() returns.

system_clock


duration · from_time_t · is_monotonic · is_steady · now · period · rep · time_point · to_time_t


class system_clock
    {
    // TYPES
    typedef unspecified rep;
    typedef ratio<unspecified, unspecified> period;
    typedef chrono::duration<rep, period> duration;
    typedef chrono::time_point<system_clock> time_point;

    static const bool is_monotonic = unspecified;
    static const bool is_steady = unspecified;

    // CURRENT TIME
    static time_point now() noexcept;

    // CONVERSIONS WITH time_t
    static time_t to_time_t(const time_point& t) noexcept;
    static time_point from_time_t(time_t t) noexcept;
    };

The clock type provides a clock based on the system's realtime clock.

system_clock::duration

typedef chrono::duration<rep, period> duration;

The type is a synonym for chrono::duration<rep, period>.

system_clock::from_time_t

static time_point from_time_t(time_t t) noexcept;

The static member function returns the object of type time_point that most nearly approximates the time represented by t.

system_clock::is_monotonic

static const bool is_monotonic = unspecified;

The static data member holds true only if the clock type is monotonic.

system_clock::is_steady

static const bool is_steady = unspecified;

The static data member holds true only if the clock type is steady.

system_clock::now

static time_point now() noexcept;

The static member function returns the current time.

system_clock::period

typedef ratio<unspecified, unspecified> period;

The type is a synonym for the ratio instantiation that defines the tick period of the clock.

system_clock::rep

typedef unspecified rep;

The type is a synonym for the arithmetic type that represents the tick count in the nested type duration.

system_clock::time_point

typedef chrono::time_point<system_clock> time_point;

The type is a synonym for the time_point instantiation that now() returns.

system_clock::to_time_t

static time_t to_time_t(const time_point& t) noexcept;

The static member function returns the object of type time_t that most nearly approximates the time represented by t.

time_point


clock · duration · max · min · operator+= · operator-= · period · rep · time_point · time_since_epoch


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;

    // CONSTRUCTORS
    time_point();
    explicit time_point(const duration& Dur);
    template<class Duration2>
        time_point(const time_point<clock, Duration2>& Tp);

    // OBSERVERS
    duration time_since_epoch() const;

    // ARITHMETIC OPERATIONS
    time_point& operator+=(const duration& Dur);
    time_point& operator-=(const duration& Dur);

    // SPECIAL VALUES
    static constexpr time_point min();
    static constexpr time_point max();
    };

The template class describes a type that represents a point in time. It holds an object of type duration that stores the elapsed time since the epoch represented by the template argument Clock.

time_point::clock

typedef Clock clock;

The type is a synonym for the template parameter Clock.

time_point::duration

typedef Duration duration;

The type is a synonym for the template parameter Duration.

time_point::max

static constexpr time_point max();

The static member function returns time_point(duration::max()).

time_point::min

static constexpr time_point min();

The static member function returns time_point(duration::min()).

time_point::operator+=

time_point& operator+=(const duration& Dur);

The operator adds Dur to the stored duration value and returns *this.

time_point::operator-=

time_point& operator-=(const duration& Dur);

The operator subtracts Dur from the stored duration value and returns *this.

time_point::period

typedef typename duration::period period;

The type is a synonym for the nested type name duration::period.

time_point::rep

typedef typename duration::rep rep;

The type is a synonym for the nested type name duration::rep.

time_point::time_point

time_point();
explicit time_point(const duration& Dur);
template<class Duration2>
    time_point(const time_point<clock, Duration2>& Tp);

The first constructor constructs an object whose stored duration value is equal to duration::zero().

The second constructor constructs an object whose stored duration value is equal to Dur.

Unless is_convertible<Duration2, duration> holds true the second constructor does not participate in overload resolution.

The third constructor constructs an object whose stored duration value is initialized with Tp.time_since_epoch().

time_point::time_since_epoch

duration time_since_epoch() const;

The member function returns the stored duration value.

time_point_cast

template<class To, class Clock, class Duration>
    time_point<Clock, To> time_point_cast(const time_point<Clock, Duration>& Tp);

The template function returns time_point<Clock, To>(duration_cast<To>(Tp.time_since_epoch())).

Unless To is an instantiation of duration, the template function does not participate in overload resolution.

treat_as_floating_point

template<class Rep>
    struct treat_as_floating_point
        : is_floating_point<Rep> { };

The template parameter Rep can be treated as a floating-point type only when the specialization treat_as_floating_point<Rep> is derived from true_type. The template class can be specialized for a user-defined type.


See also the Table of Contents and the Index.

Copyright © 1992-2013 by P.J. Plauger. All rights reserved.