I made a template and an auto function that compare 2 values and return the smallest one. This is my code:
#include
A function can only have a single return
type. Using return
type deduction means that it will be deduced based on the type of the expression in the first return
statement the parser sees. If later return
statements do not return expressions of the same type, then the function is considered to be self-contradictory and thus ill-formed.
In the second case, the ?:
determines the type of the expression based on a common type determined based on the second and third sub-expressions. The two sub-expressions will be converted to this common type.
That's different from how return
type deduction works. If you intend for your first case to work, then you need to explicitly convert the returned value to the desired return type.