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:24:17 UTC 2024
Well, someone on the Discord server has been helping me attempt
this, but while I managed to get a solution that compiles without
errors, I still get the deprecation warning.
Here is what I ended up with:
```
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);");
}
};
```
Unfortunately, the deprecation warnings still appear if the enum
contains any deprecated members. I'm starting to suspect that the
language doesn't currently have any features to stop this from
happening. This is unfortunate, as it *should* be possible to
process an enum with deprecated members *without* getting these
warnings.
More information about the Digitalmars-d-learn
mailing list