Compile time only delegates

Meta jared771 at gmail.com
Tue Mar 25 11:10:16 PDT 2014


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?


More information about the Digitalmars-d-learn mailing list