On Tuesday, 25 March 2014 at 18:10:17 UTC, Meta wrote:
On Tuesday, 25 March 2014 at 18:05:47 UTC, Frustrated wrote:
Due to a previous issue I am trying to do the following

mixin template A()
{
   mixin((function () => "int x;")() );
}

the problem is that the compiler will not let me use the delegate because it has no this context. Of course the whole point here is that the delegate will never be used at runtime since it is used in the mixin(which is purely compile time).

It should work(there is no reason it shouldn't) yet it doesn't.

The goal is that I do not want to create a function outside the mixin to use because it will be included in the context of the template mixin. e.g.,

mixin template A()
{
   string B() { return "int x;"; }
mixin(B()); // still doesn't work but if it did B would be inserted in the context of the template. e.g., if used in a class the class would then have a method named B in it, hence the use of the lambda.
}

There shouldn't be a context pointer at all as you specified that it's a function, not a delegate. Function literals don't have context pointers as far as I know. Did you try:

mixin((function () { return "int x;" })());

Just to be sure?

Thanks, I thought I did try that(that was the first thing I tried I thought). Seems to be working though.

Reply via email to