How to get all modules in a package at CT?
cc
cc at nevernet.com
Thu Oct 5 21:25:54 UTC 2023
On Thursday, 5 October 2023 at 20:42:26 UTC, mw wrote:
> On Thursday, 5 October 2023 at 20:07:38 UTC, user1234 wrote:
>> No. Sorry.
>>
>> Generally compile time code cannot interact with the system.
>> To be evaluable at compile time code has to be strongly pure,
>> that is not the case of the function you would need.
>>
>> Otherwise you'd need a new traits for that... but that traits
>> would violate the rule explained before.
>>
>>>> If you want to iterate the package for modules imported in
>>>> it, I'm not sure. __traits(allMembers, package) will list
>>>> names of imported packages but not which modules.
>>
>> static reflection on import decls is broken, that wont work
>> well
>
> So how about at runtime? I just want the compiler to help to
> list them, instead of doing manually.
At runtime, simply:
```d
foreach (m; ModuleInfo) {
writeln(m.name);
}
```
However, Walter has hinted that he wants to remove ModuleInfo at
some point.
More information about the Digitalmars-d-learn
mailing list