C + + Learning Note (vii)-lambda expression iterator algorithm

Source: Internet
Author: User

About lambda Expressions:

Brush the question when encountered a code does not understand:

char ch = *it;
Auto It2 = find_if (it, B.end (), [CH] (charreturn x! = ch;});

FIND_IF: Returns the value of the iterator when Pred is true, and returns the position of the last element if all elements are not satisfied.

here [Ch] (char x) { return x! = ch;} is to apply a lambda expression.

Lambda expression in lambda expression C + + detailed

Here is the third, capture CH, the parameter is x, if X!=ch returns 1,find_if pred is true, stop iterating, return to it at this time.

"Lambda is an anonymous function that is useful for implementing a very simple function, and we only need to invoke it once ."----know, passer-by.

In addition, pred can also be implemented with the function of imitation, reference here as well as lambda and imitation functions, unknowingly and spread out a good big piece, first save, later used to study again.

About iterators:

For example, for the termination condition of the For loop, it is not possible to use It!=xx.end (), It<=xx.end ().

C + + Learning Note (vii)-lambda expression iterator algorithm

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.