dmd foreach loops throw exceptions on invalid UTF sequences, use replacementDchar instead

max haughton maxhaton at gmail.com
Mon Nov 8 22:12:15 UTC 2021


On Monday, 8 November 2021 at 14:29:47 UTC, Atila Neves wrote:
> On Friday, 5 November 2021 at 12:38:36 UTC, max haughton wrote:
>> On Friday, 5 November 2021 at 06:15:44 UTC, Walter Bright 
>> wrote:
>>> On 11/4/2021 9:11 PM, max haughton wrote:
>>>> On Friday, 5 November 2021 at 04:02:44 UTC, Walter Bright 
>>>> wrote:
>>>>> [...]
>>>> 
>>>> I have never observed this mistake in any C++ cod,
>>>
>>> You've never observed people write:
>>>
>>>    int array[3];
>>>
>>> in C++ code?
>>>
>>>> unless you mean as a point of language design.
>>>
>>> D (still) has a rather verbose way of doing lambdas. People 
>>> constantly complained that D didn't have lambdas. Until the 
>>> => syntax was added, and suddenly lambdas in D became noticed 
>>> and useful.
>>>
>>>
>>>> This decision should be guided by how current D programmers 
>>>> act rather than a hyperreal ideal of someone encountering 
>>>> the language.
>>>
>>> The only reason D's associative arrays continue to exist is 
>>> because they are so darned syntactically convenient.
>>>
>>> I've seen over and over and over that syntactic convenience 
>>> matters a lot.
>>
>> is what I meant, vector doesn't do the same thing as [].
>
> Aside from not depending on GC-allocated memory, what does 
> vector do that [] doesn't?
>
>> It's more common in (so-called) modern C++ to see std::array 
>> these days than a raw static array in certain contexts since 
>> you still  want a constant length buffer but want iterators 
>> etc..
>
>     int src[10]{};
>     int dst[10]{};
>     transform(begin(src), end(src), begin(dst), [](int i) { 
> return i + 1; });
>     for(const auto i: dst)
>         cout << i << " ";
>     cout << endl;
>
>
> But yes, std::array is an option that's better, but legacy code 
> means C arrays have to be supported.

In my post I was referring to a C style array (in C++) rather 
than a D slice, to be clear. It's entirely possible Walter 
originally meant a slice, but the point about following the 
syntactic path of least resistance seem to be referring to a [] 
in C++ rather than a slice i.e. I was intending to get across 
that I've never seen someone making this mistake in practice 
(either using a mere [] to pass data around, or using a vector in 
place of a static array / vice versa )


More information about the Digitalmars-d mailing list