From 62620a4d6a65e0935c5f8ed71109bea6e8e85500 Mon Sep 17 00:00:00 2001 From: Kevin Funk Date: Mon, 30 Jun 2014 12:00:31 +0200 Subject: [PATCH] qHash overload for Q{Explicitly,}SharedDataPointer Interestingly, before that patch this compiled fine: typedef Q{Explicitly,}SharedDataPointer Ptr; Ptr p(new QSharedData); auto hash = qHash(p); This was because both Q{Explicitly,}SharedDataPointer overload 'operator bool()' => qHash(int) was accepted. This, however, doesn't make sense. Someone should probably take care of applying the safe bool idiom to these classes as well. Change-Id: I8bb6b2aacaa6166da817a6f3847093fd20a05a67 Reviewed-by: Olivier Goffart --- src/corelib/tools/qshareddata.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h index 00bf4cba2a..415ea0d6c7 100644 --- a/src/corelib/tools/qshareddata.h +++ b/src/corelib/tools/qshareddata.h @@ -44,6 +44,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -274,6 +275,17 @@ namespace std { } QT_BEGIN_NAMESPACE +template +Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer &ptr, uint seed = 0) +{ + return qHash(ptr.data(), seed); +} +template +Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer &ptr, uint seed = 0) +{ + return qHash(ptr.data(), seed); +} + template Q_DECLARE_TYPEINFO_BODY(QSharedDataPointer, Q_MOVABLE_TYPE); template Q_DECLARE_TYPEINFO_BODY(QExplicitlySharedDataPointer, Q_MOVABLE_TYPE);