码迷,mamicode.com
首页 > 编程语言 > 详细

c++11中的lambda表达式

时间:2018-07-06 01:27:26      阅读:194      评论:0      收藏:0      [点我收藏+]

标签: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;
    });

c++11中的lambda表达式

标签:fun   UNC   表达   ons   sort   lis   body   list   turn   

原文地址:https://www.cnblogs.com/RFisher/p/9270900.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!