qt5base-lts/tests/auto/corelib/tools
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
..
collections Deprecate conversion functions between QList and QSet 2019-05-07 14:15:44 +00:00
containerapisymmetry Remove handling of missing Q_COMPILER_INITIALIZER_LISTS 2019-05-02 23:10:55 +00:00
qalgorithms Prefix QTextStream operators with Qt:: in tests 2019-05-03 09:36:36 +00:00
qarraydata Remove handling of missing Q_COMPILER_RVALUE_REFS 2019-05-01 20:24:45 +00:00
qarraydata_strictiterators
qbitarray
qbytearray Remove handling of missing very old compiler feature check 2019-04-06 13:27:15 +00:00
qbytearraylist Remove handling of missing Q_COMPILER_INITIALIZER_LISTS 2019-05-02 23:10:55 +00:00
qbytearraymatcher
qbytedatabuffer
qcache
qchar Merge remote-tracking branch 'origin/5.9' into 5.11 2018-02-14 12:51:24 +01:00
qcollator Remove handling of missing Q_COMPILER_RVALUE_REFS 2019-05-01 20:24:45 +00:00
qcommandlineparser Remove handling of missing Q_COMPILER_INITIALIZER_LISTS 2019-05-02 23:10:55 +00:00
qcontiguouscache Replace qMove with std::move 2019-04-06 11:00:38 +00:00
qcryptographichash QCryptographicHash: Add a static method to retrieve hash length 2018-04-10 12:17:43 +00:00
qdate Add startOfDay() and endOfDay() methods to QDate 2019-04-24 13:09:26 +00:00
qdatetime Tidy up in tst_QDateTime 2019-05-22 15:43:28 +02:00
qeasingcurve Remove handling of missing Q_COMPILER_RVALUE_REFS 2019-05-01 20:24:45 +00:00
qexplicitlyshareddatapointer Add nullptr comparison to Q{Explicitly,}SharedDataPointer 2018-03-18 17:28:26 +00:00
qfreelist
qhash Remove handling of missing Q_COMPILER_INITIALIZER_LISTS 2019-05-02 23:10:55 +00:00
qhash_strictiterators
qhashfunctions qhashfunctions.h: add specializations of std::hash for some Qt types 2019-05-29 11:22:20 +02:00
qlatin1string
qline QLineF: add intersects() as a replacement for intersect() 2019-04-25 17:58:40 +00:00
qlinkedlist Remove handling of missing Q_COMPILER_INITIALIZER_LISTS 2019-05-02 23:10:55 +00:00
qlist Deprecate conversion functions between QList and QSet 2019-05-07 14:15:44 +00:00
qlist_strictiterators
qlocale Tests: Fix some warnings about deprecated functions not under test 2019-05-27 15:29:16 +02:00
qmacautoreleasepool Add missing dependencies for tst_qmacautoreleasepool 2018-08-29 02:47:45 +00:00
qmakearray corelib/tools: add qMakeArray() API 2018-07-25 06:57:44 +00:00
qmap Remove handling of missing Q_COMPILER_INITIALIZER_LISTS 2019-05-02 23:10:55 +00:00
qmap_strictiterators
qmargins
qmessageauthenticationcode
qoffsetstringarray corelib/tools: Fix auto detection of QOffsetStringArray::m_offset type 2018-08-28 14:42:46 +00:00
qpair core: Add deduction guides for QPair 2019-03-25 19:48:29 +00:00
qpoint
qpointf Fix regression in QPointF::operator== 2018-07-09 15:38:31 +00:00
qqueue
qrect
qregexp
qregularexpression QRegularExpression: anchor wildcard pattern 2018-12-15 13:24:16 +00:00
qringbuffer QRingBuffer: avoid reallocations of the data 2017-12-30 10:15:10 +00:00
qscopedpointer
qscopedvaluerollback Use move more consistently in QScopedValueRollback 2019-03-27 07:56:15 +00:00
qscopeguard Introduce QScopeGuard 2018-07-21 17:47:35 +00:00
qset Remove handling of missing Q_COMPILER_INITIALIZER_LISTS 2019-05-02 23:10:55 +00:00
qsharedpointer Remove handling of missing Q_COMPILER_RVALUE_REFS 2019-05-01 20:24:45 +00:00
qsize
qsizef
qstl
qstring Remove handling of missing very old compiler feature check 2019-04-06 13:27:15 +00:00
qstring_no_cast_from_bytearray
qstringapisymmetry Merge remote-tracking branch 'origin/5.13' into dev 2019-05-27 15:34:10 +02:00
qstringbuilder QStringBuilder: add support for QStringView 2018-01-08 09:41:43 +00:00
qstringiterator
qstringlist Remove handling of missing Q_COMPILER_INITIALIZER_LISTS 2019-05-02 23:10:55 +00:00
qstringmatcher QStringMatcher: add QStringView support 2019-03-14 04:48:06 +00:00
qstringref
qstringview QStringView: Add compare() member function 2018-07-13 13:32:34 +00:00
qtextboundaryfinder Merge remote-tracking branch 'origin/5.9' into 5.11 2018-02-14 12:51:24 +01:00
qtime Use the QTime API less clumsily 2019-04-01 14:39:34 +00:00
qtimeline Extend blacklisting of qtimeline::frameRate to macOS 10.13 2018-09-24 21:13:00 +00:00
qtimezone Support POSIX rules as $TZ values 2019-05-10 14:17:01 +00:00
qvarlengtharray Remove handling of missing Q_COMPILER_INITIALIZER_LISTS 2019-05-02 23:10:55 +00:00
qvector Add swapItemsAt() to QVector 2019-05-07 14:15:37 +00:00
qvector_strictiterators
qversionnumber Remove handling of missing Q_COMPILER_INITIALIZER_LISTS 2019-05-02 23:10:55 +00:00
tools.pro Add missing test to project file 2019-04-02 12:43:06 +00:00