[Development] QHash iteration vs std::unordered_map

Matthew Woehlke mwoehlke.floss at gmail.com
Thu Apr 20 19:06:38 CEST 2017


On 2017-04-16 10:44, Corentin wrote:
> If you want the same behavior, you can create a proxy for your associative
> container instance, with a custom iterator whose operator*() returns a std
> pair ( or a QPair ) - quite a bit of boilterplate code.

...or use
https://github.com/Kitware/qtextensions/blob/master/core/qtEnumerate.h.
Rather than returning a pair (which may add overhead), it creates a
proxy that just returns the iterator, so you can write:

  for (auto i : qtEnumerate(my_hash))
    do_stuff(i.key(), i.value());

As a plus, `key()` and `value()` are much more readable than `first` and
`second`.

-- 
Matthew




More information about the Development mailing list