I'm trying to write a function that allows the user to specify a chrono::duration
like chrono::seconds
and return the result of chrono::duration::count
.
I'm able to do this using the following template function:
template<typename D, typename Rep>
Rep getTimeSinceStart(){
return chrono::duration_cast<D>(chrono::steady_clock::now() - start).count();
};
To call this function, I must specify the type for Rep
. For example, assuming I have an object called timer
, if Rep
is a long long
:
long long sinceStart = timer.getTimeSinceStart<chrono::seconds, long long>();
However, is there a way to just specify the chrono::duration
?
I was thinking something like:
template<typename D>
D.rep getTimeSinceStart(){
return chrono::duration_cast<D>(chrono::steady_clock::now() - start).count();
};
This way I could just call:
long long sinceStart = timer.getTimeSinceStart<chrono::seconds>();