名前空間
変種
操作

operator+,-,*,/,%(std::chrono::duration)

提供: cppreference.com
< cpp‎ | chrono‎ | duration

 
 
ユーティリティライブラリ
支援を入力します (basic types, RTTI, type traits)
動的なメモリ管理
エラー処理
プログラムユーティリティ
可変個引数関数
日付と時刻
関数オブジェクト
initializer_list(C++11)
bitset
hash(C++11)
関係演算子
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
ペアとタプル
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
フォワード、スワップ、および移動
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
 
std::chrono::duration
メンバ関数
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
duration::duration
duration::operator=
duration::count
duration::zero
duration::min
duration::max
duration::operator+
duration::operator-
duration::operator++
duration::operator--
duration::operator+=
duration::operator-=
duration::operator*=
duration::operator/=
duration::operator%=
非メンバ関数
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
common_type
operator+
operator-
operator*
operator/
operator%
operator==
operator!=
operator<
operator<=
operator>
operator>=
duration_cast
ヘルパークラス
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
treat_as_floating_point
duration_values
 
template< class Rep1, class Period1, class Rep2, class Period2 >

typename std::common_type<duration<Rep1,Period1>, duration<Rep2,Period2>>::type
    constexpr operator+( const duration<Rep1,Period1>& lhs,

                         const duration<Rep2,Period2>& rhs );
(1)
template< class Rep1, class Period1, class Rep2, class Period2 >

typename std::common_type<duration<Rep1,Period1>, duration<Rep2,Period2>>::type
    constexpr operator-( const duration<Rep1,Period1>& lhs,

                         const duration<Rep2,Period2>& rhs );
(2)
template< class Rep1, class Period, class Rep2 >

duration<typename std::common_type<Rep1,Rep2>::type, Period>
    constexpr operator*( const duration<Rep1,Period>& d,

                         const Rep2& s );
(3)
template< class Rep1, class Rep2, class Period >

duration<typename std::common_type<Rep1,Rep2>::type, Period>
    constexpr operator*( const Rep1& s,

                         const duration<Rep2,Period>& d );
(4)
template< class Rep1, class Period, class Rep2 >

duration<typename common_type<Rep1,Rep2>::type, Period>
    constexpr operator/( const duration<Rep1,Period>& d,

                         const Rep2& s );
(5)
template< class Rep1, class Period1, class Rep2, class Period2 >

typename std::common_type<Rep1,Rep2>::type
    constexpr operator/( const duration<Rep1,Period1>& lhs,

                         const duration<Rep2,Period2>& rhs );
(6)
template< class Rep1, class Period, class Rep2 >

duration<typename common_type<Rep1,Rep2>::type, Period>
    constexpr operator%( const duration<Rep1, Period>& d,

                         const Rep2& s );
(7)
template< class Rep1, class Period1, class Rep2, class Period2 >

typename common_type<duration<Rep1,Period1>, duration<Rep2,Period2>>::type
constexpr operator%( const duration<Rep1,Period1>& lhs,

                     const duration<Rep2,Period2>& rhs );
(8)
2期間の間、または期間およびティック数との間に基本的な算術演算を実行します.
Original:
Performs basic arithmetic operations between two durations or between a duration and a tick count.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
彼らの共通の型に2期間に変換し、その変換後のティックカウントティック数の合計である期間を作成.
Original:
Converts the two durations to their common type and creates a duration whose tick count is the sum of the tick counts after conversion.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
彼らの共通の型に2期間に変換し、その変換後のダニのカウント刻みのrhs番号から差し引かティックのlhs番号である期間を作成.
Original:
Converts the two durations to their common type and creates a duration whose tick count is the rhs number of ticks subtracted from the lhs number of ticks after conversion.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3-4)
そのdrepによる変換後の刻みの数Rep1Rep2、と倍数の間の一般的なタイプである1に期間sを変換.
Original:
Converts the duration d to one whose rep is the common type between Rep1 and Rep2, and multiples the number of ticks after conversion by s.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5)
そのdrepRep1間の一般的なタイプであり、Rep2による変換後の刻みの数を分割つに期間sに変換します
Original:
Converts the duration d to one whose rep is the common type between Rep1 and Rep2, and divides the number of ticks after conversion by s
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
彼らの共通の型に2期間に変換し、変換後のlhsのティック数で変換後rhsのティック数を分割します。この演算子の戻り値が持続しないことに注意してください.
Original:
Converts the two durations to their common type and divides the tick count of lhs after conversion by the tick count of rhs after conversion. Note that the return value of this operator is not a duration.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
7)
そのdrepRep1間の一般的なタイプである1に期間Rep2変換し、sによって、そのダニ数変換した後、ティック数の除算の余りである期間を作成.
Original:
Converts the duration 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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
8)
彼らの共通の型に2期間に変換し、その変換後のティックカウントティック数の剰余である期間を作成.
Original:
Converts the two durations to their common type and creates a duration whose tick count is the remainder of the tick counts after conversion.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] パラメータ

lhs -
演算子の左側にある期間
Original:
duration on the left-hand side of the operator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rhs -
演算子の右側にある期間
Original:
duration on the right-hand side of the operator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
d -
混合された引数の演算子のduration引数
Original:
the duration argument for mixed-argument operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
s -
混在した引数の演算子の引数を数えるカチカチ
Original:
tick count argument for mixed-argument operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

その後、CDは、関数の戻り値の型とCR<A, B> = std::common_type<A, B>::typeであると仮定すると:
Original:
Assuming that CD is the function return type and CR<A, B> = std::common_type<A, B>::type, then:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1) CD(CD(lhs).count() + CD(rhs).count())
2) CD(CD(lhs).count() - CD(rhs).count())
3-4) CD(CD(d).count() * s)
5) CD(CD(d).count() / s).
6)
CD(lhs).count() / CD(rhs).count()(この演算子の戻り値の型は期間ではありません)
Original:
CD(lhs).count() / CD(rhs).count() (the return type of this operator is not a duration)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
7) CD(CD(d).count() % s)
8) CD(CD(lhs).count() % CD(rhs).count())


[編集]

#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";
}

Output:

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