Frist Draft (in this forum): Enum Parameters

IchorDev zxinsworld at gmail.com
Fri Aug 2 03:49:22 UTC 2024


On Wednesday, 31 July 2024 at 22:55:36 UTC, Quirin Schroll wrote:
> 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.

It could still happen in string mixins, and generally we want a 
trait to mean one specific thing.

> 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.

Silently doing the wrong thing instead of giving an error message 
IS worse—this is D, not JavaScript!

It sounds like you intend the DIP to mean `isEnum` checks for 
manifest constant declarations? This is really not clear in the 
text, it sounds like you want it to check whether 
`is(typeof(symbol) == enum)`. You could probably clarify this a 
little better.

So, does `isEnum` yield `true` for template value parameters? If 
not, I think it’s too specific. Why not generalise it to all 
manifest constants and call it `isManifestConstant` (or just 
`isManifest`) instead? This could benefit meta-programming and 
potential future language features.


More information about the dip.development mailing list