정확히 무엇을 표현하고 싶습니까? 기본값을 원하는 것이 무엇입니까?
예를 들어 ReturnT
템플릿을 정의 할 수 있으며 기본값은 DurationT
이고 기본값은 입니다.
template <typename ReturnT = float,
typename DurationT = std::chrono::duration<ReturnT, std::milli>>
ReturnT tick0()
{
std::chrono::high_resolution_clock::time_point
currentPoint { std::chrono::high_resolution_clock::now() };
DurationT elapsed { currentPoint } ;
return elapsed.count();
}
그러나 같은이 기능은 ReturnT
다른 반환 유형으로 DurationT
호출되는 것을 허용?
뜻은 다음과 같습니다.
foo0<long double, std::chrono::duration<float, std::milli>>();
나는 그렇지 않다고 생각해.
그래서 나는 하나의 유형 만 표현하고 다른 하나는 파생해야한다고 생각합니다.
std::chrono::duration<float, std::milli>
기본값으로 DurationT
을 표현하고 ReturnT
을 추론 할 수 있습니다. 예에 의해
template <typename DurationT = std::chrono::duration<float, std::milli>>
decltype(std::declval<DurationT>().count()) tick1()
{
std::chrono::high_resolution_clock::time_point
currentPoint { std::chrono::high_resolution_clock::now() };
DurationT elapsed { currentPoint } ;
return elapsed.count();
}
또는 기본 float
과 함께 ReturnT
을 표현하고,에서 DurationT
을 추론 할 수있다; 예 :
template <typename ReturnT = float>
ReturnT tick2()
{
using DurationT = std::chrono::duration<ReturnT, std::milli>;
std::chrono::high_resolution_clock::time_point
currentPoint { std::chrono::high_resolution_clock::now() };
DurationT elapsed { currentPoint } ;
return elapsed.count();
}
여기에서 달성하고자하는 것은 분명하지 않습니다. 'DurationType'을 함수의 템플릿 매개 변수로 승격시키는 것이 왜 그것의 인터페이스에도 나타나지 않는 이유는 무엇입니까? 유일하게 템플릿 매개 변수로'ReturnType'을 가질 수 있고'DurationType'을'auto'로 대체 할 수 있습니다. –