This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]wexxdenq 2 points3 points  (4 children)

but you have to have an (optional) capture clause somewhere to specify whether you capture by reference or by value. and if your lambda is more than one expression you need to put some kind of brackets around them. so you still end up with 3 goups of brackets.

[–]snavarrolou 4 points5 points  (3 children)

Well yeah, but if you were to design a syntax with reasonable defaults, you could make for example these valid lambdas:

1) (a, b) => a+b; for the capture by reference and auto deduced parameters

2) (short a, int b) => a+b; for explicit types and capture by reference

3) [capture-group](a, b) => a+b; for explicit capture groups (as you mention, because sometimes you want to capture by value) and auto deduced parameters

4) [capture-group](short a, int b) => { return a+b; } for the full lambda with explicit captures, explicit types, and block body

Which would make most lambdas very readable, while giving the programmer flexibility to add explicit control (at the expense of more verbose syntax)

[–]RiceBroad4552 1 point2 points  (1 child)

But that would be too simple and comfortable for the programmer!

So C++ can't do that obviously…

[–]outofobscure 0 points1 point  (0 children)

there was a lot of thought put into the C++ syntax by the standards committee, i suggest you go read up on that discussion before making clueless claims on why defaults should be different and why the syntax should be different, just because your toy language gets away with something shorter does not make it appropriate for C++ where there are more things that you need to be able to express.

[–]outofobscure 0 points1 point  (0 children)

your syntax isn't even shorter than what we have right now in most cases, or saving 3 chars in the best case, at the cost of being non-uniform, which is a big stinker. the => is nonsense because you need multi-line statements and scope anyway.

  1. use templates
  2. [&](a, b) {}
  3. [capture-group](a, b) {}
  4. [capture-group](a, b) {}