QStringList: add op<< overload 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: I119cc98e7e2df24549a1abb158543b729edc30ef
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
This commit is contained in:
Marc Mutz 2014-03-26 15:21:38 +01:00 committed by The Qt Project
parent 2a9d3b7a46
commit 47d2d19cf6
3 changed files with 17 additions and 0 deletions

View File

@ -478,6 +478,16 @@ QString QtPrivate::QStringList_join(const QStringList *that, const QChar *sep, i
the latter string list.
*/
/*!
\fn QStringList &QStringList::operator<<(const QList<QString> &other)
\since 5.4
\overload
Appends the \a other string list to the string list and returns a reference to
the latter string list.
*/
#ifndef QT_NO_DATASTREAM
/*!
\fn QDataStream &operator>>(QDataStream &in, QStringList &list)

View File

@ -85,6 +85,8 @@ public:
{ append(str); return *this; }
inline QStringList &operator<<(const QStringList &l)
{ *this += l; return *this; }
inline QStringList &operator<<(const QList<QString> &l)
{ *this += l; return *this; }
#ifndef QT_NO_REGEXP
inline QStringList filter(const QRegExp &rx) const;

View File

@ -321,7 +321,12 @@ void tst_QStringList::streamingOperator()
list << "hei";
list << list << "hopp" << list;
QList<QString> slist = list;
list << slist;
QCOMPARE(list, QStringList()
<< "hei" << "hei" << "hopp"
<< "hei" << "hei" << "hopp"
<< "hei" << "hei" << "hopp"
<< "hei" << "hei" << "hopp");