There is a great paper on C++ for scientific computing where the author (T. Veldhuizen) suggests a traits-based approach to address type promotion. I have used such app
I think you can use decltype for this:
template
void product(T t, U u)
{
std::cout << typeid(decltype(t * u)).name() << std::endl;
}
Or with declval:
#include
template
void product()
{
std::cout << typeid(decltype(std::declval() * std::declval())).name() << std::endl;
}
EDIT For T ans = T(a) * T(b); you can just use auto, auto ans = T(a) * T(b);