I am just wondering how to write a Lambda function in C++ that 'remembers' a value passed into it for when it is called next time? Specifically I am thinking of the i=i
syntax from Python as follows:
funs = [(lambda i=i: i) for i in range(10)]
Such that if the following code is run:
for i in range(len(funs)):
print funs[i]()
The result is:
0
1
4
9
16
I was also wondering what the technical name (if one exists for this) would be? (I know that if I knew the answer to the second question I could just Google for the solution...)