If we have:
void foo(int) {}
void foo(const int&) {}
we cannot call foo like this:
foo(3);
because the call is ambiguous:
error: call of overloaded 'foo(int)' is ambiguous 40 | foo(3); | ^ note: candidate: 'void foo(int)' 36 | void foo(int) {} | ^~~ note: candidate: 'void foo(const int&)' 37 | void foo(const int&) {} | ^~~
What we can do is explicitly provide the correct overload, for example via a function pointer:
auto (*ptr)(const int&) -> void = foo;
ptr(3); // calls the "const int&" overload, obviously
However, that kind of defeats the purpose of convenient overloads. The question is - can I somehow disambiguate the call in a more... elegant? way? Are there ever cases where it would be desired to provide both overloads, for T and for const T&?