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

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.

主站蜘蛛池模板: 寿宁县| 永泰县| 临颍县| 濮阳县| 萝北县| 赫章县| 宁乡县| 长春市| 错那县| 蓬莱市| 普兰县| 平阳县| 小金县| 论坛| 石门县| 巴林左旗| 五峰| 礼泉县| 舞钢市| 泸水县| 惠来县| 股票| 崇明县| 新丰县| 韶关市| 英山县| 大渡口区| 丰原市| 江源县| 靖西县| 江孜县| 绵阳市| 肥东县| 资阳市| 梧州市| 灵丘县| 广西| 大邑县| 婺源县| 绩溪县| 阿荣旗|