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
라는 이름의 타입을 노출하며, 이는 두 개의
std::chrono::duration
의 공통 타입으로,
Period1
와
Period2
의 최대공약수가 주기(period)가 됩니다.
목차 |
멤버 타입
| 멤버 타입 | 정의 |
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)
|
여러 타입들의 공통 타입을 결정함
(클래스 템플릿) |