Shouldn't hasSwappableElements work on char arrays?

Jonathan M Davis jmdavisProg at gmx.com
Thu Feb 24 14:03:52 PST 2011


On Thursday, February 24, 2011 13:55:43 bearophile wrote:
> Steven Schveighoffer:
> > wait, you thought char[] was an array?  You poor poor soul ;)
> > 
> > I predict we shall get 1-2 questions/claims of incredulity like this a
> > month until we get a real string type.
> 
> There's a need for both unicode strings, and simpler strings of 7 bit ASCII
> chars (both mutable and immutable. The immutable ones must not allow to
> change their length. Their hashing value may be computed lazily even for
> the immutable strings). A ubyte[] is not a good enough replacement for an
> ASCII string. Even a puny language like Python3 has recognized this.

Honestly, I think that the need for actual ASCII strings is quite rare and that 
it _should_ not be encouraged. However, it would be trivial to declare wrappers 
for char and wchar (e.g. charRange and wcharRange) which actually use char or 
wchar as their element type if it's really needed. In most cases, however, using 
unicode strings is what should be happening, so the fact that char[] doesn't 
work as a range is a _good_ thing. The only real problem with it is the fact 
that foreach doesn't use dchar as its default iteration type when iterating over 
arrays of char or wchar.

- Jonathan M Davis


More information about the Digitalmars-d mailing list