String Type Usage. String vs DString vs WString

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Jan 15 15:32:39 UTC 2018


On Monday, January 15, 2018 14:56:33 Kagamin via Digitalmars-d-learn wrote:
> On Monday, 15 January 2018 at 06:18:27 UTC, SimonN wrote:
> > D's foreach and D's ranges will autodecode and silently iterate
> > over dchar, not char
>
> foreach doesn't do it silently, decoding must be requested from
> it by explicitly specifying element type, it can also encode this
> way.

Yeah, one of the joys of that is that you have to be careful of using
foreach in range-based functions, because if you haven't specialized for
strings, and you use foreach without specifying the element type, then when
your function template is instantiated with a string, the foreach won't
match what front does.

I really don't have any complaints about how foreach does this aside from
the fact that it doesn't currently use the replacement character (so, it
will throw on invalid Unicode if it's told to decode), but the way that
interacts with Phobos is poor.

Ideally, we'd get rid of auto-decoding, and we'd get rid of the whole
exception on bad Unicode thing and just use the replacement character, but
since changing it would break a lot of code... :|

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list