Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the lambda expression of C++?

Shulou Source: shulou.com Published: 2022-06-01 19:11:02 10月01日 Update

This article mainly explains "what is the lambda expression of C++". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the lambda expression of C++".

Foreword:

Lambda is a new addition to Category 11, so there are requirements for your compiler. For example, if you use Visual Studio, then the version requirement is after VS2011.

What is the 1.lambda expression?

   lambda is a concise way to define anonymous function objects that accept parameters, store states, return values, and span multiple lines. Lambda expressions can improve the speed and efficiency of C++ programming, and readers are recommended to use them whenever possible. The following examples show how to use lambda expressions in STL algorithms such as for_each (), find_if (), and so on.

two。 Lambda expression corresponding to unary function

The lambda expression corresponding to the unary function accepts a parameter defined as follows:

[] (Type paramName) {expression}

You can also pass parameters by reference:

[] (Type& paramName) {expression}

The following shows how to use the lambda expression in the algorithm for_each () to display the contents of the STL container:

# include # include # include using namespace std;int main () {vector vecIntegers;for (int count=0; count

Tags: Expressions cantilever elements parameters predicates contents functions algorithms learning even numbers types analysis brevity preface containers objects that is as much as possible ideas situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MariaDB Apple Shulou Technology MySQL