summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qhash.cpp20
-rw-r--r--src/corelib/tools/qhash.h21
-rw-r--r--src/corelib/tools/qmap.cpp20
-rw-r--r--src/corelib/tools/qmap.h19
-rw-r--r--src/corelib/tools/qset.h11
-rw-r--r--src/corelib/tools/qset.qdoc10
6 files changed, 101 insertions, 0 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 0103a208f3..b8cd076cb6 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -924,6 +924,16 @@ void QHashData::checkSanity()
\sa clear()
*/
+/*! \fn QHash::QHash(std::initializer_list<std::pair<Key,T> > list)
+ \since 5.1
+
+ Constructs a hash with a copy of each of the elements in the
+ initializer list \a list.
+
+ This function is only available if the program is being
+ compiled in C++11 mode.
+*/
+
/*! \fn QHash::QHash(const QHash<Key, T> &other)
Constructs a copy of \a other.
@@ -1981,6 +1991,16 @@ void QHashData::checkSanity()
Constructs an empty hash.
*/
+/*! \fn QMultiHash::QMultiHash(std::initializer_list<std::pair<Key,T> > list)
+ \since 5.1
+
+ Constructs a multi hash with a copy of each of the elements in the
+ initializer list \a list.
+
+ This function is only available if the program is being
+ compiled in C++11 mode.
+*/
+
/*! \fn QMultiHash::QMultiHash(const QHash<Key, T> &other)
Constructs a copy of \a other (which can be a QHash or a
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 98965b9121..69a8afe195 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -48,6 +48,10 @@
#include <QtCore/qpair.h>
#include <QtCore/qrefcount.h>
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+#include <initializer_list>
+#endif
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -285,6 +289,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 +934,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
diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp
index 75104e4825..a4c28b5bd4 100644
--- a/src/corelib/tools/qmap.cpp
+++ b/src/corelib/tools/qmap.cpp
@@ -538,6 +538,16 @@ void QMapDataBase::freeData(QMapDataBase *d)
\sa toStdMap()
*/
+/*! \fn QMap::QMap(std::initializer_list<std::pair<Key,T> > list)
+ \since 5.1
+
+ Constructs a map with a copy of each of the elements in the
+ initializer list \a list.
+
+ This function is only available if the program is being
+ compiled in C++11 mode.
+*/
+
/*! \fn std::map<Key, T> QMap::toStdMap() const
Returns an STL map equivalent to this QMap.
@@ -1576,6 +1586,16 @@ void QMapDataBase::freeData(QMapDataBase *d)
Constructs an empty map.
*/
+/*! \fn QMultiMap::QMultiMap(std::initializer_list<std::pair<Key,T> > list)
+ \since 5.1
+
+ Constructs a multi map with a copy of each of the elements in the
+ initializer list \a list.
+
+ This function is only available if the program is being
+ compiled in C++11 mode.
+*/
+
/*! \fn QMultiMap::QMultiMap(const QMap<Key, T> &other)
Constructs a copy of \a other (which can be a QMap or a
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h
index b0ec6fb3c6..93134a43dd 100644
--- a/src/corelib/tools/qmap.h
+++ b/src/corelib/tools/qmap.h
@@ -54,6 +54,10 @@
#include <map>
#include <new>
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+#include <initializer_list>
+#endif
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -327,6 +331,14 @@ class QMap
public:
inline QMap() : d(static_cast<QMapData<Key, T> *>(const_cast<QMapDataBase *>(&QMapDataBase::shared_null))) { }
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ inline QMap(std::initializer_list<std::pair<Key,T> > list)
+ : d(static_cast<QMapData<Key, T> *>(const_cast<QMapDataBase *>(&QMapDataBase::shared_null)))
+ {
+ for (typename std::initializer_list<std::pair<Key,T> >::const_iterator it = list.begin(); it != list.end(); ++it)
+ insert(it->first, it->second);
+ }
+#endif
QMap(const QMap<Key, T> &other);
inline ~QMap() { if (!d->ref.deref()) d->destroy(); }
@@ -960,6 +972,13 @@ class QMultiMap : public QMap<Key, T>
{
public:
QMultiMap() {}
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ inline QMultiMap(std::initializer_list<std::pair<Key,T> > list)
+ {
+ for (typename std::initializer_list<std::pair<Key,T> >::const_iterator it = list.begin(); it != list.end(); ++it)
+ insert(it->first, it->second);
+ }
+#endif
QMultiMap(const QMap<Key, T> &other) : QMap<Key, T>(other) {}
inline void swap(QMultiMap<Key, T> &other) { QMap<Key, T>::swap(other); }
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h
index 6fdc8e6281..ee91336c51 100644
--- a/src/corelib/tools/qset.h
+++ b/src/corelib/tools/qset.h
@@ -43,6 +43,9 @@
#define QSET_H
#include <QtCore/qhash.h>
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+#include <initializer_list>
+#endif
QT_BEGIN_HEADER
@@ -56,6 +59,14 @@ class QSet
public:
inline QSet() {}
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ inline QSet(std::initializer_list<T> list)
+ {
+ reserve(list.size());
+ for (typename std::initializer_list<T>::const_iterator it = list.begin(); it != list.end(); ++it)
+ insert(*it);
+ }
+#endif
inline QSet(const QSet<T> &other) : q_hash(other.q_hash) {}
inline QSet<T> &operator=(const QSet<T> &other)
diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc
index ef7a4c4f52..cd90b4949b 100644
--- a/src/corelib/tools/qset.qdoc
+++ b/src/corelib/tools/qset.qdoc
@@ -103,6 +103,16 @@
\sa clear()
*/
+/*! \fn QSet::QSet(std::initializer_list<T> list)
+ \since 5.1
+
+ Constructs a set with a copy of each of the elements in the
+ initializer list \a list.
+
+ This function is only available if the program is being
+ compiled in C++11 mode.
+*/
+
/*!
\fn QSet::QSet(const QSet<T> &other)