C++11

当前头文件是通用工具库(Diagnostics library)中的 日期与时间功能组件 主题中的部分内容。

​通用工具库(参考手册) ​通用工具库(标准)

  • 包含在名称空间 std::chrono 中的内容:

    duration C++11 时间间隔
    system_clock C++11 系统范畴的实时挂钟(System-wide real time wall clock)
    steady_clock C++11 稳定时钟,即单调时钟(Monotonic clock),不能被设置
    high_resolution_clock C++11 能够提供的最短嘀嗒周期的时钟
    time_point C++11 时间点
    treat_as_floating_point 检测时间间隔是否可以被转化为另一个不同嘀嗒周期(Tick period)的时间间隔
    duration_values 由给定类型的嘀嗒数(Tick count)的零值、最小值及最大值组成的结构体

    typedef

    包含在名称空间 std::chrono 中的内容:

    nanoseconds 周期为 std::nano 的时间间隔
    microseconds 周期为 std::micro 的时间间隔
    milliseconds 周期为 std::milli 的时间间隔
    seconds 周期为 std::ratio<1> 的时间间隔
    minutes 周期为 std::ratio<60> 的时间间隔
    hours 周期为 std::ratio<3600> 的时间间隔

    特例化

    std::common_type<std::chrono::duration> std::common_type 对 std::chrono::duration 的特例化
    std::common_type<std::chrono::time_point>  std::common_type 对 std::chrono::time_point 的特例化
  • 时间间隔

    operator+
    operator-
    operator*
    operator/
    operator%
    实现了以两个时间间隔为参数的算述操作
    operator==
    operator!=
    operator<
    operator<=
    operator>
    operator>=
    比较两个时间间隔
    duration_cast 将一个时间间隔转化为另一个不同嘀嗒周期(Tick period)的时间间隔

    时间点

    operator+
    operator-
    用给定的时间间隔(Duration)修改时间点
    operator==
    operator!=
    operator<
    operator<=
    operator>
    operator>=
    比较两个时间点
    time_point_cast 将一个时间点转化成另一个有相同时钟值,但时间间隔不同的时间点
  • namespace std {
    namespace chrono {
     
        // class template duration
        template <class Rep, class Period = ratio<1> > class duration;
     
        // class template time_point
        template <class Clock, class Duration = typename Clock::duration> class time_point;
     
    } // 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 chrono {
     
        // customization traits
        template <class Rep> struct treat_as_floating_point;
        template <class Rep> struct duration_values;
     
        // duration arithmetic
        template <class Rep1, class Period1, class Rep2, class Period2>
            typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
            constexpr operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
        template <class Rep1, class Period1, class Rep2, class Period2>
            typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
            constexpr operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
        template <class Rep1, class Period, class Rep2>
            duration<typename common_type<Rep1, Rep2>::type, Period>
            constexpr operator*(const duration<Rep1, Period>& d, const Rep2& s);
        template <class Rep1, class Rep2, class Period>
            duration<typename common_type<Rep1, Rep2>::type, Period>
            constexpr operator*(const Rep1& s, const duration<Rep2, Period>& d);
        template <class Rep1, class Period, class Rep2>
            duration<typename common_type<Rep1, Rep2>::type, Period>
            constexpr operator/(const duration<Rep1, Period>& d, const Rep2& s);
        template <class Rep1, class Period1, class Rep2, class Period2>
            typename common_type<Rep1, Rep2>::type
            constexpr operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
        template <class Rep1, class Period, class Rep2>
            duration<typename common_type<Rep1, Rep2>::type, Period>
            constexpr operator%(const duration<Rep1, Period>& d, const Rep2& s);
        template <class Rep1, class Period1, class Rep2, class Period2>
            typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
            constexpr operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
     
        // duration comparisons
        template <class Rep1, class Period1, class Rep2, class Period2>
            constexpr bool operator==(const duration<Rep1, Period1>& lhs,
                                        const duration<Rep2, Period2>& rhs);
        template <class Rep1, class Period1, class Rep2, class Period2>
            constexpr bool operator!=(const duration<Rep1, Period1>& lhs,
                                        const duration<Rep2, Period2>& rhs);
        template <class Rep1, class Period1, class Rep2, class Period2>
            constexpr bool operator< (const duration<Rep1, Period1>& lhs,
                                        const duration<Rep2, Period2>& rhs);
        template <class Rep1, class Period1, class Rep2, class Period2>
            constexpr bool operator<=(const duration<Rep1, Period1>& lhs,
                                        const duration<Rep2, Period2>& rhs);
        template <class Rep1, class Period1, class Rep2, class Period2>
            constexpr bool operator> (const duration<Rep1, Period1>& lhs,
                                        const duration<Rep2, Period2>& rhs);
        template <class Rep1, class Period1, class Rep2, class Period2>
            constexpr bool operator>=(const duration<Rep1, Period1>& lhs,
                                        const duration<Rep2, Period2>& rhs);
     
        // duration_cast 
        template <class ToDuration, class Rep, class Period> 
            constexpr ToDuration duration_cast(const duration<Rep, Period>& d); 
     
        // convenience typedefs 
        typedef duration</*signed integer type of at least 64 bits*/, nano>        nanoseconds;
        typedef duration</*signed integer type of at least 55 bits*/, micro>       microseconds;
        typedef duration</*signed integer type of at least 45 bits*/, milli>       milliseconds;
        typedef duration</*signed integer type of at least 35 bits*/ >             seconds;
        typedef duration</*signed integer type of at least 29 bits*/, ratio< 60>>  minutes; 
        typedef duration</*signed integer type of at least 23 bits*/, ratio<3600>> hours; 
     
        // 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>& 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);
     
        // time_point comparisons
        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);
     
        // time_point_cast
        template <class ToDuration, class Clock, class Duration>
            time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
     
        // clocks
        class system_clock;
        class steady_clock;
        class high_resolution_clock;
     
    } // namespace chrono
    }// namespace std