operator+,-,*,/,%(std::chrono::duration)
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 std::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 std::common_type<Rep1,Rep2>::type, Period> |
(7) | |
template< class Rep1, class Period1, class Rep2, class Period2 > typename std::common_type<duration<Rep1,Period1>, duration<Rep2,Period2>>::type |
(8) | |
2つの duration の間で、または duration と刻み数の間で、基本的な算術演算を行います。
rhs
の刻み数から lhs
の刻み数を引いた刻み数を持つ duartion を作成します。Rep1
と Rep2
の共通型である rep
を持つ duration に d
を変換し、その変換後の刻み数に s
を掛けます。Rep1
と Rep2
の共通型である rep
を持つ duration に d
を変換し、その変換後の刻み数を s
で割ります。lhs
の刻み数を rhs
の刻み数で割ります。 この演算子の戻り値は duration でないことに注意してください。Rep1
と Rep2
の共通型である rep
を持つ duration に d
を変換し、その変換後の刻み数を s
で割った余りの刻み数を持つ duration を作成します。This section is incomplete Reason: list the "does not participate in overload resolution unless" constraints |
[編集] 引数
lhs | - | 演算子の左側の duration |
rhs | - | 演算子の右側の duration |
d | - | 混合した引数の演算子に対する duration 引数 |
s | - | 混合した引数の演算子に対する刻み数の引数 |
[編集] 戻り値
CD が関数の戻り値の型で CR<A, B> = std::common_type<A, B>::type であるとすると、
[編集] 例
#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() << " seconds\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 seconds 4807 seconds is 1 hours, 20 minutes, 7 seconds