Frist Draft (in this forum): Enum Parameters

Quirin Schroll qs.il.paperinik at gmail.com
Wed Jul 31 22:55:36 UTC 2024


On Wednesday, 31 July 2024 at 08:15:31 UTC, IchorDev wrote:
> My only real gripe with the DIP is that `isEnum` should only 
> work for enum parameters. Having it check for enum membership 
> will surely create bugs in generic code somewhere.

I truly wonder how. In a function template, you can’t define an 
`enum` locally that has the same name as a parameter. And if 
there’s an eponymous `enum` constant outside the function’s 
scope, the name of the argument refers to the argument (unless 
you use `with`).

It says that it checks for enum *membership,* but the most 
relevant special case would be for simple `enum` constants, which 
are technically a shorthand for defining a member of an unnamed 
`enum`, so those are implicitly included.

Considering `__traits(isRef)` works to detect `ref` variables, 
too (in the current implementation), it would be weird if 
`__traits(isEnum)` wouldn’t detect `enum` other than `enum` 
parameters. Is it really a big issue that `__traits(isEnum, arg)` 
may return `true` if you misspell `arg` so that it accidentally 
becomes some `enum`? It’s not like it would be an error to use 
`isEnum` on it, it’d just return `false` instead, which IMO is 
just worse.


More information about the dip.development mailing list