I am currently working on defining overloaded functions’ behavior. I want to be able to overload based on the function’s return type, and there are some very… interesting compilations that arise from that.
In order to resolve them, I’m trying to get a clear answer to one question: What are overloaded functions used for.
In particular, I’m talking about overloads that redefine a function with the same name and the same number of arguments, particularly when defined in different contexts.
The most typical use case for overloading in this case is, e.g., the
max function. You are quite expected to have different implementations of
max based on user defined types. Fundementally, however, they all do the same thing: accept two objects, and return (a reference to) the bigger of the two. If there is any ambiguity between overloads in such a case, that ambiguity will not result in fundamentally incorrect results. The different overloads pick between different ways of achieving the same end result.
My question is this: are there any other use cases I’m missing here. Is there a reasonable case where picking the “wrong” overload is a matter of having something completely different happening?
My intuition says no, but I’d really like to hear feedback from as many people as I can before I pass judgement.
- Different implementations for the same semantic operation.
- Potentially completely different operations that happen to have the same name and number of arguments (please post reasoning in comments)
- Other (definitely post reasoning in comments)