I am running into something that seems a bit inconsistent.
When I pass an alias of a member to a mixin it works, but a member to member doesn't.

It seems like the alias is evaluated to the last symbol before passing it to the mixin.
If that's true, is there a way to defer the evaluation?

Anyway, better look at this code:


*** This works:

struct Array {
        void foo() { writeln("foo"); }
}

mixin template arrayOperations(arrays...) {
        void foo() {
                foreach(ref a; arrays) a.foo();
        }
}

class Thing {
        Array data1;
        Array data2;
        mixin arrayOperations!(data1, data2);
}

int main(string[] argv) {
        new Thing().foo();
        return 0;
}

***

But if I wrap Array in a S, then I get a "need this for data of type Array" Is there a way (without an alias this in S) to get the following working?


*** Non working code:

struct Array {
        void foo() { writeln("foo"); }
}

struct S {
        Array data;
}

mixin template arrayOperations(arrays...) {
        void foo() {
foreach(ref a; arrays) a.foo(); // error: "need this for data of type Array"
        }
}

class Thing {
        S s1;
        S s2;
        mixin arrayOperations!(s1.data, s2.data);
}



int main(string[] argv) {
        new Thing().foo();
        return 0;
}

Reply via email to