summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKari Oikarinen <kari.oikarinen@qt.io>2019-03-07 17:34:16 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2019-03-21 15:53:52 +0000
commit3c4721488af0f33515911d07033d3f9981952543 (patch)
tree91d745b1c760f9e744d19f64347e8fa87585f0b2 /src
parent758151d077536eb8fe2cd1a3252dec5619b9789f (diff)
QVector: Add assignment from std::initializer_list
Change-Id: I88a66e4b78ca6f40c328070f275e7163fb0d691c Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qvector.h12
-rw-r--r--src/corelib/tools/qvector.qdoc11
2 files changed, 22 insertions, 1 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 988d5a9e1b..9762ec1b5b 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -79,6 +79,7 @@ public:
void swap(QVector<T> &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QVector(std::initializer_list<T> args);
+ QVector<T> &operator=(std::initializer_list<T> args);
#endif
bool operator==(const QVector<T> &v) const;
inline bool operator!=(const QVector<T> &v) const { return !(*this == v); }
@@ -542,10 +543,19 @@ QVector<T>::QVector(std::initializer_list<T> args)
d = Data::sharedNull();
}
}
+
+template <typename T>
+QVector<T> &QVector<T>::operator=(std::initializer_list<T> args)
+{
+ QVector<T> tmp(args);
+ tmp.swap(*this);
+ return *this;
+}
+
# if defined(Q_CC_MSVC)
QT_WARNING_POP
# endif // Q_CC_MSVC
-#endif // Q_COMPILER_INITALIZER_LISTS
+#endif // Q_COMPILER_INITIALIZER_LISTS
template <typename T>
void QVector<T>::freeData(Data *x)
diff --git a/src/corelib/tools/qvector.qdoc b/src/corelib/tools/qvector.qdoc
index 75b17a4207..69bbb5f9a2 100644
--- a/src/corelib/tools/qvector.qdoc
+++ b/src/corelib/tools/qvector.qdoc
@@ -263,6 +263,17 @@
\since 5.2
*/
+/*!
+ \fn template <typename T> QVector<T> &QVector<T>::operator=(std::initializer_list<T> args)
+
+ Assigns the collection of values in \a args to this QVector instance.
+
+ This operator is only enabled if the compiler supports C++11 initializer
+ lists.
+
+ \since 5.14
+*/
+
/*! \fn template <typename T> void QVector<T>::swap(QVector<T> &other)
\since 4.8