C++ Function Template With Flexible Return Type
- by Ignatius Reza
Let's say that we have a function like so
template <class T, class T2>
T getMin(T a, T2 b) {
if(a < b)
return a;
return b;
}
if we call the function like so
int a, b;
long c;
a = getMin(b, c);
if c is < a, then the value of c will be type casted to int.
Is it possible to make the return type flexible so that it would return an int, or long, or any other type considered smaller by "<" without being type casted?