Shouldn't hasSwappableElements work on char arrays?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Feb 24 13:28:20 PST 2011


On 2/24/11 3:13 PM, Jesse Phillips wrote:
> Andrej Mitrovic Wrote:
>
>> Yes. And you know what's going to happen next, right? Everyone is
>> going to create their own implementation of a string type because of
>> these non-issues. Happens in C/C++ all the time, I see it in almost
>> every mid-large codebase out there.
>
> Well, aside from discussions to create a proper string type, Text in Tango and mText on dprogramming.org I have yet to see people using a special string type.
>
> I'm not sure why you are complaining that compiler is preventing you from doing something stupid. An array of char is not swappable, a range of char is not swappable. D is not in the habit of hiding complexity, trying to swap a string requires a conversion to dchar or at least handling a sequence of char so it is best to state that is what is happening in the code.

Swapping a char[] correctly (preserving the proper code units) without 
using additional storage is a very interesting problem.

Andrei


More information about the Digitalmars-d mailing list