平台特定的std :: chrono :: high_resolution_clock :: ofence :: num

platform-specific std::chrono::high_resolution_clock::period::num

本文关键字:resolution clock num ofence high chrono std 平台      更新时间:2023-10-16

我已经注意到我测试过的每个系统的std::chrono::high_resolution_clock::period::num = 1。是否存在任何系统(嵌入式,桌面,移动设备或其他)的系统?(在这样的系统上,1秒钟在tick中无法表示。)

我知道的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秒钟在" ticks"中无法表示。这进一步转化为:

seconds不会隐式转换为high_resolution_clock::duration

要找到secondshigh_resolution_clock::duration都可以转换到的最高持续时间,您可以便便使用:

using CT = common_type_t<seconds, high_resolution_clock::duration>;

对于我所知道的所有实现,CTnanoseconds的类型 - ALIAS。