名前空間
変種
操作

std::chrono::duration_cast

提供: 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 ToDuration, class Rep, class Period>
constexpr ToDuration duration_cast(const duration<Rep,Period>& d);
(C + + 11以来)
異なるタイプのstd::chrono::durationの期間にToDurationを変換.
Original:
Converts a std::chrono::duration to a duration of different type ToDuration.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
暗黙的な変換は使用されません。可能であれば、それが1つ以上のパラメータが1あることをコンパイル時にわかっている場合は乗算と除算は、回避される。計算が可能な広いタイプで行われ、終了結果のみ·タイプに変換されます.
Original:
No implicit conversions are used. Multiplications and divisions are avoided where possible, if it is known at compile time that one or more parameters are 1. Computations are done in the widest type available and converted to the result type only when finished.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

d -
変換する期間
Original:
duration to convert
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

dタイプToDurationの期間に変換.
Original:
d converted to a duration of type ToDuration.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] ノート

ToDurationstd::chrono::durationのインスタンスでない限り、この関数はオーバーロードの解決に参加しません.
Original:
The function does not participate in the overload resolution unless ToDuration is an instance of std::chrono::duration.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
浮動小数点の期間の間、またはソースの期間が対象期間(分例えば時間)で割り切れる整数である期間の間にキャスティングが暗黙のうちに行うことができ、何duration_castは必要ありません.
Original:
Casting between floating-point durations or between integer durations where the source period is exactly divisible by the target period (e.g. hours to minutes) can be performed 暗黙のうちに, no duration_cast is needed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

この例では、関数の実行時間を測定します
Original:
This example measures the execution time of a function
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <chrono>
#include <thread>
 
void f()
{
    std::this_thread::sleep_for(std::chrono::seconds(1));
}
 
int main()
{
    auto t1 = std::chrono::high_resolution_clock::now();
    f();
    auto t2 = std::chrono::high_resolution_clock::now();
    std::cout << "f() took "
              << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
              << " milliseconds\n";
}

Output:

f() took 1000 milliseconds