Earlier quoted context omitted.
The part that confuses me is that they use “it” to name a variable that is not actually an iterator. That’s very bad style. I would name it “s”.
It's "it" as in the pronoun, not as in "iterator".
C++20 Improved the For-Loop Syntax
71–80 of 89 posts
Re: C++20 Improved the For-Loop Syntax
#72Earlier quoted context omitted.
Go is similar: package main import "fmt" var vec = []string{"the", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog"} func main() { for i, s := range vec { fmt.Printf("%d: %s\n", i, s) } } Using `fmt.Println(i, ":", s)` inserts spaces on both sides of the colon, so the output is not quite right. I find Go's `range` syntax easier to read than D's `(i, s; vec)` -- although generator functions that work wi…
D has several usages for `foreach` depending on the number and type of its arguments. In this case, it sees that `vec` is an array, and so constructs a loop over the array. If `vec` was a range, the loop will be constructed as a loop over the array. It's nice because it makes the syntax for arrays and ranges interchangeable, making for easy refactoring.
Re: C++20 Improved the For-Loop Syntax
#73C++ should copy D's elegance: import std.stdio; string[9] vec = [ "the", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog" ]; void main() { foreach (i, s; vec) writeln(i, ": ", s); }
C++23 example, import std; using namespace std; int main() { vector vec = { "the", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog" }; for (auto&& [i, it] : vec | std::views::enumerate) println ("{}:{}", ++i, it); } As I keep mentioning, the features being copied, slowly erode D's relevance.
Re: C++20 Improved the For-Loop Syntax
#74C++ should copy D's elegance: import std.stdio; string[9] vec = [ "the", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog" ]; void main() { foreach (i, s; vec) writeln(i, ": ", s); }
Go is similar: package main import "fmt" var vec = []string{"the", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog"} func main() { for i, s := range vec { fmt.Printf("%d: %s\n", i, s) } } Using `fmt.Println(i, ":", s)` inserts spaces on both sides of the colon, so the output is not quite right. I find Go's `range` syntax easier to read than D's `(i, s; vec)` -- although generator functions that work wi…
Re: C++20 Improved the For-Loop Syntax
#75Earlier quoted context omitted.
What exactly is your complaint with it? `auto&&` has been standard syntax in C++ for going on 15 years now and has a very clear, irreplaceable meaning - a type-deduced forward reference - to any remotely competent developer.
I think C++ needs more of `:`, `::` and maybe new operators `&&&` and `&&&&`.
for [auto&&&&]:::static (std::for_enumeration_initializer &&⁢ @auto: {{const signed&&&&& i const}}) { }Re: C++20 Improved the For-Loop Syntax
#76Re: C++20 Improved the For-Loop Syntax
#77Reading this, I really can't make much sense of it: for (int i=0; auto&& it: vec) cout It's certainly not obvious what's going on there at a glance. This is at least a bit more pythonic: for (auto [i, it] : std::views::enumerate(vec)) { std::cout
The part that confuses me is that they use “it” to name a variable that is not actually an iterator. That’s very bad style. I would name it “s”.
Re: C++20 Improved the For-Loop Syntax
#78Earlier quoted context omitted.
I believe one of the main goals of whatever shadowy organizations are behind the "standards committee" is to sabotage the language to help clear the way for Rust. If these people really have a great idea for what the future C++ should be like, then they should introduce that language all at once. Let us see their grand vision in one big package that can be embraced or rejected. This steady drip-drip-drip of half-bake…
The same organisations are behind Rust Foundation, and are responsible for the LLVM and GCC compilers, written in C++, rustc depends on.
Re: C++20 Improved the For-Loop Syntax
#79Earlier quoted context omitted.
> std::cout C++ needs to abandon iostreams. Didn't the C++ community acknowledge that it was a bad idea? In the early days of D, people did want to do a version of it for D, but I objected and currently nobody wants it.
Some folks don't like iostreams, I keep using them, since Turbo C++ 1.0 for MS-DOS. Although I would probably use std::print in more modern compilers. D needs to work into its marketing, all key features that made it relevant back in 2011 with Andrei's book have now been copied even if badly, across all mainstream languages.
I thought it was ugly in 1987, and it hasn't improved with age. Then for templates made it worse.
Then there's formatted I/O:
void IOS_precision()
{
cout
and I don't know if the problem with multithreading was resolved or not.> copied even if badly
Any program can be written in any language. But why suffer?
Re: C++20 Improved the For-Loop Syntax
#80C++ should copy D's elegance: import std.stdio; string[9] vec = [ "the", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog" ]; void main() { foreach (i, s; vec) writeln(i, ": ", s); }
C++23 example, import std; using namespace std; int main() { vector vec = { "the", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog" }; for (auto&& [i, it] : vec | std::views::enumerate) println ("{}:{}", ++i, it); } As I keep mentioning, the features being copied, slowly erode D's relevance.
for (auto&& [i, it] : vec | std::views::enumerate)
println ("{}:{}", ++i, it);
instead of: foreach (i, s; vec)
writeln(i, ": ", s);
well, what can I say?