std::chrono::time_point<Clock,Duration>::min
< cpp | chrono | time point
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