How do I iterate over enum members at runtime?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat Apr 9 16:20:53 PDT 2011
Well, the C code I was translating had something like this:
struct SysMetrics
{
int iIndex;
char* szLabel;
char* szDesc;
}
And then it used an array of these structures. So for all existing
enums that started with "SM_", those fields were populated with the
enum value and a name and description. A 200 line header file was
filled by hand. I really hope the author had some help from an editor
for that, lol!.
I've managed to do the same in about a dozen lines of code, although I
didn't fill the description field (I don't need it anyway):
http://codepad.org/EJEuc6qA
It's a shame that an enum with a tag doesn't have a .length property.
I've had to use __traits to build an array just to get the length.
More information about the Digitalmars-d-learn
mailing list