std::chrono::time_point<Clock,Duration>::min
来自 cppreference.com
static constexpr time_point min(); |
(直到 C++20) | |
static constexpr time_point min() noexcept; |
(自 C++20) | |
返回具有最小可能持续时间的 time_point
,即 time_point(duration::min()).
[编辑] 参数
(无)
[编辑] 返回值
最小的 time_point
。
[编辑] 示例
运行此代码
#include <chrono> #include <iomanip> #include <iostream> #include <ratio> #include <string> constexpr auto steady_min = std::chrono::steady_clock::time_point::min(); void animate_frame_at_time_offset(double game_time) { std::cout << std::string(static_cast<int>(game_time) % 10 + 1, '*') << '\n'; } int main() { auto last_frame = steady_min; std::chrono::duration<double, std::micro> game_time{0.0}; for (int n = 0; n < 5; ++n) { const auto current_frame = std::chrono::steady_clock::now(); // initialize timer if first frame ever: if (last_frame == steady_min) last_frame = current_frame; game_time += current_frame - last_frame; std::cout << "Drawing frame at " << std::setprecision(10) << std::setw(8) << game_time.count() << " μs "; animate_frame_at_time_offset(game_time.count()); } }
可能的输出
Drawing frame at 0 μs * Drawing frame at 134.499 μs ***** Drawing frame at 274.337 μs ***** Drawing frame at 416.571 μs ******* Drawing frame at 561.124 μs **