Should you be able to initialize a float with a char?
Paul Backus
snarwin at gmail.com
Fri May 20 17:15:07 UTC 2022
On Friday, 20 May 2022 at 16:56:50 UTC, deadalnix wrote:
> On Friday, 20 May 2022 at 16:02:15 UTC, Steven Schveighoffer
> wrote:
>>> It implies all implicit conversions should be removed.
>>
>> No, not at all. bool can implicitly convert to int, char is
>> probably fine also (thinking about the OP of this thread, I'm
>> actually coming around to realize, it's not that bad). I don't
>> like integers converting *to* bool or char (or dchar, etc).
>> That would stop this problem from happening. bool being
>> treated as an integral type is suspect.
>>
>
> In fact, it doesn't even require implicit conversion to be
> removed at all. Matching bool in this case really doesn't make
> sense, and even by the letter of the spec I'm not sure this is
> right.
>
> Indeed, one of the constructor in an exact match, while the
> other is an implicit conversion match.
In this example, both `int` and `bool` are implicit conversions,
because the type of `E.a` is `E`, not `int`. So partial ordering
is used to disambiguate, and the compiler (correctly) determines
that the `bool` overload is more specialized than the `int`
overload, because you can pass a `bool` argument to an `int`
parameter but not the other way around.
As soon as you allow the `E` -> `bool` implicit conversion (via
VRP), everything else follows.
More information about the Digitalmars-d
mailing list