Trying to forward unwrapped opDispatch names to alias this
aliak
something at something.com
Mon Feb 19 00:42:05 UTC 2018
I have a scenario where I'm wrapping functionality for a type,
but only if the contained type has a member. I want those to take
precedence. If the member is not there, then I want to delegate
to an aliases type via alias this.
I get an error here when I call b.p. Even though property p is in
type A and there's an alias a this in B.
Anyway to do this?
struct A {
@property string p() {
return "A";
}
@property void p(string str) {}
}
struct B(T) {
T t;
A a;
alias a this;
auto opDispatch(string name)() if (hasMember!(T, name)) {
return mixin("t." ~ name);
}
}
void main() {
B!int b;
b.max.writeln;
b.p.writeln; // Error: no property 'p' for type 'B!int'
}
Cheers,
- Ali
More information about the Digitalmars-d-learn
mailing list