DIPX: Enum Literals / Implicit Selector Expression
Timon Gehr
timon.gehr at gmx.ch
Thu Jul 7 21:39:52 UTC 2022
On 7/6/22 20:30, Walter Bright wrote:
> On 7/5/2022 4:19 PM, Timon Gehr wrote:
>> I.e., in terms of type checking, everything has already been figured
>> out and works:
>
> That example just hurts my brain :-/
Well, I don't recommend people use that specific pattern, but it makes a
lot of sense that it works in this way.
`x=>x` type checks as a `T delegate(T)` for any `T`.
`(x){}` does not type check as a `T delegate(T)` for any `T`.
The delegate literal is polysemous, and when trying to determine
matches, it's instantiated for each potential match. Therefore, if a
function accepts a `T delegate(T)`, the lambda can decide with `static
if` if there is a match or not, arbitrarily depending on `T`.
(Note that all instantiations have to type check, as D does not have
SFINAE.)
More information about the Digitalmars-d
mailing list