首页 > 编程语言 > 详细

c++11中的lambda表达式

时间:2018-07-06 00:47:29      阅读:238      评论:0      收藏:0      [点我收藏+]

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表达式

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!