From 06957af4715df7eb6b447c75a1c0180b58c8accb Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 2 Dec 2020 18:06:24 +0100 Subject: [PATCH] QDuplicateTracker: allow usage of qHash The codepath using unordered_set forced the usage of std::hash, which isn't provided by many Qt types. Instead, use the brand new helpers in QHash that dispatch to qHash with a fallback on std::hash. Change-Id: I9185fe9c52de05c470afe7466007591977e65bb1 Reviewed-by: Thiago Macieira --- src/corelib/tools/qduplicatetracker_p.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qduplicatetracker_p.h b/src/corelib/tools/qduplicatetracker_p.h index 817d259d23..c21b67ffa3 100644 --- a/src/corelib/tools/qduplicatetracker_p.h +++ b/src/corelib/tools/qduplicatetracker_p.h @@ -55,6 +55,7 @@ #if QT_HAS_INCLUDE() && __cplusplus > 201402L # include # include +# include // for the hashing helpers #else # include #endif @@ -64,9 +65,16 @@ QT_BEGIN_NAMESPACE template class QDuplicateTracker { #ifdef __cpp_lib_memory_resource + template + struct QHasher { + size_t operator()(const HT &t) const { + return QHashPrivate::calculateHash(t, qGlobalQHashSeed()); + } + }; + char buffer[Prealloc * sizeof(T)]; std::pmr::monotonic_buffer_resource res{buffer, sizeof buffer}; - std::pmr::unordered_set set{&res}; + std::pmr::unordered_set> set{&res}; #else QSet set; int setSize = 0;