std::common_type(std::chrono::duration)
性病:普通[医]类型%28 std::timeo::工期%29
template | | (since C++11) |
---|
公开名为type
,这是两种常见的类型。std::chrono::duration
S.
注
产生的持续时间的周期是Period1
和Period2
...
例
二次
#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) -> typename std::common_type<T,S>::type
{
typedef typename std::common_type<T,S>::type Common;
return Common(t) - Common(s
}
int main()
{
typedef std::chrono::milliseconds milliseconds;
typedef std::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
二次
另见
common_type (C++11) | determines the common type of a group of types (class template) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。