From d5b7b4e41cb9fa6cd14129336ce853a0564a7fea Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 26 Mar 2014 15:21:38 +0100 Subject: QStringList: add op= overloads for QList QStringList = QList already compiled, but was interpreted as QStringList = QStringList(QList), which involves the QList copy ctor. Adding the overload saves that copy. Cannot use a using declaration here, since the return type is different. Change-Id: I9f4feb2f97480d2d6a3b6fa7c71b5d511b623601 Reviewed-by: Thiago Macieira --- src/corelib/tools/qstringlist.cpp | 21 +++++++++++++++++++++ src/corelib/tools/qstringlist.h | 7 +++++++ 2 files changed, 28 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index a9d704ca4c..c735fbcc42 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -203,6 +203,27 @@ QT_BEGIN_NAMESPACE \sa operator=() */ +/*! + \fn QStringList &QStringList::operator=(const QList &other) + \since 5.4 + + Copy assignment operator from QList. Assigns the \a other + list of strings to this string list. + + After the operation, \a other and \c *this will be equal. +*/ + +/*! + \fn QStringList &QStringList::operator=(QList &&other) + \overload + \since 5.4 + + Move assignment operator from QList. Moves the \a other + list of strings to this string list. + + After the operation, \a other will be empty. +*/ + /*! \fn void QStringList::sort(Qt::CaseSensitivity cs) diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/tools/qstringlist.h index 1cdafb4ec2..271599b9d7 100644 --- a/src/corelib/tools/qstringlist.h +++ b/src/corelib/tools/qstringlist.h @@ -68,6 +68,13 @@ public: inline QStringList(std::initializer_list args) : QList(args) { } #endif + QStringList &operator=(const QList &other) + { QList::operator=(other); return *this; } +#ifdef Q_COMPILER_RVALUE_REFS + QStringList &operator=(QList &&other) + { QList::operator=(std::move(other)); return *this; } +#endif + inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive); inline int removeDuplicates(); -- cgit v1.2.3