static foreach / iterate over all consts in a module?
Robert M. Münch
robert.muench at saphirion.com
Tue Mar 5 12:57:15 UTC 2019
On 2019-03-04 00:37:56 +0000, Rubn said:
> It depends on how it is stored, if it is just an enum, then yes you can
> do pretty much what you have already. Some example of what you have
> already would help as well.
>
> https://run.dlang.io/is/l2jyWP
>
> module thisModule;
>
> enum WM_CREATE = 1;
> enum WM_DESTROY = 2;
>
> void main()
> {
> import std.stdio;
>
> foreach(memberName ; __traits(allMembers, thisModule))
> {
> alias member = __traits(getMember, thisModule, memberName);
> static if(memberName.length >= 3 && memberName[0 .. 3] == "WM_") {
> writeln(memberName, ": ", member);
> }
> }
> }
Thanks.
Trying this (I replaced thisModule by core.sys.windows.winuser
everywhere) I get the following errors for the line with the "writeln":
Error: unexpected ( in declarator
Error: basic type expected, not ": "
Error: found ": " when expecting )
Error: no identifier for declarator writeln(memberName, _error_)
Error: semicolon expected following function declaration
Error: declaration expected, not ,
Wondering why the "writeln" bombs out here...
--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster
More information about the Digitalmars-d
mailing list