-
-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Improve overload resolution #11271
base: master
Are you sure you want to change the base?
Conversation
I don't think the phobos code above should compile. |
Do you realize what this would mean when we add proper float/double overloads for all math functions? Ugly and embarrassing stuff like https://github.com/Netflix/vectorflow/pull/33/files. |
@kinke literals are |
What? The literal above is an int, see the error msg. |
@kinke in that case the user would have to decide if we wanted to convert it to a double a float or a real. |
Taking that into account would IMO be a valid stance too but probably require another MATCH value meaning lossless conversion. Anyway, an int is always losslessly representable as double, so the double overload for the example above should be a no-brainer. [C++ uses the |
@kinke c++ does horrible things with implicit conversion.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fully in favor of this. Thanks!
So the approach is: That might be acceptable. ish |
C# shows the same C++ behavior in this case: So I'd expect regular devs to expect this from D too. I'm not familiar with the exact C++ overload resolution rules. The approach here is sketched out in the 1st post - an overload requiring a single conversion ( |
Problem
From dlang/phobos#7463 (comment):
Note that this works for C++.
Approach
The current resolution scheme only takes into account the worst
MATCH
over all argument->parameter pairs. So in the case above, a single implicit conversion from int to double is just as 'bad' as converting both double and int to a float/real each.So the approach here is to use counters for each
MATCH
class, for a more fine-grained resolution.