Here is an example of what I'm trying to do (this is a βtestβ case to illustrate the problem):
#include <iostream> #include <type_traits> #include <ratio> template<int Int, typename Type> constexpr Type f(const Type x) { return Int*x; } template<class Ratio, typename Type, class = typename std::enable_if<Ratio::den != 0>::type> constexpr Type f(const Type x) { return (x*Ratio::num)/Ratio::den; } template</*An int OR a type*/ Something, typename Type> constexpr Type g(const Type x) { return f<Something, Type>(x); } int main() { std::cout<<f<1>(42.)<<std::endl; std::cout<<f<std::kilo>(42.)<<std::endl; }
As you can see, there are two versions of the f() function: the first takes int as a template parameter, and the second takes the value std::ratio . The problem is this:
I would like to "wrap" this function with g() , which can take an int OR a std::ratio as the first parameter of the template and call a good version of f() .
How to do this without writing two g() functions? In other words, what do I need to write instead of /*An int OR a type*/ ?
source share