30.05.2023 11:46, John Xu пишет:


How to put above enum as a function parameter? Following code wouldn't work:

     string getTMember(T t, enum string memberName) {
         return __traits(getMember, t, memberName);
     }

My database table is very wide, with many columns. Above ddbc allows a struct to map db returned data. Then if I want a member's value to show in vibe.d template,
how do I use a function to get it?

This works for me:
```D
import std;

void main() {
    struct T {int a; string name;}
     auto t = T(12, "got by member name");
     enum s = "name";
     writeln(__traits(getMember, t, s));
}
```

Reply via email to