Why ElementType!(char[3]) == dchar instead of char?

Justin Whear via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 1 09:32:05 PDT 2015


On Tue, 01 Sep 2015 16:25:53 +0000, Justin Whear wrote:

> On Tue, 01 Sep 2015 19:18:42 +0300, drug wrote:
> 
>> http://dpaste.dzfl.pl/4535c5c03126
> 
> Arrays of char are assumed to be UTF-8 encoded text and a single char is
> not necessarily sufficient to represent a character.  ElementType
> identifies the type that you will receive when (for instance) foreaching
> over the array and D autodecodes the UTF-8 for you.  If you'd like to
> represent raw bytes use byte[3] or ubyte[3].  If you'd like other
> encodings, check out std.encoding.

I should correct this:
 * ForeachType is the element type that will inferred by a foreach loop
 * ElementType is usually the same as ForeachType but is the type of the 
value returned by .front

One major distinction is that ElementType is only for ranges while 
ForeachType will work for iterable non-ranges.


More information about the Digitalmars-d-learn mailing list