diff options
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qvector.h | 12 | ||||
-rw-r--r-- | src/corelib/tools/qvector.qdoc | 11 |
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 |