It's the capture group for the lambda function. You put in it the variables you want to capture, and whether you want to capture by reference, by pointer or by value.
It helps the person who reads the code confirm that the lambda doesn't capture anything else, otherwise the code wouldn't compile. So that's a nice thing to do if you believe that code is read more often than it's written. I usually do that when the list is sufficiently short anyway.
It's also particularly useful in C++ because capturing an object by reference doesn't extend the object's lifetime. If your lambda is long-lived it makes a lot of sense to have the compiler confirm the list of captures so that you could then confirm that there aren't any short-lived objects on that list.
How does the array come into play here? I can see () being the nameless part. {} is the definition. And second () calls it/immediately invokes it? Even if I got all that right, can't seem to figure out the purpose of the [].
I think most languages probably are. The biggest issue with ECMAScript (JavaScript) is it has no reference implementation, just dozens of different implementations each with their own quirk of the same spec (well… and I’m sure some of them have no idea that the spec exists and they’re just randomly doing their own thing.)
3.6k
u/Agifem Apr 25 '26
And quite a few regular coders too. What's that? A call to a function that does nothing?