Live data from Hacker News

C++20 Improved the For-Loop Syntax

lzon.ca

11–20 of 89 posts

Re: C++20 Improved the For-Loop Syntax

#12
post #5

Just what C++ needs, more bloat lol.

C++ is probably the only language that needs a strong style guide, to define a subset you are allowed to use in the project. Linus Torwalds famously said that subset is zero. You're not allowed to use C++ in Linux, a wise move. Here's Google's: https://google.github.io/styleguide/cppguide.html Search for "do not use" and you'll find plenty of hits.

> C++ is probably the only language that needs a strong style guide,

here you go: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines

Re: C++20 Improved the For-Loop Syntax

#13
post #10
post #8

Earlier quoted context omitted.

Python is 0-indexed. In OP's example, the start parameter makes i start at 1. Their C++17 example prints starting from 0. Probably a mistake. If you look at the linked page for C++20[0], other types can be put in the initializer statement, so it's unlikely the loop auto-increments. [0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p06...

So, it's just a while loop in a for loop's clothing? That's not going to be confusing for people at all...

No, it's a for loop that happens to include an unrelated variable declaration.

Re: C++20 Improved the For-Loop Syntax

#15
I am so happy I haven't written a line of C++ in like 15 years. Absolutely disgusting language. Every time I look up one of their new standards, I'm like how does anyone keep all of this in their head (usually on top of stuff like boost, etc.)? No wonder LLMs are a thing.

Re: C++20 Improved the For-Loop Syntax

#17

C++20 also has an enumerate() generator, so if you like the python syntax you can just do: for (auto [i,v] : std::views::enumerate(vec)) std::cout FWIW C++23 also has a python-like print and println: std::println("{}: {}", i, v);

The enumerate is a better solution than the one in the blog post.

Re: C++20 Improved the For-Loop Syntax

#19

> It seems to me that the C++ Standards Committee is doing a decent job maintaining the language, and introducing useful features when it makes sense to do so. This can’t be further from truth. C++ is essentially Frankenstein’s monster.

An articulate creature that hounds its creator for abandoning it?

If anything it is more of a Chimera

Re: C++20 Improved the For-Loop Syntax

#20

> It seems to me that the C++ Standards Committee is doing a decent job maintaining the language, and introducing useful features when it makes sense to do so. This can’t be further from truth. C++ is essentially Frankenstein’s monster.

And the real monster was the one who created it all along!
Post reply on HN