How to get resultant type of multiplying two different types?
You can use decltype
to do this:
using result_type = decltype(std::declval<TA&>() * std::declval<TB&>());
You can use decltype
and std::declval
for this. decltype
will give you the type of an expression and std::declval
will "create" an object of the type for you, even if it can't/you don't know how to construct it. That gives you something like
using result_type = decltype(std::declval<TA&>() * std::declval<TB&>());
Note that I am using lvalue references for the type. This is done because by default decval
will give you an rvalue reference which might give you a different type.