Lambda expression in c++11

Source: Internet
Author: User

Lambda expression writing format in C + +

[capture list] (params list) mutable exception-> return type { function body }

The list of external variables, which is the list of capture list params list function parameters, mutable can be modified by external variables, exception exceptions, and return type return types.

Later, the sort can be written like this.

/*以下代码摘自陈锋的《紫书解答》*/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;    });

Lambda expression in c++11

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.