Templates don't seem to be able to type-infer the results of primitive operations. For example, the following fails to deduce R:
template<typename A, typename B, typename R>
R addNumbers(A x, B y){
return x + y;
}
main(){
addNumbers(1.0f, 1);
}
even though it's clear that float + int = float
.
Is there some way, in any version of C++, to get the inference to take this information into account without explicitly specifying it?
Aucun commentaire:
Enregistrer un commentaire