Consider the following, minimal example:
int main() {
int x = 10;
auto f1 = [x](){ };
auto f2 = [x = x](){};
}
I've seen more than once such an use of the initializer [x = x]
, but I can't fully understand it and why I should use it instead of [x]
.
I can get the meaning of something like [&x = x]
or [x = x + 1]
(as shown in the documentation and why they differ from [x]
, of course, but still I can't figure out the differences between the lambdas in the example.
Are they fully interchangeable or is there any difference I can't see?