在线文档教程
C++
应用 | Utilities

std::chrono::round(std::chrono::duration)

Std::Time::整数%28 std::time::工期%29

Defined in header
template <class ToDuration, class Rep, class Period> constexpr ToDuration round(const duration<Rep, Period>& d(since C++17)

返回值t可在ToDuration这是最接近d如果有两个这样的值,则返回偶数%28,即值t使...t % 2 == 029%。

该函数不参与重载解析,除非ToDuration是std::chrono::duration和std::chrono::treat_as_floating_point<typename ToDuration::rep>::value是false...

参数

d-duration to convert

返回值

d四舍五入至最接近类型的持续时间ToDuration甚至在半途而废的情况下。

可能的实施

模板<class T>结构是[医]持续时间:STD::false[医]类型{};模板<类Rep,类周期>结构是[医]持续时间<std::time::time<rep,time>>:std::true[医]类型{};模板<class到类,类Rep,类周期,class=std::Enable[医]如果[医]T<IS[医]持续时间<To>{}&%21 std::rono::[医]如[医]浮[医]点<typename To::rep>{}>>Conexpr to整数%28 const std::chrono::time<rep,期>&d%29{to 0=std::chrono::time:<To>%28d%29;to t1=t0+to{1};自动扩散0=d-t0;自扩散1=t1-d;if%28Diff0==dc 1%29{if%28t0.计数%28%29和1%29返回T1;返回t0;

*。

另见

duration_castconverts a duration to another, with a different tick interval (function template)
floor(std::chrono::duration) (C++17)converts a duration to another, rounding down (function template)
ceil(std::chrono::duration) (C++17)converts a duration to another, rounding up (function template)
round(std::chrono::time_point) (C++17)converts a time_point to another, rounding to nearest, ties to even (function template)
roundlroundllround (C++11)(C++11)(C++11)nearest integer, rounding away from zero in halfway cases (function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/rono/time/圆形