Hrm, I don’t quite like the arrows. C++ lambdas can contain arbitrary code and these arrows always remind me of “pure” functions (in a sense), or at least functions whose main purpose it is to map input arguments to output arguments.
For example, consider something like this relatively common block to do some complex operation on the elements of a vector using some (naive) threading (it might be nicer to first create some lambdas, push them into a queue and then spawn threads to work on that queue, but the syntax is essentially the same):
for(std::size_t i(0); i != somevec.size(); ++i) {
workers.push_back(std::thread([&somevec, i]() mutable { calc(somevec, i); }));
}
That is, we want an anonymous lambda which captures some elements of its environment (by both reference and value, also it’s essentially a closure by now) and call some function on these elements. That lambda doesn’t have any return value and doesn’t take any input arguments. Sure one could throw in an extra
lambda somewhere or put an arrow between
mutable and
{, but I have to admit I don’t see the value.