The code provided below failed to compile. The compiler blames candidate template ignored: couldn't infer template argument 'Rep2'
. What I expect is to provide a d1 and use the default value as d2.
Is it due to the default value d2=std::chrono::minutes(1)
which confused the type deduction? However, the default is the second argument which is the desired default as there is no 2nd argument provided in the BAr bar{...}
statement.
#include<chrono>
struct Bar
{
std::chrono::nanoseconds duration1;
std::chrono::nanoseconds duration2;
Bar()=delete;
template<class Rep,class Period,class Rep2,class Period2>
Bar(
const std::chrono::duration<Rep, Period> &d1,
const std::chrono::duration<Rep2, Period2> &d2=std::chrono::minutes(1)):
duration1(std::chrono::duration_cast<std::chrono::nanoseconds>(d1)),
duration2(std::chrono::duration_cast<std::chrono::nanoseconds>(d2))
{
}
};
int main()
{
Bar bar{std::chrono::hours(7)};
}