String Type Usage. String vs DString vs WString

Adam D. Ruppe destructionator at gmail.com
Mon Jan 15 14:44:46 UTC 2018


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:

string s;

foreach(c; s) { /* c is a char here, it goes over bytes */ }
foreach(char c; s) { /* c is a char here, same as above */ }
foreach(dchar c; s) { /* c is a dchar - this decodes */ }



Autodecoding is a Phobos library artifact, NOT something in the D 
language itself.


More information about the Digitalmars-d-learn mailing list