summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-12-02 18:06:24 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-12-03 06:52:06 +0100
commit06957af4715df7eb6b447c75a1c0180b58c8accb (patch)
tree65340f33641d45f7a0eaff617c4475fd44332470 /src/corelib/tools
parent7a32a2d809a24345ab3ed93739a4f52aa5ce0f3d (diff)
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qduplicatetracker_p.h10
1 files changed, 9 insertions, 1 deletions
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(<memory_resource>) && __cplusplus > 201402L
# include <unordered_set>
# include <memory_resource>
+# include <qhash.h> // for the hashing helpers
#else
# include <qset.h>
#endif
@@ -64,9 +65,16 @@ QT_BEGIN_NAMESPACE
template <typename T, size_t Prealloc = 32>
class QDuplicateTracker {
#ifdef __cpp_lib_memory_resource
+ template <typename HT>
+ 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<T> set{&res};
+ std::pmr::unordered_set<T, QHasher<T>> set{&res};
#else
QSet<T> set;
int setSize = 0;