String Type Usage. String vs DString vs WString

SimonN eiderdaus at gmail.com
Mon Jan 15 15:38:46 UTC 2018


On Monday, 15 January 2018 at 14:44:46 UTC, Adam D. Ruppe wrote:
> On Monday, 15 January 2018 at 06:18:27 UTC, SimonN wrote:
>> D's foreach [...] will autodecode and silently iterate over 
>> dchar, not char, even when the input is string
>
> That's not true. foreach will only decode on demand:
> foreach(c; s) { /* c is a char here, it goes over bytes */ }

Thanks for the correction! Surprised I got foreach(c, s) wrong, 
its non-decoding iteration is even the prominent example in TDPL.

Even `each`, the template function that implements a foreach, 
still infers as char:

     "aä".each!writeln; // prints a plus two broken characters

Only `map`



When I wrote "D's ranges", I meant Phobos's range-producing 
templates; a range itself is again encoding-agnostic.


More information about the Digitalmars-d-learn mailing list