Why is string.front dchar?

Tobias Pankrath tobias at pankrath.net
Mon Jan 20 05:30:10 PST 2014


> Same reasons which prevent sane person from being OK with int[] 
> number = [3.14l] should prevent him from being OK with string s 
> = "säд"

No, since this literal can be encoded as utf8 just fine. Keep in 
mind that literals are nothing else as values written directly 
into the source. And as is happens your example is a perfect 
value of type string.

(w|d)string.length returning anything else then the number of 
underlying code points would be inconsistent to other array types 
and m aking (d|w)string arrays of code points was a (arguably 
good) design decision.

That said: nothing prevents you from writing another string type 
that abstracts from the actual string encoding.


Phobos did it wrong though with handling char[] different from 
T[].


More information about the Digitalmars-d-learn mailing list