#include <iostream>
#include<set>
#include<vector>
//lambda改变了对c++标准库的使用
//
using namespace std;
int main() {
[] {
std::cout << "This is a simple lambda function.\n";
}();//这里直接调用
auto i= [] {
std::cout << "This is a simple lambda function.\n";
};
i();
//[导入符号](参数) mutable throwSpec -> retType
int id = 0;
auto f = [id]()mutable {//构造时id已经构造好了,并不绑定
std::cout << id << std::endl;
id++;
};
f();f();
id = 42;
f();f();f();
id = 1;
auto f2 = [&id]()mutable {//引用会变
std::cout << id << std::endl;
id++;
};
f2(); f2();
id = 42;
f2(); f2(); f2();
//class Person {
//public:
// char name() { return '1'; };
//};
//auto cmp = [](const Person&p1, const Person&p2) {
// return p1.name() < p2.name();
//};
//std::set<Person, decltype(cmp)>cool(cmp);//报错
//vector<int> vi{ 1,2,3,4,5,6 };
//int x = 3, y = 10;
//vi.erase(remove_if(vi.begin()),vi.end(),
// [x, y](int n) {
// return x<n&&n<y;
// },
// vi.end()
//);
system("pause");
return 0;
}