これが私がやろうとしていることの例です(これは問題を説明するための「テスト」ケースです):
#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;
}
ご覧のとおり、f()
関数には2つのバージョンがあります。1つint
目はテンプレートパラメーターとしてを取り、2つ目はを取りますstd::ratio
。問題は次のとおりです。
この関数を「ラップ」して、最初のテンプレートパラメータとしてORg()
を取り、の適切なバージョンを呼び出すことができます。int
std::ratio
f()
g()
2つの関数を書かずにそれを行う方法は?言い換えれば、私は代わりに何を書かなければならないの/*An int OR a type*/
ですか?