std:: common_type <std::chrono::duration>
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<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)
|
型グループの共通型を決定する
(クラステンプレート) |