operator+,-,*,/,%(std::chrono::duration)
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
template< class Rep1, class Period1, class Rep2, class Period2 > typename std::common_type<duration<Rep1,Period1>, duration<Rep2,Period2>>::type |
(1) | |
template< class Rep1, class Period1, class Rep2, class Period2 > typename std::common_type<duration<Rep1,Period1>, duration<Rep2,Period2>>::type |
(2) | |
template< class Rep1, class Period, class Rep2 > duration<typename std::common_type<Rep1,Rep2>::type, Period> |
(3) | |
template< class Rep1, class Rep2, class Period > duration<typename std::common_type<Rep1,Rep2>::type, Period> |
(4) | |
template< class Rep1, class Period, class Rep2 > duration<typename common_type<Rep1,Rep2>::type, Period> |
(5) | |
template< class Rep1, class Period1, class Rep2, class Period2 > typename std::common_type<Rep1,Rep2>::type |
(6) | |
template< class Rep1, class Period, class Rep2 > duration<typename common_type<Rep1,Rep2>::type, Period> |
(7) | |
template< class Rep1, class Period1, class Rep2, class Period2 > typename common_type<duration<Rep1,Period1>, duration<Rep2,Period2>>::type |
(8) | |
rhs
的蜱数量减去lhs
数转换后的滴答滴答计数的时间.rhs
number of ticks subtracted from the lhs
number of ticks after conversion.d
rep
Rep1
和Rep2
,倍数是常见的类型转换后的滴答s
.d
to one whose rep
is the common type between Rep1
and Rep2
, and multiples the number of ticks after conversion by s
.d
的rep
是常见的类型之间Rep1
Rep2
,划分的刻度数转换后的s
d
to one whose rep
is the common type between Rep1
and Rep2
, and divides the number of ticks after conversion by s
lhs
转换后的时钟周期数转换后的rhs
分的滴答计数。请注意,这个操作符的返回值是一个时间.lhs
after conversion by the tick count of rhs
after conversion. Note that the return value of this operator is not a duration.d
的rep
是常见的类型之间Rep1
Rep2
,并创建一个时间的时钟周期数是其余的滴答计数的划分,转换后,s
.d
to one whose rep
is the common type between Rep1
and Rep2
, and creates a duration whose tick count is the remainder of the division of the tick count, after conversion, by s
.[编辑] 参数
lhs | - | 的持续时间对操作者的左手侧
原文: duration on the left-hand side of the operator |
rhs | - | 的持续时间对操作者的右手侧的
原文: duration on the right-hand side of the operator |
d | - | 混合参数运营商的持续时间参数
原文: the duration argument for mixed-argument operators |
s | - | 滴答计数参数混合参数运营商
原文: tick count argument for mixed-argument operators |
[编辑] 返回值
[编辑] 示例
#include <chrono> #include <iostream> int main() { // simple arithmetic std::chrono::seconds s = std::chrono::hours(1) + 2*std::chrono::minutes(10) + std::chrono::seconds(70)/10; std::cout << "1 hour + 2*10 min + 70/10 sec = " << s.count() << " seconds\n"; // difference between dividing a duration by a number // and dividing a duration by another duration std::cout << "Dividing that by 2 minutes gives " << s / std::chrono::minutes(2) << '\n'; std::cout << "Dividing that by 2 gives " << (s / 2).count() << " sconds\n"; // the remainder operator is useful in determining where in a time // frame is this particular duration, e.g. to break it down into hours, // minutes, and seconds: std::cout << s.count() << " seconds is " << std::chrono::duration_cast<std::chrono::hours>( s ).count() << " hours, " << std::chrono::duration_cast<std::chrono::minutes>( s % std::chrono::hours(1) ).count() << " minutes, " << std::chrono::duration_cast<std::chrono::seconds>( s % std::chrono::minutes(1) ).count() << " seconds\n"; }
输出:
1 hour + 2*10 min + 70/10 sec = 4807 seconds Dividing that by 2 minutes gives 40 Dividing that by 2 gives 2403 sconds 4807 seconds is 1 hours, 20 minutes, 7 seconds