Odd behaviour of std.range
Paul Backus
snarwin at gmail.com
Tue Feb 22 12:53:39 UTC 2022
On Tuesday, 22 February 2022 at 12:48:21 UTC, frame wrote:
> What am I missing here? Is this some UTF conversion issue?
>
> ```d
> string a;
> char[] b;
>
> pragma(msg, typeof(a.take(1).front)); // dchar
> pragma(msg, typeof(b.take(1).front)); // dchar
> ```
This is a feature of the D standard library known as "auto
decoding":
> as a convenience, when iterating over a string using the range
> functions, each element of strings and wstrings is converted
> into a UTF-32 code-point as each item. This practice, known as
> auto decoding, means that
>
> `static assert(is(typeof(utf8.front) == dchar));`
Source: https://tour.dlang.org/tour/en/gems/unicode
More information about the Digitalmars-d-learn
mailing list