4 ms·
The #1 feature I currently want is the ability to do an implicit lambda capture of a structured binding, at least by reference. I appreciate there are interesti
by saurik 6y ago
The #1 feature I currently want is the ability to do an implicit lambda capture of a structured binding, at least by reference. I appreciate there are interesting corner cases of like, bindings to bitfields: I simply don't need those corner cases solved... if it just supported a handful of the most obvious cases I would be so so so happy, and then they can spend the next decade arguing about how to solve it 99% (which I say as we know it won't be 100%... this is C++, where everything is some ridiculous epicycle over a previous failed feature :/).
(edit:) OMG, I found this feature in the list!! (It was in the set of structured bindings changes instead of with the changes to lambda expressions, which I had immediately clanged through.) I need to figure out now what version of clang I need to use it (later edit: I don't think clang has it yet; but maybe soon?)... this is seriously going to change my life.
https://oleksandrkvl.github.io/2021/04/02/cpp-20-overview.html#structbind-specs https://oleksandrkvl.github.io/2021/04/02/cpp-20-overview.ht...
- w0utert 6y ago>> this is seriously going to change my life. Now I'm curious. Can you give a small code example of the kind of thing this solves and how it will change your life? ;-)
- saurik 6y agoI constantly use both lambdas and structured bindings; without this feature, I am having to constantly redeclare every single not-a-variable I use in every lambda level and then maintain these lists every time I add (or remove, due to warnings I get) a usage. Here is one of my lambdas: nest_.Hatch([&, &commit = commit, &issued = issued, &nonce = nonce, &v = v, &r = r, &s = s, &amount = amount, &ratio = ratio, &start = start, &range = range, &funder = funder, &recipient = recipient, &reveal = reveal, &winner = winner]() noexcept { return [=]() noexcept -> task<void> { try { And like, at least there I am able to redeclare them in a "natural" way... I also tend to hide lambdas inside of macros to let me build new scope constructs, and if a structured binding happens to float across one of those boundaries I am just screwed and have to declare adapter references in the enclosing scope (which is the same number of name repetitions, but I can't reuse the original name and it uses more boilerplate).
- w0utert 6y agoAh I see, yes that's horrible. It's kind of weird structured bindings where not captured with [=](){} before, actually. I'm still stuck at C++11 for most of my work so I cannot use structured bindings at all, but I would not have expected to have to write that kind of monstrosity in C++17
- foota 6y agoOut of curiosity, what kind of domain is this?
- saurik 6y agoI work on a "streaming" probabilistic nanopayments system that is used for (initially) multihop VPN-like service from randomly selected providers; it is called Orchid. https://github.com/OrchidTechnologies/orchid https://github.com/OrchidTechnologies/orchid
- SavantIdiot 6y agoHow did you fall into such a niche? I don't mean that as a pejorative. It just seems so specific. And esoteric to me.
- Apofis 6y agoIt's a VPN Service that uses cryptocurrency as a means of payment. What seems really esoteric to me is that the 'Orchid' Ethereum Token has a $737,057,000.00 fully diluted market cap, which I'm struggling to understand: https://etherscan.io/token/0x4575f41308ec1483f3d399aa9a2826d74da13deb https://etherscan.io/token/0x4575f41308ec1483f3d399aa9a2826d...
- saurik 6y agoI dunno... Brian Fox (the developer of bash) got involved, and he tapped me (someone he has worked with before) as a combination networking and security expert? FWIW, if you describe anything with the technical precision I just did, almost anything will sound "esoteric" ;P.
- oops94 6y agoI believe GCC has supported this for a while now, even before it was added to the list of features for C++20.
- saurik 6y agoYeah... I did know gcc allowed it, but I didn't know it was because the spec now allowed it and not that they were just doing it anyway. Sadly, I am heavily heavily using coroutines (--even coroutine lambdas... with captures structured bindings ;P (don't try to auto template them though: that crashes the compiler)--which clang has much better support for.
- deleted 6y ago[deleted]
- gumby 6y agoThis 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.
- 6y ago