In the following C++ Going native video,
there is mention of a language feature called "structural binding".
I had once referred to this concept as "destructuring" (comming of a javascript background).
The feature will allow users to capture multiple return values without needing to use std::tie
, or specify the types.
Example:
std::map<std::string,int> table;
auto { cursor, inserted } = table.insert({"hello",0});
Where can I find this proposal, and track its progress?
The proposal you are referring to is P0144R0: Structured Bindings . The post-Kona mailing lists this paper as under Evolution Working Group. It is not covered in the current Evolution Working Group(EWG) active issue list and Nicol Bolos points out the the EWG active issue list has not been updated for Kona. Once it shows up in the EWG active list then you can track the proposal by tracking the issue.
There are some really good trip reports and in particular Botond Ballo's trip report covers this proposal under the section Proposals for which further work is encouraged and it says:
A proposal for de-structuring initialization, that would allow writing auto {x, y, z} = expr; where the type of expr was a tuple-like object, whose elements would be bound to the variables x, y, and z (which this construct declares). “Tuple-like objects” include std::tuple, std::pair, std::array, and aggregate structures. The proposal lacked a mechanism to adapt a non-aggregate user-defined type to be “tuple-like” and work with this syntax; EWG’s feedback was that such a mechanism is important. Moreover, EWG recommended that the proposal be expanded to allow (optionally) specifying types for x, y, and z, instead of having their types be deduced.
We can find the WG21 meeting mailing by going to the WG21 site and going to the papers section.
As T.C. notes there is also a competing proposal P0151R0: Proposal of Multi-Declarators which says:
We propose a better approach for “Structured Bindings” as defined in P0144R0 where “better” is defined as terser, more ortogonal, more general, more expressive, less (parsingwise) ambiguous.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With