[Development] QHash iteration vs std::unordered_map
sergio.martins at kdab.com
Thu Apr 20 19:18:37 CEST 2017
On 2017-04-20 18:06, Matthew Woehlke wrote:
> On 2017-04-16 10:44, Corentin wrote:
>> If you want the same behavior, you can create a proxy for your
>> container instance, with a custom iterator whose operator*() returns a
>> pair ( or a QPair ) - quite a bit of boilterplate code.
> ...or use
> 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());
That doesn't work with temporaries, does it ?
Maybe something to fix in the C++ language, since the usual
lifetime-extension tricks don't help in this case.
Sérgio Martins | sergio.martins at kdab.com | Senior Software Engineer
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - The Qt, C++ and OpenGL Experts
More information about the Development