On Monday, 15 February 2021 at 12:37:14 UTC, novice3 wrote:
This is reduced example.
I am sorry for this type of question,
but could please anybody show me template for this boring
coding?
Is this possible to avoid this manual coding?
Show me direction or examples please.
This will do most of it:
mixin template declareAnonymous(E, string sep = "_")
if (is(E == enum))
{
static foreach (memberName; __traits(allMembers, E))
{
mixin(
"alias ",
__traits(identifier, E), sep, memberName,
" = __traits(getMember, E, memberName);"
);
}
}
Usage:
enum MY_ENUM { A, B, C }
mixin declareAnonymous!MY_ENUM;
static assert(MY_ENUM_A == MY_ENUM.A);
static assert(MY_ENUM_B == MY_ENUM.B);
static assert(MY_ENUM_C == MY_ENUM.C);