summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/text/qchar.h15
-rw-r--r--tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp7
2 files changed, 22 insertions, 0 deletions
diff --git a/src/corelib/text/qchar.h b/src/corelib/text/qchar.h
index fb358ba8be..8a616b4c73 100644
--- a/src/corelib/text/qchar.h
+++ b/src/corelib/text/qchar.h
@@ -42,6 +42,8 @@
#include <QtCore/qglobal.h>
+#include <functional> // for std::hash
+
QT_BEGIN_NAMESPACE
@@ -664,4 +666,17 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QChar &);
QT_END_NAMESPACE
+namespace std {
+template <>
+struct hash<QT_PREPEND_NAMESPACE(QChar)>
+{
+ template <typename = void> // for transparent constexpr tracking
+ constexpr size_t operator()(QT_PREPEND_NAMESPACE(QChar) c) const
+ noexcept(noexcept(std::hash<char16_t>{}(u' ')))
+ {
+ return std::hash<char16_t>{}(c.unicode());
+ }
+};
+} // namespace std
+
#endif // QCHAR_H
diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
index fcd227f1bf..b2ec6e1c1c 100644
--- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
+++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
@@ -309,6 +309,13 @@ void tst_QHashFunctions::stdHash()
QCOMPARE(s.size(), 2UL);
}
+ {
+ std::unordered_set<QChar> s = {u'H', u'W'};
+ QCOMPARE(s.size(), 2UL);
+ s.insert(u'H');
+ QCOMPARE(s.size(), 2UL);
+ }
+
}
void tst_QHashFunctions::setGlobalQHashSeed()