summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2020-05-20 13:59:48 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2020-08-01 00:01:52 +0200
commit5d7be66fd742e694576ce722aa6e0766c23942f7 (patch)
tree9014b7ffecf242024849abc9a5b12c1eba0f11c7 /src
parent0c53f8ba98fee41d84362b44eb731ff722c8f7fe (diff)
QList: Add a append(QList &&) overload
We already had append(const QList &) and now there's an overload taking an rvalue reference. Change-Id: Id2fbc6c57badebebeee7b80d15bb333270fa4e19 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qlist.h33
-rw-r--r--src/corelib/tools/qlist.qdoc31
2 files changed, 64 insertions, 0 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 0078f87cce..443789b411 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -239,6 +239,7 @@ public:
void append(const_iterator i1, const_iterator i2);
void append(rvalue_ref t) { emplaceBack(std::move(t)); }
void append(const QList<T> &l) { append(l.constBegin(), l.constEnd()); }
+ void append(QList<T> &&l);
void prepend(rvalue_ref t);
void prepend(const T &t);
@@ -434,14 +435,19 @@ public:
// comfort
QList<T> &operator+=(const QList<T> &l) { append(l.cbegin(), l.cend()); return *this; }
+ QList<T> &operator+=(QList<T> &&l) { append(std::move(l)); return *this; }
inline QList<T> operator+(const QList<T> &l) const
{ QList n = *this; n += l; return n; }
+ inline QList<T> operator+(QList<T> &&l) const
+ { QList n = *this; n += std::move(l); return n; }
inline QList<T> &operator+=(const T &t)
{ append(t); return *this; }
inline QList<T> &operator<< (const T &t)
{ append(t); return *this; }
inline QList<T> &operator<<(const QList<T> &l)
{ *this += l; return *this; }
+ inline QList<T> &operator<<(QList<T> &&l)
+ { *this += std::move(l); return *this; }
inline QList<T> &operator+=(rvalue_ref t)
{ append(std::move(t)); return *this; }
inline QList<T> &operator<<(rvalue_ref t)
@@ -580,6 +586,33 @@ inline void QList<T>::append(const_iterator i1, const_iterator i2)
}
template <typename T>
+inline void QList<T>::append(QList<T> &&other)
+{
+ if (other.isEmpty())
+ return;
+ if (other.d->needsDetach() || !std::is_nothrow_move_constructible_v<T>)
+ return append(other);
+
+ const size_t newSize = size() + other.size();
+ if (d->needsDetach() || newSize > d->allocatedCapacity()) {
+ DataPointer detached(Data::allocate(d->detachCapacity(newSize),
+ d->detachFlags() | Data::GrowsForward));
+
+ if (!d->needsDetach())
+ detached->moveAppend(begin(), end());
+ else
+ detached->copyAppend(cbegin(), cend());
+ detached->moveAppend(other.begin(), other.end());
+
+ d.swap(detached);
+ } else {
+ // we're detached and we can just move data around
+ d->moveAppend(other.begin(), other.end());
+ }
+}
+
+
+template <typename T>
inline typename QList<T>::iterator
QList<T>::insert(qsizetype i, qsizetype n, parameter_type t)
{
diff --git a/src/corelib/tools/qlist.qdoc b/src/corelib/tools/qlist.qdoc
index 8d1280a2ea..339c089bb8 100644
--- a/src/corelib/tools/qlist.qdoc
+++ b/src/corelib/tools/qlist.qdoc
@@ -670,6 +670,15 @@
\sa operator<<(), operator+=()
*/
+/*! \fn template <typename T> void QList<T>::append(QList<T> &&value)
+ \overload
+
+ \since 6.0
+
+ Moves the items of the \a value list to the end of this list.
+
+ \sa operator<<(), operator+=()
+*/
/*!
\fn template <typename T> void QList<T>::prepend(const T &value)
@@ -1290,6 +1299,14 @@
\sa operator+(), append()
*/
+/*! \fn template <typename T> QList<T> &QList<T>::operator+=(QList<T> &&other)
+ \since 6.0
+
+ \overload
+
+ \sa operator+(), append()
+*/
+
/*! \fn template <typename T> void QList<T>::operator+=(const T &value)
\overload
@@ -1315,6 +1332,14 @@
\sa operator+=()
*/
+/*! \fn template <typename T> QList<T> QList<T>::operator+(QList<T> &&other) const
+ \since 6.0
+
+ \overload
+
+ \sa operator+=()
+*/
+
/*! \fn template <typename T> QList<T> &QList<T>::operator<<(const T &value)
Appends \a value to the list and returns a reference to this list.
@@ -1336,6 +1361,12 @@
Appends \a other to the list and returns a reference to the list.
*/
+/*! \fn template <typename T> QList<T> &QList<T>::operator<<(QList<T> &&other)
+ \since 6.0
+
+ \overload
+*/
+
/*! \typedef QList::iterator
The QList::iterator typedef provides an STL-style non-const