On 11/13/2018 7:12 PM, Isaac S. wrote:
why should an enum not convert to its declared type, rather than blindly using its literal value. Just using the literal value discards the secondary-type information the programmer had given it.

D has the following match levels:

1. exact
2. conversion to const
3. implicit conversion
4. no match

C++, on the other hand, has a long list of match levels, which nobody remembers, and yet still causes problems (see Scott Meyers). The conversion of `A` to `int` already drops it to match level 3, from which it will not rise. I.e. the second level being an exact match with `int` does not help.

The further disambiguation between multiple matching functions is done using partial ordering. This has NOTHING to do with the arguments. It just looks at:

   f(int)
   f(short)

and picks f(short) because it is more specialized. This partial ordering is what C++ does with template functions. It is simpler and more robust than the older more primitive "match level" system C++ uses for non-template functions. I suspect that if C++ were to do a "do-over" with function overloading, it would use partial ordering instead of match levels.

Interestingly, the match level and partial ordering methods almost always produce the same results.

There have been various attempts over the years to "fix" various things in the D matching system by adding "just one more" match level. I've rejected all of them, because things that look simple and obvious with trivial examples tend to sink in a swamp with the dirty reality of the rather vast number of types and conversions that D supports. This happens in C++, and what people tend to do is just throw up their hands and hackishly add in more overloads until they get the result they want.

Reply via email to