ModuleInfo, Object.localClasses(), and Object.find() - any users?

Dadoum contact at dadoum.ml
Tue Dec 13 21:29:57 UTC 2022


On Friday, 9 December 2022 at 22:20:28 UTC, Walter Bright wrote:
> 2. Does anybody need them?

I use those in this way:
```d
foreach(mod; ModuleInfo) {
     foreach(cla; mod.localClasses) {
         if(cla.base && cla.isBackendBuilder) {
             BackendBuilder backendBuilder = cast(BackendBuilder) 
cla.create();
             backendBuilder.__ctor();
             ushort score = backendBuilder.evaluateEnvironment();
             if (score > maxScore) {
                 maxScore = score;
                 bestBuilder = backendBuilder;
             } else {
                 destroy(backendBuilder);
             }
         }
     }
}
```

My use case here is to enumerate all the classes that can 
initialize a backend that are currently loaded in the runtime. 
But I only need to iterate through all types.

If there was a way to make templates that are automatically 
instatiated into all child classes, it would probably allow the 
right classes to automatically register to a list on Runtime 
initialization, and thus optimizing this code.


More information about the Digitalmars-d mailing list