Why foreach(c; someString) must yield dchar

Rainer Deyke rainerd at eldwood.com
Thu Aug 19 16:52:48 PDT 2010


On 8/19/2010 03:56, Jonathan Davis wrote:
> The problem is that chars are not characters. They are UTF-8 code
> units.

So what?  You're acting like 'char' (and specifically 'char[]') is some
sort of unique special case.  In reality, it's just one case of encoded
data.  What about compressed data?  What about packed arrays of bits?
What about other containers?

There's a useful generic idiom for iterating over a sequence of A as if
it was a sequence of B: the adapter range.  Narrow strings aren't
special enough to deserve special language support.


-- 
Rainer Deyke - rainerd at eldwood.com


More information about the Digitalmars-d mailing list