特定于平台的 std::chrono::high_resolution_clock::period::num [英] platform-specific std::chrono::high_resolution_clock::period::num
问题描述
我注意到对于我测试过的每个系统,std::chrono::high_resolution_clock::period::num = 1
.是否存在任何系统(嵌入式、桌面、移动或其他)恰好是其他数字?(在这样的系统上,1 秒不能用刻度表示.)
I've noticed that std::chrono::high_resolution_clock::period::num = 1
for every system I've tested. Does there exist any system (embedded, desktop, mobile, or otherwise) where it happens to be some other number? (On such a system, 1 second would not be representable in ticks.)
推荐答案
我知道 std::chrono::high_resolution_clock
的三种实现:Visual Studio、gcc 和 clang(当与 libc++ 一起使用).
There are three implementations of std::chrono::high_resolution_clock
that I am aware of: Visual Studio, gcc and clang (when used with libc++).
所有这三个都具有纳秒精度(std::chrono::high_resolution_clock::period::num = 1
).对于 VS 和 libc++,high_resolution_clock
被类型别名为 steady_clock
.在 gcc 上,它被类型别名为 system_clock
.
All three of these have nanosecond-precision (std::chrono::high_resolution_clock::period::num = 1
). For VS and libc++, high_resolution_clock
is type-aliased to steady_clock
. On gcc it is type-aliased to system_clock
.
规范中没有任何内容可以阻止 std::chrono::high_resolution_clock::period::num != 1
,您是对的,在这样的系统上 1 秒是无法表示的在滴答声"中.这进一步转化为:
There is nothing in the spec that prevents std::chrono::high_resolution_clock::period::num != 1
, and you are correct that on such a system 1 second would not be representable in "ticks". This further translates to:
seconds
不会隐式转换为 high_resolution_clock::duration
.
要找到 seconds
和 high_resolution_clock::duration
可转换为的最粗略持续时间,您可以使用:
To find the coarsest duration to which both seconds
and high_resolution_clock::duration
are convertible to, you can portably use:
using CT = common_type_t<seconds, high_resolution_clock::duration>;
对于我所知道的所有实现,CT
是 nanoseconds
的类型别名.
For all of the implementations I'm aware of, CT
is a type-alias for nanoseconds
.
这篇关于特定于平台的 std::chrono::high_resolution_clock::period::num的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!