Find in assoc array then iterate

Sergey kornburn at yandex.ru
Fri Oct 21 22:16:21 UTC 2022


On Friday, 21 October 2022 at 22:03:53 UTC, Kevin Bailey wrote:
> I'm trying to do this equivalent C++:
>
>     unordered_map<string, int> map;
>
>     for (auto i = map.find(something); i != map.end(); ++i)
>         ...do something with i...
>
> in D, but obviously with an associative array. It seems that 
> it's quite
> easy to iterate through the whole "map", but not start from the 
> middle.
> Am I missing something obvious (or not so obvious) ?

How should that work, if map is unordered?

In D:
Implementation Defined: The built-in associative arrays do not 
preserve the order of the keys inserted into the array. In 
particular, in a foreach loop the order in which the elements are 
iterated is typically unspecified.
https://dlang.org/spec/hash-map.html


More information about the Digitalmars-d-learn mailing list