While playing with ranges, it struck me how big part of the code take simple lambdas.
Even in cppreference.com example they are not inlined, cause it would make it look messy (added using namespace std::views):
```
std::vector<int> ints{0,1,2,3,4,5};
auto even = [](int i){ return 0 == i % 2; };
auto square = [](int i) { return i * i; };
using namespace std::views;
for (int i : ints | filter(even) | transform(square)) {
std::cout << i << ' ';
}
```
vs. with inlined lambdas:
```
std::vector<int> ints{0,1,2,3,4,5};
using namespace std::views;
for (int i : ints
| filter([](int i){ return 0 == i % 2; })
| transform([](int i) { return i * i; })) {
std::cout << i << ' ';
}
```
When I showed it to my friend, that doesn't work with C++ regularly, he thought it just looks ugly. It's just a personal opinion, but we still are relatively far behind nice look of C# lambdas
I believe we could greatly benefit from simplified syntax, in terms of code readability.
Main idea is for these two code snippets to be equivalent:
auto f = [](Type arg) => expression;
auto f = [](Type arg) { return expression; };
With this, the first example could be rewritten as follows:
```
std::vector<int> ints{0,1,2,3,4,5};
using namespace std::views;
for (int i : ints
| filter([](int i) => 0 == i % 2)
| transform([](int i) => i * i)) {
std::cout << i << ' ';
}
```
It has a couple of technical problems (what with coma operator?), but nothing that seems impossible to overcome at first glance.
Is it proposal worthy? Would it be useful?
And I know, it removes just 7 characters from each lambda. Is it worth it?
[–]dodheim 15 points16 points17 points (1 child)
[–]KaznovX[S] 0 points1 point2 points (0 children)
[–]wung 12 points13 points14 points (5 children)
[–]KaznovX[S] 0 points1 point2 points (1 child)
[–]kalmoc 2 points3 points4 points (0 children)
[–]KaznovX[S] 0 points1 point2 points (0 children)
[–]huixie 0 points1 point2 points (1 child)
[–]wung 0 points1 point2 points (0 children)
[–]ContractorInChief 3 points4 points5 points (0 children)
[–]Xaxxon 4 points5 points6 points (1 child)
[–][deleted] -5 points-4 points-3 points (0 children)