From 81e893fb2d57b7f2d332f4f626e38f51acf43542 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 27 Nov 2020 17:39:10 +0100 Subject: 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 Reviewed-by: Lars Knoll Reviewed-by: Andrei Golubev --- src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp') 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 +{ + // seed is optional + size_t operator()(const K &key, size_t seed = 0) const; +}; +} +//! [33] -- cgit v1.2.3