Using getSymbolsByUDA in a static foreach loop

Jack Stouffer jack at jackstouffer.com
Wed Jan 19 20:46:17 UTC 2022


I'm trying to use getSymbolsByUDA in order to loop over all of 
the members in a struct with a certain UDA, and then call a 
function on the member. The plan is to use this to avoid looping 
over an array of function pointers.

However, the compiler is giving a strange error and the 
documentation of getSymbolsByUDA is unhelpful, as there are no 
practical use-case examples.

Here's a very simplified version of my code

```d
import std.traits;

enum Runnable;

struct SubSystem
{
     void run();
}

struct Manager
{
     @Runnable SubSystem subsystem;

     void run()
     {
         static foreach(system; getSymbolsByUDA!(Manager, 
Runnable))
         {
             system.run();
         }
     }
}

void main()
{
     Manager m;
     m.run();
}

```

Result:

```
onlineapp.d(16): Error: value of `this` is not known at compile 
time
```

This seems to me to be the logical way to write this code. What 
am I missing?



More information about the Digitalmars-d-learn mailing list