std.algorithm.remove and principle of least astonishment

klickverbot see at klickverbot.at
Sat Oct 16 12:56:12 PDT 2010


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.


More information about the Digitalmars-d mailing list