<div dir="ltr">Very unlikely I'd say. Hashes are used all over the place in ppl' code and making this change will break way too much to be sensible.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 16, 2017 at 6:05 PM, Mark Gaiser <span dir="ltr"><<a href="mailto:markg85@gmail.com" target="_blank">markg85@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sun, Apr 16, 2017 at 4:44 PM, Corentin <<a href="mailto:corentin.jabot@gmail.com">corentin.jabot@gmail.com</a>> wrote:<br>
> Funny, a friend at kdab asked me about that exact question a few minutes<br>
> ago.<br>
> The reason for the difference is most certainly an historical one ( and<br>
> can't be changed because it would break quite a bit of code ).<br>
><br>
> If you want the same behavior, you can create a proxy for your associative<br>
> container instance, with a custom iterator whose operator*() returns a std<br>
> pair ( or a QPair ) - quite a bit of boilterplate code.<br>
<br>
</span>It probably does come down to historic reasons, but that would be<br>
strange as well.<br>
I doubt that the C++ committee changed what is returned by operator*()<br>
(correct me if i'm wrong) so i'm inclined to think that the<br>
std::<container> stuff is returning it as an std::pair for quite a<br>
while now.<br>
That again makes me wonder, why did Qt diverge from that?<br>
<br>
And... if Qt plans to change it in Qt6?<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
><br>
><br>
><br>
> Le dim. 16 avr. 2017 à 15:57, Mark Gaiser <<a href="mailto:markg85@gmail.com">markg85@gmail.com</a>> a écrit :<br>
>><br>
>> Hi,<br>
>><br>
>> Take this simple example:<br>
>><br>
>>   QHash<int, QString> test = {<br>
>>     {10, "aaa"},<br>
>>     {20, "bbb"},<br>
>>     {30, "ccc"}<br>
>>   };<br>
>><br>
>>   for (const auto &entry: qAsConst(test)) {<br>
>>     qDebug() << entry;<br>
>>   }<br>
>><br>
>> It returns:<br>
>> "aaa"<br>
>> "ccc"<br>
>> "bbb"<br>
>><br>
>> and the std::unordered_map version:<br>
>>   std::unordered_map<int, QString> test = {<br>
>>     {10, "aaa"},<br>
>>     {20, "bbb"},<br>
>>     {30, "ccc"}<br>
>>   };<br>
>><br>
>>   for (const auto &entry: test) {<br>
>>     qDebug() << entry;<br>
>>   }<br>
>><br>
>> it returns:<br>
>> std::pair(30,"ccc")<br>
>> std::pair(10,"aaa")<br>
>> std::pair(20,"bbb")<br>
>><br>
>> As you can see, the QHash iteration directly returns the value. The<br>
>> std::unordered_map returns a std::par with the key and value for the<br>
>> current iteration (in it's respective first and second members). Both<br>
>> approaches probably have arguments in favor and against. What i'm<br>
>> curious about is why there is a difference at all?<br>
>><br>
>> I'm curious because the behavior is a bit unexpected when compared to<br>
>> std::unordered_map. I would have guessed QHash to follow the same<br>
>> logic as std::unordered_map, only with a Qt syntax. So for instance a<br>
>> return of QPair(...), not the value directly.<br>
>><br>
>> Thanks,<br>
>> Mark<br>
>> ______________________________<wbr>_________________<br>
>> Development mailing list<br>
>> <a href="mailto:Development@qt-project.org">Development@qt-project.org</a><br>
>> <a href="http://lists.qt-project.org/mailman/listinfo/development" rel="noreferrer" target="_blank">http://lists.qt-project.org/<wbr>mailman/listinfo/development</a><br>
______________________________<wbr>_________________<br>
Development mailing list<br>
<a href="mailto:Development@qt-project.org">Development@qt-project.org</a><br>
<a href="http://lists.qt-project.org/mailman/listinfo/development" rel="noreferrer" target="_blank">http://lists.qt-project.org/<wbr>mailman/listinfo/development</a><br>
</div></div></blockquote></div><br></div>