関数本体内にさまざまなバージョンを実装するだけで、より簡単で読みやすい方法はどうでしょうか?
template<typename T>
void DoSomething(T inVal) {
static_assert(std::is_floating_point<T>::value || std::is_integral<T>::value, "Only defined for float or integral types");
if constexpr(std::is_floating_point<T>::value) {
// Do something with a float
} else if constexpr(std::is_integral<T>::value) {
// Do something with an integral
}
}
パフォーマンスについて心配する必要はありません。条件はコンパイル時定数であり、降下コンパイラはそれらを最適化します。「if constexpr」は残念ながら c++17 ですが、両方のバージョンが両方のタイプでエラーなしでコンパイルされる場合は、「constexpr」を削除できます。