提示这篇文章可能较长,分为如下几部分
什么是lambda函数
Lambda函数的用处
Lambda函数中的变量截取
Lambda函数和STL
1. 什么是lambda函数
lambda表达式无疑是C++11最激动人心的特性之一!它会使你编写的代码变得更优雅、更快速! 它实现了C++11对于支持闭包的支持。首先我们先看一下什么叫做闭包
维基百科上,对于闭包的解释是:
In programming languages, a closure (also lexical closure orfunction closure) is afunction or reference to a function together with a referencing environment—a table storing areference to each of the non-local variables (also called free variables or upvalues) of that function.[1] A closure—unlike a plainfunction pointer—allows a function to access those non-local variables even when invoked outside its immediatelexical scope.
The concept of closures was developed in the 1960s and was first fully implemented in 1975[citation needed] as a language feature in the Scheme programming la