5 ms·
> In C++11, there is no ergonomic way to do a lambda capture by move – which is usually how I want to capture variables into a closure > It is unergonomic to r
by RcouF1uZ4gsC 3y ago
> In C++11, there is no ergonomic way to do a lambda capture by move – which is usually how I want to capture variables into a closure
> It is unergonomic to return multiple values by tuple in C++. It can be done, but the calls to std::tie and std::make_tuple are long-winded and distracting, not to mention that you’ll be writing unidiomatically, which is always bad for people who are reading and debugging your code.
C++14 allows you to move capture in lambdas. C++17 has structured bindings that help with returning multiple values.
If you are claiming to an expert in C++ talking about paper cuts, at least be aware of things that have happened in C++ in the last decade.
- hardware2win 3y ago>C++14 allows you to move capture in lambdas. Your quote says cpp11 and youre arguing with 14? Wtf?
- leni536 3y agoThe limitations of C++11 shouldn't really be relevant today.
- deleted 3y ago[deleted]
- Night_Thastus 3y agoHahahaha. Oh that's a good one. Source: Someone who was, until recently, limited to C++03. Luckily we're up to 17 now, but occasionally 11 limitations creep in.
- thecodedmessage 3y agoAuthor of the blog post here. I am limited to C++11 for this, and will be limited to C++03 for some related projects. I did say C++11 in that comment, as I am of course aware that C++ has "fixed" that issue, but I'm still entitled to my gripes. I find it odd that someone claimed I was not aware the issue has been fixed in later versions, when I specifically said a version. People seem to be very motivated to assume I'm wrong about C++... because otherwise they'd have to admit that their favorite language has flaws. In any case, I revised that section to explain how even the "fixed" version in C++14 is still a paper-cut, and make the section hopefully flow a little better. ETA: I replied to the right comment. I'm agreeing with you :-)
- Night_Thastus 3y agoDid you reply to the wrong comment? I was just saying that being stuck on older versions is more common that most people think.
- deleted 3y ago[deleted]
- fsloth 3y agoLet the holy wars begin. "Lambda capture" sounds like "my favourite way to juggle chainsaws". The correct answer to "I don't like lambda syntax..." is not "learn lambda syntax" but "do not use lambdas unless you really need them, and then think twice". Honestly, C++ is a massive footgun. Write the most simple, inelegant C++ you possibly can. The coming generations who need to maintain your code for the next 200 years will be thankfull for it. Don't pretend C++ is something more elegant like Ocaml that the compiler sugars you into believing. It's not! It's a horrible pile of ... things ... piled .. on top of .. things .. on top of ...(etc). And when something goes sideways at any point in that pile of templated tower of abstractions, the compiler will gift you with an outpout that is closer to a mix of toenail clippings and dog poo than an output from an industrial level programming tool. After which you need a heavy drink and wish there was a better language out there. And then you realize there isn't, for the specific task, and you adjust by reducing the complexity of the abstractions you use and prefer to have a codebase that has more lines of code and fever chances of irritating the compiler.
- gpderetta 3y agoI don't care if you do not like the lambda syntax (there is plenty of syntax of C++ that I dislike), but lambdas are now a pretty core feature of the language, so you better learn it or switch to another language.
- fsloth 3y agoStrong disagree. It’s not about the syntax, it’s about understanding the resource management model lambdas add on top of the existing mess. There is no good reason to use lambdas except parametrization of stl algorithms. Don’t use them as part of api design. The only thing you gain is one more level of complexity on reasoning resource management. Yes, to be specific, one should know how they work, and then not use them. This is in the context of C++ being a minefield of practically infinite complexity, in which the only way to survive is to pick the language subset you know you are able to handle, and stick with it. Of course, every party picks their own subset :)
- 3y ago
- thecodedmessage 3y agoI said "In C++11" because I am aware that it has been fixed later. But I'm stuck in C++11 for platform reasons and so I get to complain about its problems too. But of course, it is because I am aware that this has been fixed -- crappily -- that I qualified it. I'll add more qualifications for you :-) And I have now addressed structured bindings in the article itself for what they are: a halfway solution, unacceptable to anyone used to real tuples.