summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-11-27 17:39:10 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-11-30 17:16:22 +0100
commit81e893fb2d57b7f2d332f4f626e38f51acf43542 (patch)
treeb8bc1fc0a30a6419f75094433cdf52025e5f0da0 /src/corelib/doc/snippets
parent5dab710b90e7041aaa9fcf3631f2ca6af1baab5f (diff)
QHash: support std::hash as hashing function
In addition (and as a fallback) from requiring qHash, add support for std::hash specializations. This catches two birds with one stone: 1) users of Qt can simply specialize std::hash for their datatypes, and use them in both QHash and stdlib unordered associative containers; 2) we get QHash support for any (stdlib) datatype that is hashable without having to overload qHash for them. [ChangeLog][QtCore][QHash] QHash, QMultiHash and QSet now support for key types anything that can be hashed via std::hash, instead of always requiring a qHash() overload. Change-Id: Ib5ecba86e4b376d318389500bd24883ac6534c5f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
index 77981075a2..ee9f88fc65 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
@@ -350,3 +350,13 @@ size_t qHash(const K &key);
size_t qHash(K key, size_t seed);
size_t qHash(const K &key, size_t seed);
//! [32]
+
+//! [33]
+namespace std {
+template <> struct hash<K>
+{
+ // seed is optional
+ size_t operator()(const K &key, size_t seed = 0) const;
+};
+}
+//! [33]