[C++11] lambda function

Source: Internet
Author: User
Brief introduction:

[Capture] (parameter) mutable->return_type {statement}

[Capture]: A capture list, which is a caret of a lambda function that captures a variable from the context for use by a function.
[var]: Value passing capture variable var;
[=]: Value passing captures all parent-scoped variables;
[&var]: Reference passing capture variable var;
[&]: Reference passing captures all parent-scoped variables;
[This]: value is passed to capture the current this pointer.

(parameter): Parameter list. If you do not need it, you can omit it together with parentheses.

The mutable:mutable modifier. By default, a lambda function is always a const function, and mutable can cancel its constant nature. When you use this modifier, the argument list cannot be omitted.

->return_type: return type. Displays the claim return type. Do not need to return when you can omit it together with. When there is a return value, the type can be inferred by the compiler itself, implicitly declared.

{statement}: function body. You can use the capture list to capture a variable or use a parameter in a parameter list.

Instance:

  

[C++11] lambda function

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.