标签:fun UNC 表达 ons sort lis body list turn
c++中的lambda表达式书写格式
[capture list] (params list) mutable exception-> return type { function body }
其中,capture list
是外部变量列表,params list
是函数参数列表,mutable
可以修改外部变量,exception
异常,return type
返回类型。
以后排序可以这么写了
/*以下代码摘自陈锋的《紫书解答》*/
struct TS {
int a, b, c;
}tss[N];
sort(tss, tss+N, [](const TS& t1, const TS& t2) {
if (t1.a != t2.a) return t1.a < t2.a;
if (t1.b != t2.b) return t1.b < t2.b;
return t1.c < t2.c;
});
标签:fun UNC 表达 ons sort lis body list turn
原文地址:https://www.cnblogs.com/RFisher/p/9270900.html