std::chrono::time_point<Clock,Duration>::min

来自cppreference.com
< cpp‎ | chrono‎ | time point
 
 
工具库
通用工具
格式化库 (C++20)
(C++11)
关系运算符 (C++20 中弃用)
整数比较函数
(C++20)(C++20)(C++20)
(C++20)
swap 与类型运算
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
常用词汇类型
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)

初等字符串转换
(C++17)
(C++17)
栈踪
 
 
 
static constexpr time_point min();
(C++20 前)
static constexpr time_point min() noexcept;
(C++20 起)

返回拥有最小可能时长的 time_point ,即 time_point(std::chrono::duration::min())

参数

(无)

返回值

最小的可能的 time_point

示例

#include <iostream>
#include <ratio>
#include <chrono>
 
constexpr auto steady_min = std::chrono::steady_clock::time_point::min();
 
int main()
{
    auto last_frame = steady_min;
    std::chrono::duration<float, std::milli> game_time {0.0F};
 
    for (std::size_t count = 0; count < 5; ++count) {
        auto current_frame = std::chrono::steady_clock::now();
        // 若是首帧则初始化计时器:
        if (last_frame == steady_min)
            last_frame = current_frame;
        game_time += current_frame - last_frame;
        std::cout << "Drawing frame at " << game_time.count() << " ms\n";
        // 在时间偏移 game_time 绘制帧……
    }
}

可能的输出:

Drawing frame at 0 ms
Drawing frame at 0.17551 ms
Drawing frame at 0.358325 ms
Drawing frame at 0.545384 ms
Drawing frame at 0.736717 ms