I have this working code:
template <typename X, typename Y>
auto f(X a, Y b) { return a + b; };
template <typename X, typename Y>
auto f(X* a, Y* b) { return *a + *b; };
int main() {
int* p;
int* q;
f(p, q);
}
which compiles and runs the second f(), because it is more specialized.
However, if we const-qualify the arguments like so:
template <typename X, typename Y>
auto f(const X a, const Y b) { return a + b; };
template <typename X, typename Y>
auto f(const X* a, const Y* b) { return *a + *b; };
int main() {
int* p;
int* q;
f(p, q);
}
It no longer works and tries to pick the first function, erroring out on the a + b for pointes.
Why does const-qualifying the types make the second template no longer more specialized?