Loop through all modules and module members?

Philippe Sigaud philippe.sigaud at gmail.com
Sun Jan 2 01:04:42 PST 2011


On Sat, Jan 1, 2011 at 18:56, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> On 1/1/11, Philippe Sigaud <philippe.sigaud at gmail.com> wrote:
>> I'm not sure it's doable at
>> compile-time right now: you need to have access to the module code, as
>> text. Do imports work in CT-evaluable functions?
>>
>> Philippe
>>
>
> You're gonna love this:
>
> module mymodule;
>
> void main()
> {
>    pragma(msg, import(.stringof[7..$] ~ ".d"));
> }

I saw your .stringof trick a few days ago and it made my day :-)
But I didn't know you could text-import at compile-time (with access
for the programmer, I mean. Obviously the compiler can import at CT).
Cool!

OK, then it's doable to get a compile-time list of imported modules
from a module name. Too bad modules are not first class in D: would
they have type, we could return a list of them [std.algorithm,
std.concurrency, ...]


> Of course, you need to -J switch with the path of your module.

I'm not much versed in DMD switches. I'll try and see.

Philippe


More information about the Digitalmars-d-learn mailing list