Hi,
Take this simple example:
QHash<int, QString> test = {
{10, "aaa"},
{20, "bbb"},
{30, "ccc"}
};
for (const auto &entry: qAsConst(test)) {
qDebug() << entry;
}
It returns:
"aaa"
"ccc"
"bbb"
and the std::unordered_map version:
std::unordered_map<int, QString> test = {
{10, "aaa"},
{20, "bbb"},
{30, "ccc"}
};
for (const auto &entry: test) {
qDebug() << entry;
}
it returns:
std::pair(30,"ccc")
std::pair(10,"aaa")
std::pair(20,"bbb")
As you can see, the QHash iteration directly returns the value. The
std::unordered_map returns a std::par with the key and value for the
current iteration (in it's respective first and second members). Both
approaches probably have arguments in favor and against. What i'm
curious about is why there is a difference at all?
I'm curious because the behavior is a bit unexpected when compared to
std::unordered_map. I would have guessed QHash to follow the same
logic as std::unordered_map, only with a Qt syntax. So for instance a
return of QPair(...), not the value directly.
Thanks,
Mark
_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development