std.algorithm.remove and principle of least astonishment

Pelle pelle.mansson at gmail.com
Sat Oct 16 14:08:14 PDT 2010


On 10/16/2010 09:56 PM, klickverbot wrote:
> On 10/16/10 9:47 PM, Andrei Alexandrescu wrote:
>> Thanks for the input. This is not a bug, it's what I believe to be a
>> very intentional feature: strings are not ordinary arrays because
>> characters have variable length. As such, assigning to "the first
>> character in a string" is not allowed because the assignment might mess
>> up the next character.
>
> I see that there is a problem due the difference of code units and code
> points, but why does the following work then?
>
> tmp = tmp[ 0 .. i ] ~ tmp[ ( i + 1 ) .. $ ];
>
> This is equivalent to my (naïve?) mental model of remove(), and thus it
> seems very counter-intuitive to me that one works, but the other doesn't.

Try it with ä or ░ instead of x.


More information about the Digitalmars-d mailing list