Add a inline QVector::append(const QVector &) overload

This is present in QList already and its lack is a nuisance when
switching from QList based code to QVector (which makes sense e.g.
if the item size exceeds sizeof(void*))

Also, albeit operator+=() and operator<<() exist, some people
simply prefer functions with real function names.

[ChangeLog][QtCore][QVector] Added QVector::append(const QVector &) overload

Change-Id: I9aae8223b086765625f2f3071fab5da0780f8a43
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
hjk 2014-11-06 09:19:29 +01:00
parent 1031ad8761
commit d3f3e1218c
3 changed files with 25 additions and 0 deletions

View File

@ -463,6 +463,18 @@
\sa operator<<(), prepend(), insert()
*/
/*! \fn void QVector::append(const QVector<T> &value)
\overload
\since 5.5
Appends the items of the \a value vector to this vector.
\sa operator<<(), operator+=()
*/
/*! \fn void QVector::prepend(const T &value)
Inserts \a value at the beginning of the vector.

View File

@ -128,6 +128,7 @@ public:
T &operator[](int i);
const T &operator[](int i) const;
void append(const T &t);
inline void append(const QVector<T> &l) { *this += l; }
void prepend(const T &t);
void insert(int i, const T &t);
void insert(int i, int n, const T &t);

View File

@ -575,6 +575,18 @@ void tst_QVector::append() const
QCOMPARE(v.last(), SimpleValue<T>::at(0));
}
#endif
{
QVector<int> v;
v << 1 << 2 << 3;
QVector<int> x;
x << 4 << 5 << 6;
v.append(x);
QVector<int> combined;
combined << 1 << 2 << 3 << 4 << 5 << 6;
QCOMPARE(v, combined);
}
}
void tst_QVector::appendInt() const