Get UDAs of self's declaration as a member?
cc
cc at nevernet.com
Mon Apr 25 21:32:16 UTC 2022
Hard to word this question right, but is it possible to get the
UDAs assigned to a class/structure's member variable declaration,
within that variable's definition? e.g.
```d
import std.stdio;
import std.traits;
enum SPECIAL;
struct Foo {
void foo() {
static if (hasUDA!(typeof(this), SPECIAL))
writeln("special");
else
writeln("not special");
}
}
struct Bar {
@SPECIAL Foo foo;
}
void main() {
Foo foo;
foo.foo;
Bar bar;
bar.foo.foo;
}
```
This doesn't work of course, `@SPECIAL` isn't applied to `struct
Foo` itself so no UDA is found by `hasUDA!Foo`. Without
iterating Bar directly, is there some way to detect *within*
Foo's member functions, that the Foo being called is declared
with `@SPECIAL` inside its parent structure?
More information about the Digitalmars-d-learn
mailing list