On 2012-06-01 16:30, Steven Schveighoffer wrote:

I'm surprised at some things that work with alias. It sometimes seems
like black magic.

Consider that this does work:

void incx(alias x)()
{
x++;
}

void main()
{
int x = 0;
incx!x();
assert(x == 1);
}


now, consider that when incx!x is compiled, the stack frame for main
doesn't exist! So how does the compiler build it?

I suppose the issue with the lambda in class scope issue above is
different, because incx has an implicit reference back to its caller's
frame through the stack pointer.

But it seems like there may be a way that it could work. For example,
create an implicit, final (private) member function which has the body
of the lambda. Then construct the Bar type with an alias to that
function. Would it need a stack frame to work? I have no idea :) Again,
black magic.

-Steve

I don't see this example as strange. I mean, the same would work with a pointer or ref.

The lambda on the other hand was create in a scope where the this-reference wasn't available. But I don't know, as you say, black magic.

--
/Jacob Carlborg

Reply via email to