官术网_书友最值得收藏!

Simplifying the function notation using a Lambda expression

The Lambda expression is an anonymous notation that represents something that performs an operation or calculation. In functional programming, the Lambda expression is useful to produce the first class and pure function, which we will discuss in separate chapters in this book. For now, let's familiarize ourselves with this new feature introduced in C++11 by investigating three basic parts of the Lambda expression:

  • capturing list: []
  • parameter list: ()
  • body: {}

The order of these three basic parts is as follows:

    [](){} 

The capturing list part is also used as a mark to identify the Lambda expression. It is a placeholder to value to be involved in the expression. The only capture defaults are the ampersand symbol (&), which will implicitly capture the automatic variables by reference, and the equal sign (=), which will implicitly capture the automatic variables by copy (we will discuss it further in the upcoming section). The parameter list is similar to the capturing list in every function where we can pass the value to it. The body is the implementation of the function itself.

主站蜘蛛池模板: 凌海市| 五华县| 砚山县| 句容市| 洱源县| 永福县| 高淳县| 乐至县| 抚州市| 临武县| 新巴尔虎右旗| 葵青区| 镇平县| 兴山县| 吉木乃县| 商丘市| 汕头市| 紫云| 望奎县| 资溪县| 垦利县| 南靖县| 宜黄县| 望江县| 潞城市| 临邑县| 无棣县| 樟树市| 漯河市| 句容市| 石景山区| 怀柔区| 桐梓县| 鄂州市| 五指山市| 南宁市| 梁平县| 寿光市| 台安县| 绵阳市| 惠安县|