c++11中的lambda表达式

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;
	});
posted @ 2018-07-05 22:38  RawFisher  阅读(98)  评论(0编辑  收藏  举报