5 ms·
This thankfully made it into C++20. However a full destructuring bind, à la Lisp, hasn't. You can't do `for (auto& [a, [b, c]] : some_container_of_structs)` w
by gumby 6y ago
This thankfully made it into C++20.
However a full destructuring bind, à la Lisp, hasn't. You can't do `for (auto& [a, [b, c]] : some_container_of_structs)` which is handy for taking apart all sorts of things.
Relatedly there's no "ignore" though it exists in function declaration syntax: you can write `void foo (char the_char, int, long a_long);`. But you can't ignore the parts of a destructure you don't need: `auto& [a, , c]`. This capability is sometimes useful in the function declaration case but is quite handy, say, when a function returns multiple values but you only need one (consider error code and explanation).
And variadic destructuring...well I could go on.
I haven't attended a C++ committee meeting in 25 years (and didn't do a lot when I did) so I have no reason to complain.
- saurik 6y agoYeah: 100% to these complaints; I do run into the full destructuring issue occasionally, but it isn't blocking me ability to do composition of features in the same way this lambda capture issue is ;P.
- gpderetta 6y agoOne day we will get it. I believe the intention is to support full destructuring but it is hard to get a feature added to the standard. Sometimes functionality is cut just to increase the probability that it will be voted in. For example lambdas were added in C++11, but generic lambdas were cut out and only added in C++14.
- kazinator 6y agoDestructuring that lets you ignore parts of the object is usually found in the form of pattern matching. Lisp destructuring comes directly from macros: CL's destructuring lambda lists and macro lambda lists are closely related cousins. Macros usually care about all their arguments. Reason being, they are designed to cater to those arguments; an unnecessary element in the syntax of a macro will just be left out from its design, rather than incorporated as a piece of structure that gets ignored. (The exceptions to it are reasonably rare that it's acceptable to just capture a variable here and there and ignore it.)