如何将包含微秒数的intmax_t
转换为适当的std::chrono::duration
变量?
更具体地说,
...
intmax_t myUsInterval = 10000000LL; /* my desirable interval is 10s in us units */
std::chrono::duration<std::intmax_t, std::micro> timeout; /* I want to get timeout variable to use it in std::chrono library */
/* How can I: timeout <- myUsInterval ???????? */
答案 0 :(得分:1)
std::chrono::microseconds timeout{myUsInterval};
或者如果你真的想要intmax_t
代表(在这个例子中不需要):
std::chrono::duration<std::intmax_t, std::micro> timeout{myUsInterval};
有关<chrono>
的视频教程,请参阅:CppCon 2016: Howard Hinnant “A <chrono> Tutorial" on YouTube