Go to file
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
bin syncqt: Fix resolution of injected headers for external modules 2019-04-23 09:09:33 +00:00
config.tests x86: Disable AVX support on 64-bit MinGW 2019-02-06 08:11:29 +00:00
dist Merge remote-tracking branch 'origin/5.12' into 5.13 2019-04-24 01:00:13 +02:00
doc Merge remote-tracking branch 'origin/5.12' into 5.13 2019-05-27 09:17:14 +02:00
examples Torrent example: replace a QMultiMap with a sorted vector 2019-05-25 09:30:51 +00:00
lib
mkspecs Merge remote-tracking branch 'origin/5.13' into dev 2019-05-27 15:34:10 +02:00
qmake Do not ignore exit codes of install commands 2019-05-23 11:06:48 +02:00
src qhashfunctions.h: add specializations of std::hash for some Qt types 2019-05-29 11:22:20 +02:00
tests qhashfunctions.h: add specializations of std::hash for some Qt types 2019-05-29 11:22:20 +02:00
util Add locale support for Cebuano and Erzya languages (new in CLDR v35.1) 2019-05-20 20:42:11 +02:00
.gitattributes
.gitignore Remove support for qml1 plugins and modules 2018-11-15 19:52:13 +00:00
.qmake.conf Bump version 2019-03-22 05:35:40 +00:00
.tag
config_help.txt Android: Nuke mips architectures 2019-05-06 08:01:04 +00:00
configure configure: Treat win32-clang-g++ the same as win32-g++ 2018-10-10 04:10:40 +00:00
configure.bat Configure: simplify logic 2019-03-14 12:13:58 +00:00
configure.json rtems: Disable features which RTEMS does not support 2019-05-14 13:53:35 +02:00
configure.pri Add qmake support for c++2a 2019-04-19 08:14:25 +00:00
header.BSD
header.COMM
header.FDL
header.GPL
header.GPL-EXCEPT
header.LGPL
header.LGPL3
header.LGPL3-COMM
header.LGPL-NOGPL2
header.LGPL-ONLY
header.MIT qsimd: add support for new x86 CPU features 2018-05-05 06:20:07 +00:00
INSTALL INSTALL: Remove outdated reference to Windows CE 2019-02-13 13:01:57 +00:00
LICENSE.FDL
LICENSE.GPL2
LICENSE.GPL3
LICENSE.GPL3-EXCEPT
LICENSE.LGPL3
LICENSE.LGPLv3
LICENSE.QT-LICENSE-AGREEMENT-4.0 Replace commercial preview license with Qt License Agreement 4.0 2018-06-21 11:39:15 +00:00
qtbase.pro
sync.profile platformsupport/input: add xkbcommon utilities lib 2019-03-01 14:31:28 +00:00