__traits(allMembers) and aliases
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Aug 25 07:08:07 PDT 2015
On Tuesday, 25 August 2015 at 12:48:12 UTC, Dejan Lekic wrote:
> It is off-topic (sorry for that), but how you grab only those
> (say functions) in a module that are annotated with @ChoseMe ??
> allMembers trait gives bunch of strings, and I could not find a
> way to use them with hasUDA template...
Here's the actual implementation:
```
template isDerelictSymbol(alias SymbolContainer, string sym)
{
static if(is(typeof(hasUDA!(__traits(getMember,
SymbolContainer, sym), DerelictSymbol)))) {
static if(hasUDA!(__traits(getMember,
SymbolContainer, sym), DerelictSymbol))
enum isDerelictSymbol = true;
else
enum isDerelictSymbol = false;
}
else enum isDerelictSymbol = false;
}
```
sym comes from allMembers. The typeof test probably isn't
necessary in most cases, but function pointer aliases of this
form:
```
extern(C) @nogc nothrow {
alias FuncPtr = void funcPtr;
}
```
...fail to compile if I don't do the typeof check. If I can
figure out a way to test for aliases, I can eliminate that bit as
well.
More information about the Digitalmars-d-learn
mailing list