QChar: make std::hash'able
Change-Id: I2164df19cd17ab96a39020de66a3fe9fec838a36 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>bb10
parent
0bed456f47
commit
900e8b023b
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue