Why foreach(c; someString) must yield dchar
Kagamin
spam at here.lot
Fri Aug 20 11:35:38 PDT 2010
Jonathan M Davis Wrote:
> > Trivial: take byte and add 256.
>
> If you want to change the iteration type to int or
> long or whatever when iterating over bytes so that you can change the variable
> without overflow issues, you can. But the byte itself is meaingful by itself.
> Such is not generally the case with char or wchar.
I thought, it's your point that having a meaning doesn't help to avoid bugs.
> > If you care about people and want to force them to use dchar ranges, you
> > can do it with the library: make it refuse narrow strings - as long as the
> > library is unusable with narrow strings, people will have to do something
> > about it, say, use wrappers like one proposed in this thread (but
> > providing forward dchar range interface).
>
> We _can't_ force everyone to use dstring.
I'm talking not about dstrings, I said dchar range wrapper. Andrei mentioned byDchar, I don't know if that's the thing. Anyway, std.algorithm does iterate over dchars in narrow strings somehow. You can do it too.
More information about the Digitalmars-d
mailing list