mixin template A()
{
     lazy mixin(B);
     //mixin(B);
}

template B()
{
string B() { return "void foo(double d) { foo(cast(int)d); }"; }
}

class C
{
    void foo(int x) { writeln("x"); }
mixin A; // tries to add foo to class but already exists(even though it is not identical)
}

without the lazy mixin in A, foo is created while the template is being "instantiated". Then in C, the mixin does not overload foo and hence does nothing(there is no foo(double) in C).

If we can "lazily" evaluate the string mixin, then it would work(since string mixins do not do any overload analysis).

That, or allow one to overload with mixin templates.

i.e., the class C becomes

class C
{
    void foo(int x) { writeln("x"); }
mixin(B); // because of lazy(which doesn't evaluate string mixins immediately)
}

I know it doesn't seem like much but it is. Because one can't simplify certain things(I can't get the this pointer under the hood in a string template which makes code generation difficult and requires extra code to get everything working).



Reply via email to