C++11 lambda????
???????????? ???????[ 2014/11/10 10:55:07 ] ????????C++ NET ???????
????C++11??????lambda????????ó??????????????????????ú????????????е???????????????????????????
????Lambda?????????????????????
??????????????????????????????lambda??????????????????б??б???????????????????
????Lambda????????????????‘[]’???????????‘=’??‘&’?????lambda????“????”??lambda??????????? scope?????????????????????????????????‘&’?????????????‘=’??????????????????????????????
????Lambda???????????б?
????Mutable ???
?????????
?????????
????“????”?壬???lambda??????????е???????
????????????????β?????????
????int x = 10;
????int y = 3;
????int z ;
????z = [=]()mutable throw() -> int { int n = x + y; x = y ; y = n; return n;}();
????cout<<z<<endl;
????cout<<"x:"<<x<<" "<<"y:"<<y<<endl;
???????н?????
????13
????x: 10 y: 3
???????????????????????x??y????x??y???????з??????
?????????????lambda?????????????????Щ???????????????????
???????????????????????lambda???????洫???????
#include <iostream>
using namespace std;
int main()
{
int n = [] (int x?? int y) { return x + y; }(5?? 4);
cout << n << endl;
}
???????н?????9
?????????????????????????????“??????”?????‘()’?????????
?????????????????????????????????ú?????????lambda??????????о?????????????????????????ò?????????????????÷???????
#include <iostream>
using namespace std;
int main()
{
auto f = [] (int x?? int y) { return x + y; };
cout << f(21?? 12) << endl;
}
???????н?????33
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11