diff options
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r-- | src/corelib/tools/qhash.h | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 98965b9121..5d9238f453 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -48,7 +48,9 @@ #include <QtCore/qpair.h> #include <QtCore/qrefcount.h> -QT_BEGIN_HEADER +#ifdef Q_COMPILER_INITIALIZER_LISTS +#include <initializer_list> +#endif QT_BEGIN_NAMESPACE @@ -285,6 +287,15 @@ class QHash public: inline QHash() : d(const_cast<QHashData *>(&QHashData::shared_null)) { } +#ifdef Q_COMPILER_INITIALIZER_LISTS + inline QHash(std::initializer_list<std::pair<Key,T> > list) + : d(const_cast<QHashData *>(&QHashData::shared_null)) + { + reserve(list.size()); + for (typename std::initializer_list<std::pair<Key,T> >::const_iterator it = list.begin(); it != list.end(); ++it) + insert(it->first, it->second); + } +#endif inline QHash(const QHash<Key, T> &other) : d(other.d) { d->ref.ref(); if (!d->sharable) detach(); } inline ~QHash() { if (!d->ref.deref()) freeData(d); } @@ -921,6 +932,14 @@ class QMultiHash : public QHash<Key, T> { public: QMultiHash() {} +#ifdef Q_COMPILER_INITIALIZER_LISTS + inline QMultiHash(std::initializer_list<std::pair<Key,T> > list) + { + this->reserve(list.size()); + for (typename std::initializer_list<std::pair<Key,T> >::const_iterator it = list.begin(); it != list.end(); ++it) + insert(it->first, it->second); + } +#endif QMultiHash(const QHash<Key, T> &other) : QHash<Key, T>(other) {} inline void swap(QMultiHash<Key, T> &other) { QHash<Key, T>::swap(other); } // prevent QMultiHash<->QHash swaps @@ -1034,6 +1053,4 @@ Q_DECLARE_MUTABLE_ASSOCIATIVE_ITERATOR(Hash) QT_END_NAMESPACE -QT_END_HEADER - #endif // QHASH_H |