by nemothekid · 2y ago · 0 comments
&&auto my_closure = [&](int x, int y) { return x + y }
to just let my_closure = |x: int, y: int| { x + y }
C++ is the one that tries hard to standout.Because it is. And is a statement I agree 100% being a +20-years C developer with a hardwired C parser in my brain: Rust, Zig and some (most?) newer C++ syntax is contorted at minimum (to my eyes).
I wish the only difference were about just new operators, but just the fact that the type has to come after the variable declaration is awful to me (also for returning types in functions declarations). One can tell me 100 reasons why Rust does it this way and they'll probably be all true and right, and you can call me all sort of things but this kind of new syntax puts me off right away.
auto my_closure = [](int x, int y) { return x + y; };
let my_closure = |x: int, y: int| { x + y }
and frankly, the option of an explicit capture-list with aliases and mixing moves and copies is a benefit: int sum = 0, diff = 0;
auto adder = [&sum](int num) {
sum += num;
// compilation error, author didn't
// mean to capture diff.
diff -= num;
};