Multi-layer structured binding

110 views
Skip to first unread message

Antonio Perez

unread,
May 15, 2017, 5:29:47 AM5/15/17
to ISO C++ Standard - Future Proposals
C++17 introduced structured binding. This is a great idea, and I applaud the move. I propose a slight generalization to structured binding. 
Currently, this is legal: 
tuple a = {2, 3.7, tuple(5, 7)};  
auto [x,y,z] = a;
//x = 2, y = 3.7, z = tuple(5,7)

I propose allowing structured binding over multiple levels:

tuple a = {2, 3.7, tuple(5, 7)};  
auto [x,y,[z1,z2]] = a;
//x = 2, y = 3.7, z1 = 5, and z2 = 7

This move represents an intuitive generalization of the syntax, and I believe it will make structured binding a more complete and useful language feature. 

Vicente J. Botet Escriba

unread,
May 15, 2017, 6:05:56 PM5/15/17
to std-pr...@isocpp.org

I don't believe there will be too much opposition to this feature.

Vicente

Richard Smith

unread,
May 15, 2017, 7:19:13 PM5/15/17
to std-pr...@isocpp.org
There is a conflict between this and attribute syntax, which will need to be ironed out before this extension can be accepted, but we did discuss this before structured bindings were moved into the standard draft and it was definitely an anticipated future direction.

Antonio Perez

unread,
May 16, 2017, 9:41:31 AM5/16/17
to ISO C++ Standard - Future Proposals
Oh! Good! So it's probably something that'll be seen in C++20?

Nicol Bolas

unread,
May 16, 2017, 10:17:51 AM5/16/17
to ISO C++ Standard - Future Proposals
On Tuesday, May 16, 2017 at 9:41:31 AM UTC-4, Antonio Perez wrote:
Oh! Good! So it's probably something that'll be seen in C++20?

Only if someone actually makes a proposal for it and pushes it. The main point is that the designers of structured binding anticipated that this would be a logical next step. That doesn't mean it will happen, only that it was anticipated that this was desired.
Reply all
Reply to author
Forward
0 new messages