foreach for string[string]AA
Minty Fresh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 1 05:21:25 PST 2017
On Tuesday, 28 February 2017 at 18:16:45 UTC, Anton Pastukhov
wrote:
> On Tuesday, 28 February 2017 at 17:16:43 UTC, Daniel Kozák
> wrote:
>> V Tue, 28 Feb 2017 15:15:00 +0000
>> Anton Pastukhov via Digitalmars-d-learn
>> <digitalmars-d-learn at puremagic.com> napsáno:
>>
>>> I can't see the logic in AA foreach order. Consider this code:
>>> ...
>>> Output:
>>> three
>>> two
>>> one
>>> four
>>>
>>> I was sure output should be
>>> one
>>> two
>>> three
>>> four
>>
>> https://forum.dlang.org/post/xbanhtkvrizyqjcibsck@forum.dlang.org
>
> Thank you for the link, it was informative reading. It's a pity
> that still there is no ordered AA at least as a library type.
Ordered AA isn't that common a use case, and it's not without
overhead. You essentially need to store an array of keys that
define iteration order, which requires extra memory allocations
(and, depending on implementation, may slow down iteration as
well).
I come from a Ruby background, so I have found key order useful
in the past, but in most cases I probably could've gotten by just
fine with an array or set of element pairs.
Introduction of a more convenient tuple type into D might make
something like this easier.
More information about the Digitalmars-d-learn
mailing list