std::common_type<std::chrono::duration>
From cppreference.com
| ヘッダー <chrono> で定義 |
||
| template< class Rep1, class Period1, class Rep2, class Period2 > struct common_type<std::chrono::duration<Rep1, Period1>, |
(C++11以降) | |
type という名前の型を公開します。これは、2つの std::chrono::duration の共通型であり、その期間は Period1 と Period2 の最大公約数です。
目次 |
[編集] メンバ型
| メンバ型 | 定義 |
type
|
std::chrono::duration<typename std::common_type<Rep1, Rep2>::type, /* 注を参照 */> |
[編集] 注記
結果の期間の期間は、Period1::num と Period2::num の最大公約数と、Period1::den と Period2::den の最小公倍数の比を形成することによって計算できます。
[編集] 例
このコードを実行
#include <chrono> #include <iostream> #include <type_traits> // std::chrono already finds the greatest common divisor, // likely using std::common_type<>. We make the type // deduction externally. template<typename T,typename S> constexpr auto durationDiff(const T& t, const S& s) -> typename std::common_type<T,S>::type { typedef typename std::common_type<T,S>::type Common; return Common(t) - Common(s); } int main() { using namespace std::literals; constexpr auto ms = 30ms; constexpr auto us = 1100us; constexpr auto diff = durationDiff(ms, us); std::cout << ms << " - " << us << " = " << diff << '\n'; }
出力
30ms - 1100us = 28900us
[編集] 関連項目
| std::common_type 特性を特殊化する (クラス テンプレートの特殊化) | |
| (C++11) |
型のグループの共通の型を決定する (クラステンプレート) |