I found the original proposal for *C++ structured bindings here. It proposes a way to easily bind multiple return values, i.e.:
auto {a, b} = minmax(data);
But now I see that everyone points to the C++17/C++1z proposal syntax of
auto [a, b] = minmax(data);
Now that I learned "lists are written { like, this }" there comes a new list-syntax? Why? What is the problem with curly braces here?
The change from {} to [] occurred after Jacksonville and was made in response to comments from that meeting. This is detailed in p0144r2, which states: "because it is more visually distinct from the existing syntax for declaring multiple variables of the same type."
It appears that the NB comments requesting a change to the original usage of {} did not increase consensus in the Nov 2016 meetings, leaving the [] usage intact. At least until the Spring meeting.
The National Bodies from Spain and US have proposed to change back to the
{}
syntax because (P0488R0):Therefore, there still remains the possibility of ending up having the original syntax for C++17 (which I strongly believe is preferred by most users).
Update from this trip report:
@SebastianWahl only commented with a link. I will quickly summarize the content behind the link.
is ok with
auto
. But you can also do this:So when you use
{...}
this would becomewhich is bad, because the piece
tuple<int,float,string> {a,b,c}
also has a meaning in C++ and thus would be a difficult ambiguity, difficult to solve.One thing to be said for the square brackets syntax is that it closely resembles lambda capture clauses, where, similarly, you don't specify the variable type, since auto is implied. I.e.
It's obviously not the exact same thing, but when you think about it as "syntax for auto capturing by making sense of the context," it can work:
This is still under debate. It's difficult to be certain which syntax will be least confusing given how many uses there are for [] and {} already.
There's also the risk that "least confusing" and "easiest to parse" will be in conflict.