"tuple unpacking" with zip?
Shriramana Sharma via Digitalmars-d
digitalmars-d at puremagic.com
Wed Oct 21 07:13:37 PDT 2015
John Colvin wrote:
>> But this is false, no? Since ElementType!string is char and not
>> dchar?
>
> No. char[], wchar[] and dchar[] all have ElementType dchar.
> Strings are special for ranges. It's a bad mistake, but it is
> what it is and apparently won't be changed.
Why is it a mistake? That seems a very sane thing, although somewhat quirky.
Since ElementType is a Range primitive, and apparently iterating through a
string as a range will produce each semantically meaningful Unicode
character rather than each UTF-8 or UTF-16 codepoint, it does make sense to
do this.
>>> foreach(int i, dchar c; zip(ints, chars))
>>> or
>>> foreach(i, c; zip(ints, chars))
>>
>> What's the diff betn char and dchar in this particular context?
>
> See http://dlang.org/type.html and
> http://dlang.org/arrays.html#strings
Actually I found the explanation at
http://dlang.org/phobos/std_range_primitives.html#ElementType.
--
Shriramana Sharma, Penguin #395953
More information about the Digitalmars-d
mailing list