C++??lambda????????ι??????
???????????? ???????[ 2017/2/16 16:05:41 ] ????????C++
?????Android?????????C++11/14??????????????????????仯????±????????е????????о????????C++????п???lambda????????????£?????????????????£?д??????????????3??lambda??????
[cpp] view plain copy ??CODE?????????????????????
#include <stdlib.h>
#include <stdio.h>
//1. ?????
auto hello = [] () {printf( "Hello world!
");};
// 2. ???????
auto hello_int = [] (int val){ printf("the value is %d
"?? val); };
int main(int argc?? char **argv) {
hello();
hello_int(argc);
// 3. ???????б??lambda????
auto lambda = [argc?? argv]() {printf("param: %d?? path is:%s
"?? argc?? argv[0]);};
lambda();
return 0;
}
???????????lambda??????lambda???????????????????????????±?????飬?????????????????????£????????????????????????????????????????????????????????????????????????????????????????????б????????????
??????£????????????????????£????£??????main??????
???水??????????????ж????????lambda??????????????????ò????????????????????????????????
??????????ú???[??????????????????demangle?????????????]????????
[html] view plain copy ??CODE?????????????????????
$_0::operator()(void)
$_1::operator()(int)
main::$_2::operator() const(void)
?????????????()??????.. ??????????????this????????????????????????????????????????????????????????????operator()..
???????????????????????
OK???????????lambda?????????????????????????????С???????
????????????????????????£?
[cpp] view plain copy ??CODE?????????????????????
#include <stdlib.h>
#include <stdio.h>
class $_0 {
public:
void operator() {
printf( "Hello world!
");
}
};
class $_1 {
public:
void operator(int va) {
printf("the value is %d
"?? val);
}
};
class main::$_2 {
public:
main::$_2(int i?? char **v): argc(i)?? argv(v) {}
//???????б??????????????б?...
void operator() const {
printf("param: %d?? path is:%s
"?? argc?? argv[0]);
}
private:
int argc;
char **argv;
}
int main(int argc?? char **argv) {
$_0 hello;
hello();
$_1 hello_int;
hello_int(argc);
main::$_2 lambda(argc?? argv);
lambda();
return 0;
}
????lambda???????????????????????????????????е?????
??????
???·???
??????????????????
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