Re:C++20 Improved the For-Loop Syntax
by xigoi on Wednesday July 15, 2026 @09:35AM
(#48920637)
I find Go’s version worse in that it does not allow you to elide the index (which is not needed most of the time). You have to write `for _, s := range vec`, as `for s := range vec` makes s the index.
[ Parent
| on HN ]
Re:C++20 Improved the For-Loop Syntax
by WalterBright on Wednesday July 15, 2026 @01:39PM
(#48924429)
To clarify,
foreach (s; vec)
works if you don't need the index. To be able to modify s in place: foreach (ref s; vec) s = "replacement";