Getting all types defined in a module at compile time

Ben Jones fake at fake.fake
Mon Nov 18 21:48:00 UTC 2019


I'm trying to get a list of all the types defined in a module at 
compile time (enums, structs, classes).  I attempted to use the 
isAggregateType trait, but it choked when it was passed modules 
that had been imported (object, and the others explicitly 
imported).

My next attempt was to try to filter out the modules, then look 
at everything left over with things like isAggregateType, etc.  
However, I'm getting errors when trying to filter on isModule.

Am I missing out on a simpler/more direct approach?  Is there a 
workaround to this alias error?

```
module thismodule;

import std.meta;
import std.traits;

struct S{}
enum E {asdf};
class C{}

template symbols(alias mod){
	alias getSymbol(alias T) = __traits(getMember, mod, T);
     alias symbols = staticMap!(getSymbol, __traits(allMembers, 
mod));
}

template notmodule(alias T){
     alias notmodule = __traits(isModule, T);
}

void main(){
     static foreach(s; symbols!thismodule){
      	pragma(msg, fullyQualifiedName!s);
     }

     alias notmods = Filter!(templateNot!notmodule, 
symbols!thismodule);

}
```

I get errors:

```
(on the alias notmodule line) Error: trait isModule is either 
invalid or not supported in alias
```


More information about the Digitalmars-d-learn mailing list