summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qlinkedlist.cpp9
-rw-r--r--src/corelib/tools/qlinkedlist.h11
2 files changed, 20 insertions, 0 deletions
diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp
index b4a341ac74..6e7a7a2635 100644
--- a/src/corelib/tools/qlinkedlist.cpp
+++ b/src/corelib/tools/qlinkedlist.cpp
@@ -137,6 +137,15 @@ const QLinkedListData QLinkedListData::shared_null = {
\sa operator=()
*/
+/*! \fn QLinkedList::QLinkedList(std::initializer_list<T> list)
+ \since 5.2
+
+ Constructs a list from the std::initializer_list specified by \a list.
+
+ This constructor is only enabled if the compiler supports C++11
+ initializer lists.
+*/
+
/*! \fn QLinkedList::~QLinkedList()
Destroys the list. References to the values in the list, and all
diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h
index 56ff2da16d..79a62cb87c 100644
--- a/src/corelib/tools/qlinkedlist.h
+++ b/src/corelib/tools/qlinkedlist.h
@@ -50,6 +50,10 @@
#include <algorithm>
+#if defined(Q_COMPILER_INITIALIZER_LISTS)
+# include <initializer_list>
+#endif
+
QT_BEGIN_NAMESPACE
@@ -80,6 +84,13 @@ class QLinkedList
public:
inline QLinkedList() : d(const_cast<QLinkedListData *>(&QLinkedListData::shared_null)) { }
inline QLinkedList(const QLinkedList<T> &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach(); }
+#if defined(Q_COMPILER_INITIALIZER_LISTS)
+ inline QLinkedList(std::initializer_list<T> list)
+ : d(const_cast<QLinkedListData *>(&QLinkedListData::shared_null))
+ {
+ std::copy(list.begin(), list.end(), std::back_inserter(*this));
+ }
+#endif
~QLinkedList();
QLinkedList<T> &operator=(const QLinkedList<T> &);
#ifdef Q_COMPILER_RVALUE_REFS