C++标准库扩展与定制:时间、复数、大整数及随机数的深入探索
1. 为 <chrono>
的高分辨率时钟提供 now()
函数
C++标准库在 <chrono>
库中支持时间计时功能,其中包含系统时钟和高分辨率时钟等多种时钟。高分辨率时钟 std::chrono::high_resolution_clock
适合在实时C++项目中提供时基。
以下是 std::chrono::high_resolution_clock
的可能概要:
namespace std { namespace chrono {
class high_resolution_clock
{
public:
// 时钟的分辨率为微秒。
typedef chrono::microseconds duration;
// 表示、周期和时间点的类型。
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<high_resolution_clock,
duration> time_point;
// 计数器是稳定的。这意味着
// 调用now()总是返回比前一次调用更晚的时间。
static constexpr bool is_ste