QFlags: add qHash overload

Stop going through the implicit int conversion.

[ChangeLog][QtCore][QFlags] QFlags now has a qHash() overload.

Change-Id: Id380ed252695f24af2e8c239b650dcb6f44e2893
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Giuseppe D'Angelo 2021-05-01 18:03:41 +02:00
parent e906bb84fb
commit ddee595d58
2 changed files with 13 additions and 0 deletions

View File

@ -515,6 +515,15 @@ static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined");
\sa Int
*/
/*!
\fn template <typename Enum> size_t qHash(QFlags<Enum> flags, size_t seed = 0) noexcept
\since 6.2
\relates QFlags
Calculates the hash for the flags \a flags, using \a seed
to seed the calcualtion.
*/
/*!
\macro Q_DISABLE_COPY(Class)
\relates QObject

View File

@ -175,6 +175,10 @@ Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(QKeyCombination key, size_t
{ return qHash(key.toCombined(), seed); }
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(QStringView key, uint chained = 0) noexcept;
template <typename Enum>
Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(QFlags<Enum> flags, size_t seed = 0) noexcept
{ return qHash(flags.toInt(), seed); }
template <typename T, std::enable_if_t<QHashPrivate::HasQHashSingleArgOverload<T>, bool> = true>
size_t qHash(const T &t, size_t seed) noexcept(noexcept(qHash(t)))
{ return qHash(t) ^ seed; }