opDispatch with string mixin does not work as I would expect.
German Diago
germandiago at gmail.com
Sat Feb 10 06:32:43 UTC 2018
Hello everyone,
I am trying to forward some member functions from a struct as a
Catch-all function, so I did something like this:
struct A {
struct HeaderData {
align(1):
char [21] id;
ubyte field1;
ubyte field2;
}
Nullable!(HeaderData) headerData;
auto opDispatch(string name)() {
readHeader();
static foreach (member; __traits(allMembers,
HeaderData)) {
static if (name == member) {
return mixin("headerData." ~ name);
}
}
}
The mixin line does not work. I want to generate the access to
the field. How could I achieve that?
More information about the Digitalmars-d-learn
mailing list