//[capture list](params list)mutable exception->return type{function body}
//[capture list] :捕获外部变量列表
//() :参数列表
//nutable: 说明是否可以修改捕获的变量,
//exception :异常设定
//-> :返回值
//{} :函数体
vector<int> a = {2,4,6,1,4};
sort(a.begin(), a.end(), cmp);
for_each(a.begin(), a.end(), [&](int a){cout << a << " ";});
cout<<endl;
sort(a.begin(), a.end(), [](int a, int b)->bool{return a>b;});
for_each(a.begin(), a.end(), [](int a){cout << a << " ";});
cout << "--------------"<<endl;
//[capture list] :捕获外部变量列表,有值捕获,引用捕获, 隐式捕获
int c = 100;
auto f = [c](int a){cout << c+a<<endl;};
c = 200;
f(2); //运行结果为102, 即更改了c之后, f中的c依然是100,这是一种值传递,拷贝值传递
int& rc = c;
rc = 100;
auto f2 = [&c](int a)mutable throw (){c++;cout << c + a<<endl;};
//mutable 表示捕获的值是可修改的
//throw () 表示不抛出任何异常
c = 200;
f2(2); //传递饮用,c的改变导致了函数f2输出的变化
//隐式捕获,编译器可以通过函数体内部的代码确定需要捕获哪些变量。有两种形式[=]和[&], [=]表示隐式值捕获,[&]表示隐式引用捕获
//混合捕获方式,[=,&x], 表示x以引用捕获的方式捕获,其他变量隐式值捕获
// [&,x], 表示x以值捕获方式捕获,其他变量以引用方式捕获