Why foreach(c; someString) must yield dchar

Kagamin spam at here.lot
Thu Aug 19 07:13:25 PDT 2010


Jonathan Davis Wrote:

> bytes and shorts are legitimate values on their own, so it wouldn't
> make sense to give the type to foreach as long.

Having wider integer always has sense.

> byte or short on its own just fine.

Yes, but odds are that it's a bug. You can easily hit an overflow.

> So, it's almost a guarantee that the correct type for iterating over a
> string or wstring is dchar, not char or wchar. String types are just
> weird that way due to how multibyte unicode encodings work.

If you don't like narrow strings, don't use them. Use dstring. You are free to write what you want.

> So, since it makes so little sense to iterate over chars or wchars by default,
> it would make sense to make the default dchar.

It's an iteration over array items. This makes perfect sense.


More information about the Digitalmars-d mailing list