Comment #0 by eberhardhoepfner — 2013-10-10T10:36:35Z
mixin templates and alias-this are really the same thing, the first being a static mixin, the second a dynamic mixin. So I expect them to be interchangeable:
import std.stdio;
mixin template T() {
void foo() { writeln("mixin"); }
}
class C {
void foo() { writeln("mixin"); }
}
class Outer {
void foo() { writeln("outer"); }
class Inner {
static const bool TEMPLATE = true;
static if (TEMPLATE) {
mixin T;
} else {
C c = new C;
alias c this;
}
void test() {
foo();
}
}
void test() {
Inner i = new Inner;
i.test();
}
}
void main(string[] args) {
Outer o = new Outer;
o.test();
}
Output:
TEMPLATE == true: "mixin"
TEMPLATE == false: "outer" <-- should be "mixin"!
I expect alias-this to behave like a mixin template:
class C {
void foo() {}
}
class Outer {
void foo() {}
static class Inner {
C c = new C;
alias c this;
void test() {
foo(); // Error
}
}
}
test.d(10): Error: this for foo needs to be type Outer not type test.Outer.Inner
Comment #1 by robert.schadek — 2024-12-13T18:12:34Z