C++ still doesn't have good loop syntax
Quirin Schroll
qs.il.paperinik at gmail.com
Tue Jul 21 10:09:50 UTC 2026
On Wednesday, 15 July 2026 at 15:00:13 UTC, Meta wrote:
> On Wednesday, 15 July 2026 at 01:43:56 UTC, Walter Bright wrote:
>> ```d
>> import std.stdio;
>>
>> string[9] vec = [
>> "the", "quick", "brown", "fox",
>> "jumped", "over", "the", "lazy", "dog"
>> ];
>>
>> void main()
>> {
>> foreach (i, s; vec)
>> writeln(i, ": ", s);
>> }
>> ```
>> https://news.ycombinator.com/item?id=48915184
>>
>> ```C++
>> vector<string> vec = {
>> "the", "quick", "brown", "fox",
>> "jumped", "over", "the", "lazy", "dog"
>> };
>>
>>
>>
>> for (int i=0; auto&& it: vec)
>> cout << (++i) << ": " << it << endl;
>> ```
>> https://lzon.ca/posts/tips/cpp-for-range-init/
>
> Hoping we can someday make the D example even better with
> static static array length inference 👌
>
> ```d
> string[$] vec = [ ... ]; // or some equivalent syntax
> ```
D’s going to have it soon:
https://dlang.org/changelog/pending.html#dmd.sarr-length-infer
More information about the Digitalmars-d
mailing list