C + + version fifth exercise 10.14 10.15

Source: Internet
Author: User

Lambda recognition: A lambda expression represents a callable unit of code that I can interpret as an unnamed inline function, a lambda with a return type, a parameter list, and a function body; a lambda may be defined inside a function.

Lambda expression: [Capture list] (parameter list)->return type{function body}

Exercise 10.14 Write a lambda, accept two int, return their and;

#include <iostream>usingnamespace  std; int Main () {    int a=5, b=6;     = [] (intint &b) {return//lambda expression    cout << Sum (A, b) << Endl;         return 0 ;}

Exercise 10.15 Writes a lambda, captures the int of the function it is in, and accepts an int parameter, and the lambda should return the and of the captured int and int parameters

#include <iostream>using namespacestd;intSumConst int&a,Const int&AMP;B)//function{Auto F= [A] (intb) {returnA + b; };//lambda expression inside the function, a from the int argument where the function is located    returnf (b);}intMain () {intA=5, b=6; cout<< sum (A, B) <<Endl; return 0;}

C + + version fifth exercise 10.14 10.15

Related Article

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.