Oct 29, 2008 09:15
All of the lambdas I've presented so far have been stateless: they contain no data members. You can have stateful lambdas too, and this is accomplished through "capturing" local variables. The empty lambda-introducer [] says "I am a stateless lambda"...
What if you want to deal with (b), (c), and (d): avoid copies, observe updates to the local variables from within the lambda, and modify the local variables from within the lambda? In that case, you want to capture by reference. The syntax for doing this is the lambda-introducer [&x, &y] (you should think of this as X& x, Y& y ; that is, "reference" and not "address of")... Они просто душки, эти разработчики компиляторов C++. ;)
не люблю,
c++,
языки программирования