char array weirdness
Anon via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Mar 28 15:43:26 PDT 2016
On Monday, 28 March 2016 at 22:34:31 UTC, Jack Stouffer wrote:
> void main () {
> import std.range.primitives;
> char[] val = ['1', '0', 'h', '3', '6', 'm', '2', '8', 's'];
> pragma(msg, ElementEncodingType!(typeof(val)));
> pragma(msg, typeof(val.front));
> }
>
> prints
>
> char
> dchar
>
> Why?
Unicode! `char` is UTF-8, which means a character can be from 1
to 4 bytes. val.front gives a `dchar` (UTF-32), consuming those
bytes and giving you a sensible value.
More information about the Digitalmars-d-learn
mailing list