【发布时间】:2018-05-21 02:56:37
【问题描述】:
我注意到std::chrono::high_resolution_clock::period::num = 1 用于我测试过的每个系统。是否存在任何恰好是其他数字的系统(嵌入式、桌面、移动或其他)? (在这样的系统上,1 秒无法以刻度表示。)
【问题讨论】:
我注意到std::chrono::high_resolution_clock::period::num = 1 用于我测试过的每个系统。是否存在任何恰好是其他数字的系统(嵌入式、桌面、移动或其他)? (在这样的系统上,1 秒无法以刻度表示。)
【问题讨论】:
我知道std::chrono::high_resolution_clock 的三种实现方式:Visual Studio、gcc 和 clang(与 libc++ 一起使用时)。
这三个都具有纳秒精度 (std::chrono::high_resolution_clock::period::num = 1)。对于 VS 和 libc++,high_resolution_clock 的类型别名为 steady_clock。在 gcc 上,它的类型别名为 system_clock。
规范中没有任何内容阻止std::chrono::high_resolution_clock::period::num != 1,您说得对,在这样的系统上,1 秒不能用“滴答声”表示。这进一步转化为:
seconds不会隐式转换为high_resolution_clock::duration。
要找到seconds 和high_resolution_clock::duration 都可以转换到的最粗略持续时间,您可以便携地使用:
using CT = common_type_t<seconds, high_resolution_clock::duration>;
对于我知道的所有实现,CT 是 nanoseconds 的类型别名。
【讨论】: