c++ - 特定于平台的 std::chrono::high_resolution_clock::period::num

标签 c++ time std

我注意到对于我测试过的每个系统,std::chrono::high_treatment_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_treatment_clock::period::num != 1,并且您是正确的,在这样的系统上 1 秒无法表示在“蜱”中。这进一步转化为:

seconds would not be implicitly convertible to high_resolution_clock::duration.

要找到high_resolution_clock::duration可转换的最粗略持续时间,您可以方便地使用:

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

对于我所知道的所有实现,CT纳秒 的类型别名。

关于c++ - 特定于平台的 std::chrono::high_resolution_clock::period::num,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47687645/

相关文章:

c# - 等价于 C# 中的 yield

c++ - 用VS2008编译的C++应用程序在其他电脑上运行不起来

c++ - 当算法需要零秒/毫秒时间时,如何获得近似时间?

c++ - 将 std::string 的 c_str() 结果分配给标准保证安全的同一个 std::string?

c++ - 如何从新插入的对(到 map )返回引用对?

c++ - 无限模板递归,因为仅使用 gcc 没有 bool 表达式优化

c++ - Android设备 radio ROM编程

安卓 : Time milliseconds to X day - X hours - x Minute - X seconds left

Java 到 Oracle - 要使用的正确日期格式

c++ 为什么 std::multimap 比 std::priority_queue 慢