QStringList: add op= overloads for QList<QString>
QStringList = QList<QString> already compiled, but was interpreted as QStringList = QStringList(QList<QString>), 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 <thiago.macieira@intel.com>
This commit is contained in:
parent
a74e4b85be
commit
d5b7b4e41c
@ -203,6 +203,27 @@ QT_BEGIN_NAMESPACE
|
||||
\sa operator=()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QStringList &QStringList::operator=(const QList<QString> &other)
|
||||
\since 5.4
|
||||
|
||||
Copy assignment operator from QList<QString>. 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<QString> &&other)
|
||||
\overload
|
||||
\since 5.4
|
||||
|
||||
Move assignment operator from QList<QString>. 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)
|
||||
|
||||
|
@ -68,6 +68,13 @@ public:
|
||||
inline QStringList(std::initializer_list<QString> args) : QList<QString>(args) { }
|
||||
#endif
|
||||
|
||||
QStringList &operator=(const QList<QString> &other)
|
||||
{ QList<QString>::operator=(other); return *this; }
|
||||
#ifdef Q_COMPILER_RVALUE_REFS
|
||||
QStringList &operator=(QList<QString> &&other)
|
||||
{ QList<QString>::operator=(std::move(other)); return *this; }
|
||||
#endif
|
||||
|
||||
inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
||||
inline int removeDuplicates();
|
||||
|
||||
|
@ -66,6 +66,7 @@ private slots:
|
||||
void lastIndexOf_regExp();
|
||||
|
||||
void streamingOperator();
|
||||
void assignmentOperator();
|
||||
void join() const;
|
||||
void join_data() const;
|
||||
void joinEmptiness() const;
|
||||
@ -344,6 +345,21 @@ void tst_QStringList::streamingOperator()
|
||||
QCOMPARE(list2 << list3, QStringList() << "adam" << "eva");
|
||||
}
|
||||
|
||||
void tst_QStringList::assignmentOperator()
|
||||
{
|
||||
// compile-only test
|
||||
|
||||
QStringList adam;
|
||||
adam << "adam";
|
||||
QList<QString> eva;
|
||||
eva << "eva";
|
||||
QStringList result;
|
||||
QStringList &ref1 = (result = adam);
|
||||
QStringList &ref2 = (result = eva);
|
||||
Q_UNUSED(ref1);
|
||||
Q_UNUSED(ref2);
|
||||
}
|
||||
|
||||
void tst_QStringList::join() const
|
||||
{
|
||||
QFETCH(QStringList, input);
|
||||
|
Loading…
Reference in New Issue
Block a user