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:20:24 UTC 2024


I know that DStep generates CTFE functions to automatically make 
aliases for enum members so that the can be used without the enum 
name, as is done in C. DStep does it with a CTFE function, though 
it should also be possible with a mixin template.

Here is my attempt so far, using a mixin template:
```
template enumMixin(Enum) {
     private import std.traits;
     static foreach(member; EnumMembers!Enum) static if 
(__traits(isDeprecated, member))
     {
         private alias m = __traits(identifier, member);
         alias m = member;
     }
};
```

It hasn't worked so far.


More information about the Digitalmars-d-learn mailing list