C++ Lambda??????????
???????????? ???????[ 2014/9/16 13:20:09 ] ??????????????? C++ NET
????????????????
????????????LB?????????LB??????????????????????LB??????????????????LB?????????????????????????????????????????á??????????????functor???????????????LB????????std::function???????????auto lb?????????
????std::function <void(int)> lb; //lb is a function which takes an integer and returns void
???????????????壬??????????????LB??????????????????????????????????????????????????
struct MyLambda
{
std::function <int (int)> _lbda;//line1
int _extra;
};
MyLambda TestLambdaObj(int t)
{
MyLambda ret;
if (t == 1)
{
ret._extra = t;
ret._lbda = [=](int x) -> int { return t + x; }; //line2
return ret;
}
else
{
ret._extra = t;
ret._lbda = [=](int x) -> int { return t * x; };//line3
return ret;
}
}
void TestLambdaFun2(int t)
{
MyLambda ret = TestLambdaObj(t);
int v = ret._lbda(t); //line4
printf(“v is ‘%d’ for type %d”?? v?? t);
}
?????????????MyLambda???????????????????function???_lbda??????C++ SPEC??????????LB??????????????????????????????????????????????????????line2??line3???? ???????function??????line4????
???????????
????function??????????“???”???????????γ?????LB?????????line2??line3????
??????LB?????function??????????????????line4????????????????????????????????????????????inline????????????????????????
?????????closure????LB?????????
???????????????LB??????std::function?????????“???”??
????C++??LB??????????????????????class???????syntax sugar?????????std::function???????????????????
????auto sum = 0;
????auto step = 2;
????auto lb = [&](int i){ sum += i + step; }//capture sum and step by ref
????lb?γ???????????????????з?????sum??step??????class????????????????????10?д???
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
??C++????????????C++ lvalue??rvalueC++11????????C++???????????????C++?е?????????????????C++?????????C++???Windows????λ??C/C++???????????????????JAVA??C??C++??????????c++??python???????????????????????????????C++???????C++?е????????C++????????????????C++ ???????????????C++?????????????????????C++????????????
???·???
??????????????????
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????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????