定义于头文件
<chrono>
|
||
template <class ToDuration, class Clock, class Duration>
constexpr time_point<Clock, ToDuration> round(const time_point<Clock, Duration>& tp); |
(C++17 起) | |
返回能以 ToDuration
表示的最接近 tp
的时间点,中点情况下向偶数舍入。
函数不参与重载决议,除非 ToDuration
是 std::chrono::duration 的特化且 std::chrono::treat_as_floating_point<typename ToDuration::rep>::value 为 false 。
目录 |
tp | - | 要舍入到最近值的 time_point |
舍入到使用 ToDuration
类型时长的最近时间点的 tp
,中点情况下向偶数舍入。
template <class T> struct is_duration : std::false_type {}; template <class Rep, class Period> struct is_duration< std::chrono::duration<Rep, Period>> : std::true_type {}; template <class To, class Clock, class FromDuration, class = std::enable_if_t<is_duration<To>{} && !std::chrono::treat_as_floating_point<typename To::rep>{}>> constexpr std::chrono::time_point<Clock, To> round( const std::chrono::time_point<Clock, FromDuration>& tp) { return std::chrono::time_point<Clock, To>{ std::chrono::round<To>(tp.time_since_epoch())}; } |
本节未完成 原因:暂无示例 |
转换 time_point 为同一时钟上拥有不同 duration 的另一 time_point (函数模板) |
|
(C++17)
|
转换 time_point 到另一个,向上取整 (函数模板) |
(C++17)
|
转换 time_point 到另一个,向下取整 (函数模板) |
(C++17)
|
转换 duration 到另一个,就近取整,倾向偶数 (函数模板) |
(C++11)
(C++11) (C++11) |
最接近整数,中间情况下舍入到远离零 (函数) |