std::common_type(std::chrono::duration)
提供: cppreference.com
template<class Rep1, class Period1, class Rep2, class Period2> struct common_type<std::chrono::duration<Rep1, Period1>, | (C++11以上) | |
2つの std::chrono::duration の共通型となるメンバ型 type
を提供します。
[編集]ノート
結果となる duration の period は Period1
と Period2
の最大公約数です。
[編集]例
Run this code
#include <iostream>#include <chrono> // std::chrono already finds the greatest common divisor,// likely using std::common_type<>. We make the type// deduction externally. template<typename T,typename S>auto durationDiff(const T& t, const S& s)->typenamestd::common_type<T,S>::type{typedeftypenamestd::common_type<T,S>::type Common;return Common(t)- Common(s);} int main(){typedefstd::chrono::milliseconds milliseconds;typedefstd::chrono::microseconds microseconds; auto ms = milliseconds(30);auto us = microseconds(1100); std::cout<< ms.count()<<"ms - "<< us.count()<<"us = "<< durationDiff(ms,us).count()<<"\n";}
出力:
30ms - 1100us = 28900
[編集]関連項目
(C++11) | 指定された型のグループの共通型を調べます (クラステンプレート) |