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

来自cppreference.com
< cpp‎ | chrono‎ | time point
 
 
 
日期和时间工具
(C++11)
(C++11)
时钟
(C++20)
                                                  
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
日历
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
时区
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
C 风格日期和时间
 
 
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