Consider the following minimal example:
int main() { int x = 10; auto f1 = [x](){ }; auto f2 = [x = x](){}; }
I have seen this use of the initializer [x = x]
more than once, but I cannot fully understand it and why I should use it instead of [x]
.
I can get the value of something like [&x = x]
or [x = x + 1]
(as shown in the documentation and why they differ from [x]
, of Of course, but still I can not understand the differences between lambdas in this an example.
Are they completely interchangeable or is there some kind of difference that I don't see?
source share