如何将包含微秒量的intmax_t转换为适当的std :: chrono :: duration变量?

时间:2017-11-19 10:34:32

标签: c++11 std chrono

如何将包含微秒数的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 ???????? */

1 个答案:

答案 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