AA behaves differently in CTFE?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 24 16:25:12 PST 2015


On 11/24/15 2:43 PM, Bastiaan Veelo wrote:
> On Tuesday, 24 November 2015 at 14:23:38 UTC, Steven Schveighoffer wrote:
>> If CTFE associative arrays perform differently, then that is a bug. I
>> am not sure if this is the case, but you should file a bug anyway,
>> someone can take a look at it.
>>
>> If you can narrow it down to a minimal case where it breaks down, that
>> would be helpful.
>>
>> -Steve
>
> Thanks. After narrowing it down further I discovered a mistake in my
> code, which caused undesired behaviour dependent on the order in which
> elements on an AA are traversed by foreach.
>
> As it turns out, the order in which foreach traverses elements of an AA
> at compile time differs from the order at run time. So yes, associative
> arrays behave differently, but it is hardly a bug since "in a foreach
> loop the order in which the elements are iterated is unspecified." [1]
>
> [1] http://dlang.org/hash-map.html

Ah yes, that is very true.

Thanks for looking at it further!

If you need traversal to be consistent, there is std.container.rbtree, 
but it's not very friendly to use as a map.

-Steve


More information about the Digitalmars-d-learn mailing list