qt6-bb10/tests/auto
Marc Mutz 4469e36d72 qhashfunctions.h: add specializations of std::hash for some Qt types
We have a problem. Our types don't play well with the std unordered
containers, because they do not specialize std::hash. We therefore
force our users to come up with an implementation, hindering
interoperability, since any two developers are unlikely to come up
with compatible implementations. So combining libraries written by
different developers will result in ODR violations.

Now that we depend on C++11, and thus the presence of std::hash, we
still face the problem that the standard does not provide us with a
means to compose new hash functions out of old ones. In particular, we
cannot, yet, depend on C++17's std::hash<std::string_view> to
implement std::hash<QByteArray>, say. There's also no std::hash for
std::tuple, which would allow easy composition by using std::tie().

So piggy-back on the work we have done over the years on qHash()
functions, and implement the std::hash specializations for Qt types
using the existing qHash() functions, with a twist: The standard
allows implementations to provide means against predictable hash
values. Qt has this, too, but the seed is managed by the container and
passed to the qHash() function as a separate argument. The standard
does not have this explicit seed, so any protection must be implicit
in the normal use of std::hash.

To reap whatever protection that std library has on offer, if any, we
calculate a seed value by hashing int(0). This will be subject to
constant folding if there's no actual seed, but will produce a value
dependent on the seed if there is one.

Add some tests.

A question that remains is how to document the specialization. Can we
have a \stdhashable QDoc macro that does everything for us?

Task-number: QTBUG-33428
Change-Id: Idfe775f1661f8489587353c4b148d76611ac76f3
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2019-05-29 11:22:20 +02:00
..
android
bic/data Add binary compatibility files for 5.12 for QtBase 2018-12-21 19:42:57 +00:00
cmake Export modules' enabled/disabled features to cmake 2018-09-28 13:10:28 +00:00
concurrent Remove handling of missing Q_COMPILER_INITIALIZER_LISTS 2019-05-02 23:10:55 +00:00
corelib qhashfunctions.h: add specializations of std::hash for some Qt types 2019-05-29 11:22:20 +02:00
dbus Merge remote-tracking branch 'origin/5.12' into 5.13 2019-02-19 01:00:08 +01:00
gui QTextMarkdownWriter: fix some bad cases with word wrap 2019-05-24 15:37:05 +02:00
guiapplauncher
installed_cmake
network Tests: Fix some warnings about deprecated functions not under test 2019-05-27 15:29:16 +02:00
opengl qWaitFor: Prevent being stuck in QCoreApplication::processEvents 2019-01-09 18:10:54 +00:00
other Handle missing enum value in test 2019-05-13 16:39:44 +00:00
printsupport Tests: Fix some warnings about deprecated functions not under test 2019-05-27 15:29:16 +02:00
shared Read font selection flags and use them when querying for metrics 2018-11-30 16:15:03 +00:00
sql QSqlError: fix redundant space in text() output 2019-03-26 06:12:10 +00:00
testlib Merge remote-tracking branch 'origin/5.13' into dev 2019-05-13 08:04:58 +02:00
tools Merge remote-tracking branch 'origin/5.13' into dev 2019-05-15 07:11:41 +02:00
widgets Merge remote-tracking branch 'origin/5.13' into dev 2019-05-27 15:34:10 +02:00
xml Prefix QTextStream operators with Qt:: in tests 2019-05-03 09:36:36 +00:00
auto.pro winrt: Skip network auto tests for now 2018-06-22 05:02:39 +00:00
network-settings.h Port tst_qtcpsocket to the docker server 2019-02-28 15:48:31 +00:00