What is the difference between this line of code (Code 1)
auto l1 = [](auto a) { static int l = 0; std::cout << a << " " << ++l << std::endl; };
this line (Code 2)
static int l = 0;
auto l1 = [](auto a) { std::cout << a << " " << ++l << std::endl; };
and this? (Code 3)
int l = 0;
auto l1 = [l](auto a) mutable { std::cout << a << " " << ++l << std::endl; };
Main
l1("Joe");
l1("Joo");
l1(1.5);
Sometimes the int variable 'l' is shared between the calls and sometimes it is not. Having auto for one of the lambda's parameter, does it create multiple instances of the lambdas? I am not entirely sure how (Code 1) differs from (Code 2) and how (Code 2) differs from (Code 3). I was expecting (Code 3) to create multiple instances of the lambda so the output would be (Joe 1, Joe 2, 1.5 1) but turns out to be (Joe 1, Joe 2, 1.5 3).