diff options
author | Kevin Funk <kfunk@kde.org> | 2014-06-30 12:00:31 +0200 |
---|---|---|
committer | Kevin Funk <kevin.funk@kdab.com> | 2014-06-30 13:47:23 +0200 |
commit | 62620a4d6a65e0935c5f8ed71109bea6e8e85500 (patch) | |
tree | 9fcc2513ea1093a9ab139938c616c52ca76f3d1e /src | |
parent | 28e51580269020b5f7bcd6aeee53d2488b6b5be3 (diff) |
qHash overload for Q{Explicitly,}SharedDataPointer
Interestingly, before that patch this compiled fine:
typedef Q{Explicitly,}SharedDataPointer<QSharedData> 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 <ogoffart@woboq.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qshareddata.h | 12 |
1 files changed, 12 insertions, 0 deletions
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 <QtCore/qglobal.h> #include <QtCore/qatomic.h> +#include <QtCore/qhash.h> QT_BEGIN_NAMESPACE @@ -274,6 +275,17 @@ namespace std { } QT_BEGIN_NAMESPACE +template <class T> +Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0) +{ + return qHash(ptr.data(), seed); +} +template <class T> +Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer<T> &ptr, uint seed = 0) +{ + return qHash(ptr.data(), seed); +} + template<typename T> Q_DECLARE_TYPEINFO_BODY(QSharedDataPointer<T>, Q_MOVABLE_TYPE); template<typename T> Q_DECLARE_TYPEINFO_BODY(QExplicitlySharedDataPointer<T>, Q_MOVABLE_TYPE); |