Using getSymbolsByUDA in a static foreach loop
Jack Stouffer
jack at jackstouffer.com
Thu Jan 20 00:55:33 UTC 2022
On Wednesday, 19 January 2022 at 21:49:12 UTC, Adam D Ruppe wrote:
> I never use most of std.traits, they just complicate things.
> Bleh idk, I wouldn't bother with it and loop through the
> __traits instead.
Unless I'm missing something obvious this has to be a DMD bug,
because this prints nothing:
```d
import std.traits;
import std.stdio;
enum Runnable;
struct SubSystem
{
void run()
{
writeln("SubSystem ran");
}
}
struct Manager
{
@Runnable SubSystem subsystem;
void run()
{
static foreach(member; __traits(allMembers, Manager))
{
static foreach (attribute;
__traits(getAttributes, member))
{
static if (attribute == Runnable)
{
__traits(child, Manager, member).run();
}
}
}
}
}
void main()
{
Manager m;
m.run();
}
```
The `__traits(getAttributes, member)` call always returns an
empty tuple. Calling `__traits(getAttributes, Manager.subsystem)`
manually works as expected.
More information about the Digitalmars-d-learn
mailing list