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.p.writeln; // Error: no property 'p' for type 'B!int'

- Ali

Reply via email to