Char representation

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 22 05:32:45 PST 2016


On 23/11/2016 2:29 AM, RazvanN wrote:
> Given the following code:
>
>  char[5] a = ['a', 'b', 'c', 'd', 'e'];
>  alias Range = char[];
>  writeln(is(ElementType!Range == char));
>
> One would expect that the program will print true. In fact, it prints
> false and I noticed that if Range is char[], wchar[], dchar[], string,
> wstring, dstring
> Unqual!(ElementType!Range) is dchar. I find it odd that the internal
> representation for char and string is dchar. Is this a bug?

"For example, ElementType!(T[]) is T if T[] isn't a narrow string; if it 
is, the element type is dchar"[0].

[0] https://dlang.org/phobos/std_range_primitives.html#ElementType


More information about the Digitalmars-d-learn mailing list