Doing a `static foreach` or `foreach` through enum members in a template or CTFE function, while disabling deprecation warnings
Liam McGillivray
yoshi.pit.link.mario at gmail.com
Fri Apr 19 22:29:50 UTC 2024
On Friday, 19 April 2024 at 22:24:17 UTC, Liam McGillivray wrote:
> ```
> template enumMixin(alias Enum) {
> static foreach(m; __traits(allMembers, Enum)) static if
> (!__traits(isDeprecated, __traits(getMember, Enum, m)))
> {
> mixin("alias "~m~" = __traits(getMember, Enum, m);");
> }
> };
> ```
Correction: The code shown above actually *does* work properly
without any deprecation warnings. I made a mistake with the enum
being set to the CTFE function I was previously using instead of
this template. This template actually works.
I posted here for visibility and searchability, in case anyone
else wants to do something like this.
More information about the Digitalmars-d-learn
mailing list