Bug 20648 – static foreach over allMembers of module doesn't seem to work

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-03-09T03:44:42Z
Last change time
2020-03-21T03:56:37Z
Assigned to
No Owner
Creator
Manu

Comments

Comment #0 by turkeyman — 2020-03-09T03:44:42Z
This should list all the structs in the module: ---------------------- module my_module; struct Wow {} template ScrapeStructs(Tys...) { import std.meta : AliasSeq; static if (Tys.length == 0) alias ScrapeStructs = AliasSeq!(); else static if (is(Tys[0] == struct)) alias ScrapeStructs = AliasSeq!(Tys[0], ScrapeStructs!(Tys[1 .. $])); else alias ScrapeStructs = ScrapeStructs!(Tys[1 .. $]); } alias AllStructs = ScrapeStructs!(__traits(allMembers, my_module)); pragma(msg, AllStructs); // () pragma(msg, is(Wow == struct)); // true ---------------------- But it doesn't...
Comment #1 by boris2.9 — 2020-03-09T08:37:20Z
But "__traits(allMembers" returns a tuple of strings. You can use mixin to get a type (2.088+) or getMember. --- else static if (is(mixin(Tys[0]) == struct)) alias ScrapeStructs = AliasSeq!(mixin(Tys[0]), ScrapeStructs!(Tys[1 .. $])); ---
Comment #2 by turkeyman — 2020-03-09T09:50:14Z
Oh yeah, ffs... Sorry! Stupid mistake! >_<