constructs a closure: an unnamed function object capable of capturing variables in scope. —— lambda functions (since c++11) [cppreference.com]
按照c++11标准的说法,lambda表达式的标准格式如下:
int main()
{
}
...省略...
push ebp
mov ebp,esp
sub esp,0cch
push ebx
push esi
push edi
push ecx
lea edi,[ebp-0cch]
mov ecx,33h
mov eax,0cccccccch
rep stos dword ptr es:[edi]
pop ecx
mov dword ptr [this],ecx
pop edi
pop esi
pop ebx
mov esp,ebp
pop ebp
ret
int 3
对应有汇编代码:
auto lambda = []{
lea ecx,[ebp-5]
call 001e1570
sub esp,0d8h
lea edi,[ebp+ffffff28h]
mov ecx,36h
mov dword ptr [ebp-8],ecx
mov dword ptr [ebp-14h],0ah
mov eax,dword ptr [ebp-8]
mov ecx,dword ptr [eax]
mov dword ptr [ebp-14h],ecx
int a = 0xb;
mov dword ptr [ebp-8],0bh
lea eax,[ebp-8]
push eax
lea ecx,[ebp-14h]
call 010e1be0
call 010e1c20
lea edi,[ebp+ffffff34h]
mov ecx,dword ptr [ebp+8]
mov edx,dword ptr [ecx]
mov dword ptr [eax],edx
ret 4
fun(&a,this);
int fun(int in,int* this)