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.

Reply via email to