So I know that I cannot use a float
as a template parameter:
template<float T>
float foo(const float param) { return param + T; }
I've heard that ratio
can be used as an alternative. I'd like to do something like this:
template<ratio T>
float foo(const float param) { return param * T::num / static_cast<float>(T::den); }
Unfortunately ratio
is not a complete type so that doesn't work at all. And ultimately I have to ask, why not just do:
template<int Num, int Denom>
float foo(const float param) { return param * Num / static_cast<float>(Denom); }
My preference would be to use a ratio
because it more clearly represents what I'm trying to do. Could someone provide me a simple way to use ratio
?