From 5357231c0a10eef558cc6aebfd172048dc010a96 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 24 May 2019 14:27:48 +0200 Subject: Make QList an alias to QVector This is almost 100% source compatible with Qt 5. Exceptions are * Stability of references for large or non movable types * taking a PMF for types that are now overloaded with r-value references in QVector * The missing prepend optimization in QVector (that is still planned to come for Qt 6) Change-Id: I96d44553304dd623def9c70d6fea8fa2fb0373b0 Reviewed-by: Simon Hausmann --- qmake/Makefile.unix | 6 +- qmake/Makefile.win32 | 1 - src/corelib/global/qtypeinfo.h | 1 - src/corelib/io/qdebug.h | 6 - src/corelib/itemmodels/qitemselectionmodel.h | 2 +- src/corelib/kernel/qmetaobject.cpp | 4 +- src/corelib/kernel/qmetaobject_moc_p.h | 3 + src/corelib/kernel/qmetatype.h | 9 +- src/corelib/serialization/qcborvalue_p.h | 2 +- src/corelib/serialization/qdatastream.h | 12 - src/corelib/tools/qcontainerfwd.h | 2 +- src/corelib/tools/qlist.cpp | 2025 ------------------- src/corelib/tools/qlist.h | 1142 +---------- src/corelib/tools/qvector.h | 11 +- src/dbus/qdbusmisc.cpp | 5 +- src/tools/bootstrap/bootstrap.pro | 1 - src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp | 3 +- src/widgets/itemviews/qlistwidget.cpp | 4 +- src/widgets/itemviews/qtreewidget.cpp | 2 +- sync.profile | 1 + .../qtconcurrentfilter/tst_qtconcurrentfilter.cpp | 40 +- .../qtconcurrentmap/tst_qtconcurrentmap.cpp | 41 +- .../corelib/kernel/qmetaobject/tst_qmetaobject.cpp | 24 +- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 2 +- .../corelib/tools/collections/tst_collections.cpp | 17 - .../tst_containerapisymmetry.cpp | 3 - tests/auto/corelib/tools/qlist/.gitignore | 1 - tests/auto/corelib/tools/qlist/qlist.pro | 6 - tests/auto/corelib/tools/qlist/tst_qlist.cpp | 2115 -------------------- .../qlist_strictiterators.pro | 3 - tests/auto/corelib/tools/tools.pro | 2 - .../auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp | 2 +- tests/auto/network/ssl/qdtls/tst_qdtls.cpp | 1 - tests/auto/network/ssl/qocsp/tst_qocsp.cpp | 1 - .../selftests/expected_signaldumper.lightxml | 2 +- .../testlib/selftests/expected_signaldumper.tap | 2 +- .../selftests/expected_signaldumper.teamcity | 2 +- .../testlib/selftests/expected_signaldumper.txt | 2 +- .../testlib/selftests/expected_signaldumper.xml | 2 +- .../selftests/expected_signaldumper.xunitxml | 4 +- tests/auto/tools/moc/allmocs_baseline_in.json | 12 +- 41 files changed, 106 insertions(+), 5420 deletions(-) delete mode 100644 tests/auto/corelib/tools/qlist/.gitignore delete mode 100644 tests/auto/corelib/tools/qlist/qlist.pro delete mode 100644 tests/auto/corelib/tools/qlist/tst_qlist.cpp delete mode 100644 tests/auto/corelib/tools/qlist_strictiterators/qlist_strictiterators.pro diff --git a/qmake/Makefile.unix b/qmake/Makefile.unix index da0fccb834..2e4958dcd7 100644 --- a/qmake/Makefile.unix +++ b/qmake/Makefile.unix @@ -29,7 +29,7 @@ QOBJS = \ quuid.o \ qarraydata.o qbitarray.o qbytearray.o qbytearraylist.o qbytearraymatcher.o \ qcalendar.o qgregoriancalendar.o qromancalendar.o \ - qcryptographichash.o qdatetime.o qhash.o qlist.o \ + qcryptographichash.o qdatetime.o qhash.o \ qlocale.o qlocale_tools.o qmap.o qregexp.o qringbuffer.o \ qstringbuilder.o qstring.o qstringlist.o qversionnumber.o \ qvsnprintf.o qxmlstream.o qxmlutils.o \ @@ -125,7 +125,6 @@ DEPEND_SRC = \ $(SOURCE_PATH)/src/corelib/tools/qbitarray.cpp \ $(SOURCE_PATH)/src/corelib/tools/qcryptographichash.cpp \ $(SOURCE_PATH)/src/corelib/tools/qhash.cpp \ - $(SOURCE_PATH)/src/corelib/tools/qlist.cpp \ $(SOURCE_PATH)/src/corelib/tools/qmap.cpp \ $(SOURCE_PATH)/src/corelib/tools/qringbuffer.cpp \ $(SOURCE_PATH)/src/corelib/tools/qversionnumber.cpp \ @@ -371,9 +370,6 @@ qversionnumber.o: $(SOURCE_PATH)/src/corelib/tools/qversionnumber.cpp qbuffer.o: $(SOURCE_PATH)/src/corelib/io/qbuffer.cpp $(CXX) -c -o $@ $(CXXFLAGS) $< -qlist.o: $(SOURCE_PATH)/src/corelib/tools/qlist.cpp - $(CXX) -c -o $@ $(CXXFLAGS) $< - qfile.o: $(SOURCE_PATH)/src/corelib/io/qfile.cpp $(CXX) -c -o $@ $(CXXFLAGS) $< diff --git a/qmake/Makefile.win32 b/qmake/Makefile.win32 index 74fb80e337..1c2692d143 100644 --- a/qmake/Makefile.win32 +++ b/qmake/Makefile.win32 @@ -90,7 +90,6 @@ QTOBJS= \ qiodevice.obj \ qringbuffer.obj \ qdebug.obj \ - qlist.obj \ qlocale.obj \ qlocale_tools.obj \ qlocale_win.obj \ diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h index 30be47296e..34cf1de4f5 100644 --- a/src/corelib/global/qtypeinfo.h +++ b/src/corelib/global/qtypeinfo.h @@ -209,7 +209,6 @@ public: \ }; \ } -Q_DECLARE_MOVABLE_CONTAINER(QList); Q_DECLARE_MOVABLE_CONTAINER(QVector); Q_DECLARE_MOVABLE_CONTAINER(QQueue); Q_DECLARE_MOVABLE_CONTAINER(QStack); diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 421c5d933b..2314b36bda 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -234,12 +234,6 @@ inline QDebug printSequentialContainer(QDebug debug, const char *which, const Se } // namespace QtPrivate -template -inline QDebug operator<<(QDebug debug, const QList &list) -{ - return QtPrivate::printSequentialContainer(debug, "" /*for historical reasons*/, list); -} - template inline QDebug operator<<(QDebug debug, const QVector &vec) { diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index 5820695592..5421eb2afa 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -241,7 +241,7 @@ inline uint qHash(const QItemSelectionRange &) { return 0; } # define Q_TEMPLATE_EXTERN extern # endif # endif -Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QList; +Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QVector; #endif // Q_CC_MSVC class Q_CORE_EXPORT QItemSelection : public QList diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index a8e8866339..b1e1bb8b4a 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -682,7 +682,9 @@ static void argumentTypesFromString(const char *str, const char *end, --level; ++str; } - types += QArgumentType(QByteArray(begin, str - begin)); + QByteArray argType(begin, str - begin); + argType.replace("QList<", "QVector<"); + types += QArgumentType(std::move(argType)); } } diff --git a/src/corelib/kernel/qmetaobject_moc_p.h b/src/corelib/kernel/qmetaobject_moc_p.h index 8c7900767b..471e43f85b 100644 --- a/src/corelib/kernel/qmetaobject_moc_p.h +++ b/src/corelib/kernel/qmetaobject_moc_p.h @@ -213,6 +213,9 @@ static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixSc } } + // Qt 5 compatibility, make sure we use the correct type name for QList + result.replace("QList<", "QVector<"); + return result; } diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 8b621f0161..7b985be9fd 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -207,10 +207,10 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId(); F(UInt, -1, uint, "quint32") \ F(LongLong, -1, qlonglong, "qint64") \ F(ULongLong, -1, qulonglong, "quint64") \ - F(QVariantList, -1, QVariantList, "QList") \ + F(QVariantList, -1, QVariantList, "QVector") \ F(QVariantMap, -1, QVariantMap, "QMap") \ F(QVariantHash, -1, QVariantHash, "QHash") \ - F(QByteArrayList, -1, QByteArrayList, "QList") \ + F(QByteArrayList, -1, QByteArrayList, "QVector") \ #define QT_FOR_EACH_STATIC_TYPE(F)\ QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)\ @@ -225,7 +225,6 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId(); TypeName = Id, #define QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(F) \ - F(QList) \ F(QVector) \ F(QQueue) \ F(QStack) \ @@ -1003,10 +1002,6 @@ struct ContainerAPI : CapabilitiesImpl static int size(const T *t) { return int(std::distance(t->begin(), t->end())); } }; -template -struct ContainerAPI > : CapabilitiesImpl > -{ static int size(const QList *t) { return t->size(); } }; - template struct ContainerAPI > : CapabilitiesImpl > { static int size(const QVector *t) { return t->size(); } }; diff --git a/src/corelib/serialization/qcborvalue_p.h b/src/corelib/serialization/qcborvalue_p.h index 38ad54047f..d18d108969 100644 --- a/src/corelib/serialization/qcborvalue_p.h +++ b/src/corelib/serialization/qcborvalue_p.h @@ -215,7 +215,7 @@ public: } void insertAt(qsizetype idx, const QCborValue &value, ContainerDisposition disp = CopyContainer) { - replaceAt_internal(*elements.insert(elements.begin() + idx, {}), value, disp); + replaceAt_internal(*elements.insert(elements.begin() + int(idx), {}), value, disp); } void append(QtCbor::Undefined) diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h index bcfcd47ccf..20d3953652 100644 --- a/src/corelib/serialization/qdatastream.h +++ b/src/corelib/serialization/qdatastream.h @@ -389,18 +389,6 @@ typename std::enable_if::value, QDataStream &>::type& operator>>(QDataStream &s, T &t) { return s >> reinterpret_cast::type &>(t); } -template -inline QDataStream &operator>>(QDataStream &s, QList &l) -{ - return QtPrivate::readArrayBasedContainer(s, l); -} - -template -inline QDataStream &operator<<(QDataStream &s, const QList &l) -{ - return QtPrivate::writeSequentialContainer(s, l); -} - template inline QDataStream &operator>>(QDataStream &s, QVector &v) { diff --git a/src/corelib/tools/qcontainerfwd.h b/src/corelib/tools/qcontainerfwd.h index 532b4c95ce..f6efa99b6a 100644 --- a/src/corelib/tools/qcontainerfwd.h +++ b/src/corelib/tools/qcontainerfwd.h @@ -50,7 +50,6 @@ template class QHash; #ifndef QT_NO_LINKED_LIST template class QLinkedList; #endif -template class QList; template class QMap; template class QMultiHash; template class QMultiMap; @@ -60,6 +59,7 @@ template class QSet; template class QStack; template class QVarLengthArray; template class QVector; +template using QList = QVector; QT_END_NAMESPACE diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index 5d5da20752..62201fd5d6 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -63,2029 +63,4 @@ template class Q_CORE_EXPORT QVector; template class Q_CORE_EXPORT QVector; #endif - -/* - QList as an array-list combines the easy-of-use of a random - access interface with fast list operations and the low memory - management overhead of an array. Accessing elements by index, - appending, prepending, and removing elements from both the front - and the back all happen in constant time O(1). Inserting or - removing elements at random index positions \ai happens in linear - time, or more precisly in O(min{i,n-i}) <= O(n/2), with n being - the number of elements in the list. -*/ - -const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, { nullptr } }; - -/*! - * Detaches the QListData by allocating new memory for a list which will be bigger - * than the copied one and is expected to grow further. - * *idx is the desired insertion point and is clamped to the actual size of the list. - * num is the number of new elements to insert at the insertion point. - * Returns the old (shared) data, it is up to the caller to deref() and free(). - * For the new data node_copy needs to be called. - * - * \internal - */ -QListData::Data *QListData::detach_grow(int *idx, int num) -{ - Data *x = d; - int l = x->end - x->begin; - int nl = l + num; - auto blockInfo = qCalculateGrowingBlockSize(nl, sizeof(void *), DataHeaderSize); - Data* t = static_cast(::malloc(blockInfo.size)); - Q_CHECK_PTR(t); - t->alloc = int(uint(blockInfo.elementCount)); - - t->ref.initializeOwned(); - // The space reservation algorithm's optimization is biased towards appending: - // Something which looks like an append will put the data at the beginning, - // while something which looks like a prepend will put it in the middle - // instead of at the end. That's based on the assumption that prepending - // is uncommon and even an initial prepend will eventually be followed by - // at least some appends. - int bg; - if (*idx < 0) { - *idx = 0; - bg = (t->alloc - nl) >> 1; - } else if (*idx > l) { - *idx = l; - bg = 0; - } else if (*idx < (l >> 1)) { - bg = (t->alloc - nl) >> 1; - } else { - bg = 0; - } - t->begin = bg; - t->end = bg + nl; - d = t; - - return x; -} - -/*! - * Detaches the QListData by allocating new memory for a list which possibly - * has a different size than the copied one. - * Returns the old (shared) data, it is up to the caller to deref() and free() - * For the new data node_copy needs to be called. - * - * \internal - */ -QListData::Data *QListData::detach(int alloc) -{ - Data *x = d; - Data* t = static_cast(::malloc(qCalculateBlockSize(alloc, sizeof(void*), DataHeaderSize))); - Q_CHECK_PTR(t); - - t->ref.initializeOwned(); - t->alloc = alloc; - if (!alloc) { - t->begin = 0; - t->end = 0; - } else { - t->begin = x->begin; - t->end = x->end; - } - d = t; - - return x; -} - -void QListData::realloc(int alloc) -{ - Q_ASSERT(!d->ref.isShared()); - Data *x = static_cast(::realloc(d, qCalculateBlockSize(alloc, sizeof(void *), DataHeaderSize))); - Q_CHECK_PTR(x); - - d = x; - d->alloc = alloc; - if (!alloc) - d->begin = d->end = 0; -} - -void QListData::realloc_grow(int growth) -{ - Q_ASSERT(!d->ref.isShared()); - auto r = qCalculateGrowingBlockSize(d->alloc + growth, sizeof(void *), DataHeaderSize); - Data *x = static_cast(::realloc(d, r.size)); - Q_CHECK_PTR(x); - - d = x; - d->alloc = int(uint(r.elementCount)); -} - -void QListData::dispose(Data *d) -{ - Q_ASSERT(!d->ref.isShared()); - free(d); -} - -// ensures that enough space is available to append n elements -void **QListData::append(int n) -{ - Q_ASSERT(!d->ref.isShared()); - int e = d->end; - if (e + n > d->alloc) { - int b = d->begin; - if (b - n >= 2 * d->alloc / 3) { - // we have enough space. Just not at the end -> move it. - e -= b; - ::memcpy(d->array, d->array + b, e * sizeof(void *)); - d->begin = 0; - } else { - realloc_grow(n); - } - } - d->end = e + n; - return d->array + e; -} - -// ensures that enough space is available to append one element -void **QListData::append() -{ - return append(1); -} - -// ensures that enough space is available to append the list -void **QListData::append(const QListData& l) -{ - return append(l.d->end - l.d->begin); -} - -void **QListData::prepend() -{ - Q_ASSERT(!d->ref.isShared()); - if (d->begin == 0) { - if (d->end >= d->alloc / 3) - realloc_grow(1); - - if (d->end < d->alloc / 3) - d->begin = d->alloc - 2 * d->end; - else - d->begin = d->alloc - d->end; - - ::memmove(d->array + d->begin, d->array, d->end * sizeof(void *)); - d->end += d->begin; - } - return d->array + --d->begin; -} - -void **QListData::insert(int i) -{ - Q_ASSERT(!d->ref.isShared()); - if (i <= 0) - return prepend(); - int size = d->end - d->begin; - if (i >= size) - return append(); - - bool leftward = false; - - if (d->begin == 0) { - if (d->end == d->alloc) { - // If the array is full, we expand it and move some items rightward - realloc_grow(1); - } else { - // If there is free space at the end of the array, we move some items rightward - } - } else { - if (d->end == d->alloc) { - // If there is free space at the beginning of the array, we move some items leftward - leftward = true; - } else { - // If there is free space at both ends, we move as few items as possible - leftward = (i < size - i); - } - } - - if (leftward) { - --d->begin; - ::memmove(d->array + d->begin, d->array + d->begin + 1, i * sizeof(void *)); - } else { - ::memmove(d->array + d->begin + i + 1, d->array + d->begin + i, - (size - i) * sizeof(void *)); - ++d->end; - } - return d->array + d->begin + i; -} - -void QListData::remove(int i) -{ - Q_ASSERT(!d->ref.isShared()); - i += d->begin; - if (i - d->begin < d->end - i) { - if (int offset = i - d->begin) - ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *)); - d->begin++; - } else { - if (int offset = d->end - i - 1) - ::memmove(d->array + i, d->array + i + 1, offset * sizeof(void *)); - d->end--; - } -} - -void QListData::remove(int i, int n) -{ - Q_ASSERT(!d->ref.isShared()); - i += d->begin; - int middle = i + n/2; - if (middle - d->begin < d->end - middle) { - ::memmove(d->array + d->begin + n, d->array + d->begin, - (i - d->begin) * sizeof(void*)); - d->begin += n; - } else { - ::memmove(d->array + i, d->array + i + n, - (d->end - i - n) * sizeof(void*)); - d->end -= n; - } -} - -void QListData::move(int from, int to) -{ - Q_ASSERT(!d->ref.isShared()); - if (from == to) - return; - - from += d->begin; - to += d->begin; - void *t = d->array[from]; - - if (from < to) { - if (d->end == d->alloc || 3 * (to - from) < 2 * (d->end - d->begin)) { - ::memmove(d->array + from, d->array + from + 1, (to - from) * sizeof(void *)); - } else { - // optimization - if (int offset = from - d->begin) - ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *)); - if (int offset = d->end - (to + 1)) - ::memmove(d->array + to + 2, d->array + to + 1, offset * sizeof(void *)); - ++d->begin; - ++d->end; - ++to; - } - } else { - if (d->begin == 0 || 3 * (from - to) < 2 * (d->end - d->begin)) { - ::memmove(d->array + to + 1, d->array + to, (from - to) * sizeof(void *)); - } else { - // optimization - if (int offset = to - d->begin) - ::memmove(d->array + d->begin - 1, d->array + d->begin, offset * sizeof(void *)); - if (int offset = d->end - (from + 1)) - ::memmove(d->array + from, d->array + from + 1, offset * sizeof(void *)); - --d->begin; - --d->end; - --to; - } - } - d->array[to] = t; -} - -void **QListData::erase(void **xi) -{ - Q_ASSERT(!d->ref.isShared()); - int i = xi - (d->array + d->begin); - remove(i); - return d->array + d->begin + i; -} - -/*! \class QList - \inmodule QtCore - \brief The QList class is a template class that provides lists. - - \ingroup tools - \ingroup shared - - \reentrant - - QList\ is one of Qt's generic \l{container classes}. It - stores items in a list that provides fast index-based access - and index-based insertions and removals. - - QList\, QLinkedList\, and QVector\ provide similar - APIs and functionality. They are often interchangeable, but there - are performance consequences. Here is an overview of use cases: - - \list - \li QVector should be your default first choice. - QVector\ will usually give better performance than QList\, - because QVector\ always stores its items sequentially in memory, - where QList\ will allocate its items on the heap unless - \c {sizeof(T) <= sizeof(void*)} and T has been declared to be - either a \c{Q_MOVABLE_TYPE} or a \c{Q_PRIMITIVE_TYPE} using - \l {Q_DECLARE_TYPEINFO}. See the \l {Pros and Cons of Using QList} - for an explanation. - \li However, QList is used throughout the Qt APIs for passing - parameters and for returning values. Use QList to interface with - those APIs. - \li If you need a real linked list, which guarantees - \l {Algorithmic Complexity}{constant time} insertions mid-list and - uses iterators to items rather than indexes, use QLinkedList. - \endlist - - \note QVector and QVarLengthArray both guarantee C-compatible - array layout. QList does not. This might be important if your - application must interface with a C API. - - \note Iterators into a QLinkedList and references into - heap-allocating QLists remain valid as long as the referenced items - remain in the container. This is not true for iterators and - references into a QVector and non-heap-allocating QLists. - - Internally, QList\ is represented as an array of T if - \c{sizeof(T) <= sizeof(void*)} and T has been declared to be - either a \c{Q_MOVABLE_TYPE} or a \c{Q_PRIMITIVE_TYPE} using - \l {Q_DECLARE_TYPEINFO}. Otherwise, QList\ is represented - as an array of T* and the items are allocated on the heap. - - The array representation allows very fast insertions and - index-based access. The prepend() and append() operations are - also very fast because QList preallocates memory at both - ends of its internal array. (See \l{Algorithmic Complexity} for - details. - - Note, however, that when the conditions specified above are not met, - each append or insert of a new item requires allocating the new item - on the heap, and this per item allocation will make QVector a better - choice for use cases that do a lot of appending or inserting, because - QVector can allocate memory for many items in a single heap allocation. - - Note that the internal array only ever gets bigger over the life - of the list. It never shrinks. The internal array is deallocated - by the destructor and by the assignment operator, when one list - is assigned to another. - - Here's an example of a QList that stores integers and - a QList that stores QDate values: - - \snippet code/src_corelib_tools_qlistdata.cpp 0 - - Qt includes a QStringList class that inherits QList\ - and adds a few convenience functions, such as QStringList::join() - and QStringList::filter(). QString::split() creates QStringLists - from strings. - - QList stores a list of items. The default constructor creates an - empty list. You can use the initializer-list constructor to create - a list with elements: - - \snippet code/src_corelib_tools_qlistdata.cpp 1a - - QList provides these basic functions to add, move, and remove - items: insert(), replace(), removeAt(), move(), and swap(). In - addition, it provides the following convenience functions: - append(), \l{operator<<()}, \l{operator+=()}, prepend(), removeFirst(), - and removeLast(). - - \l{operator<<()} allows to conveniently add multiple elements to a list: - - \snippet code/src_corelib_tools_qlistdata.cpp 1b - - QList uses 0-based indexes, just like C++ arrays. To access the - item at a particular index position, you can use operator[](). On - non-const lists, operator[]() returns a reference to the item and - can be used on the left side of an assignment: - - \snippet code/src_corelib_tools_qlistdata.cpp 2 - - Because QList is implemented as an array of pointers for types - that are larger than a pointer or are not movable, this operation - requires (\l{Algorithmic Complexity}{constant time}). For read-only - access, an alternative syntax is to use at(): - - \snippet code/src_corelib_tools_qlistdata.cpp 3 - - at() can be faster than operator[](), because it never causes a - \l{deep copy} to occur. - - A common requirement is to remove an item from a list and do - something with it. For this, QList provides takeAt(), takeFirst(), - and takeLast(). Here's a loop that removes the items from a list - one at a time and calls \c delete on them: - - \snippet code/src_corelib_tools_qlistdata.cpp 4 - - Inserting and removing items at either end of the list is very - fast (\l{Algorithmic Complexity}{constant time} in most cases), - because QList preallocates extra space on both sides of its - internal buffer to allow for fast growth at both ends of the list. - - If you want to find all occurrences of a particular value in a - list, use indexOf() or lastIndexOf(). The former searches forward - starting from a given index position, the latter searches - backward. Both return the index of a matching item if they find - it; otherwise, they return -1. For example: - - \snippet code/src_corelib_tools_qlistdata.cpp 5 - - If you simply want to check whether a list contains a particular - value, use contains(). If you want to find out how many times a - particular value occurs in the list, use count(). If you want to - replace all occurrences of a particular value with another, use - replace(). - - QList's value type must be an \l{assignable data type}. This - covers most data types that are commonly used, but the compiler - won't let you, for example, store a QWidget as a value; instead, - store a QWidget *. A few functions have additional requirements; - for example, indexOf() and lastIndexOf() expect the value type to - support \c operator==(). These requirements are documented on a - per-function basis. - - Like the other container classes, QList provides \l{Java-style - iterators} (QListIterator and QMutableListIterator) and - \l{STL-style iterators} (QList::const_iterator and - QList::iterator). In practice, these are rarely used, because you - can use indexes into the QList. QList is implemented in such a way - that direct index-based access is just as fast as using iterators. - - QList does \e not support inserting, prepending, appending or - replacing with references to its own values. Doing so will cause - your application to abort with an error message. - - To make QList as efficient as possible, its member functions don't - validate their input before using it. Except for isEmpty(), member - functions always assume the list is \e not empty. Member functions - that take index values as parameters always assume their index - value parameters are in the valid range. This means QList member - functions can fail. If you define QT_NO_DEBUG when you compile, - failures will not be detected. If you \e don't define QT_NO_DEBUG, - failures will be detected using Q_ASSERT() or Q_ASSERT_X() with an - appropriate message. - - To avoid failures when your list can be empty, call isEmpty() - before calling other member functions. If you must pass an index - value that might not be in the valid range, check that it is less - than the value returned by size() but \e not less than 0. - - \section1 More Members - - If T is a QByteArray, this class has a couple more members that can be - used. See the documentation for QByteArrayList for more information. - - If T is QString, this class has the following additional members: - \l{QStringList::filter()}{filter}, - \l{QStringList::join()}{join}, - \l{QStringList::removeDuplicates()}{removeDuplicates}, - \l{QStringList::sort()}{sort}. - - \section1 More Information on Using Qt Containers - - For a detailed discussion comparing Qt containers with each other and - with STL containers, see \l {Understand the Qt Containers}. - - \sa QListIterator, QMutableListIterator, QLinkedList, QVector -*/ - -/*! - \fn template QList::QList(QList &&other) - - Move-constructs a QList instance, making it point at the same - object that \a other was pointing to. - - \since 5.2 -*/ - -/*! \fn template template QList::QList(InputIterator first, InputIterator last) - \since 5.14 - - Constructs a QList with the contents in the iterator range [\a first, \a last). - - The value type of \c InputIterator must be convertible to \c T. -*/ - -/*! - \fn template QList QList::mid(int pos, int length) const - - Returns a sub-list which includes elements from this list, - starting at position \a pos. If \a length is -1 (the default), all - elements from \a pos are included; otherwise \a length elements (or - all remaining elements if there are less than \a length elements) - are included. -*/ - -/*! \fn template QList::QList() - - Constructs an empty list. -*/ - -/*! \fn template QList::QList(const QList &other) - - Constructs a copy of \a other. - - This operation takes \l{Algorithmic Complexity}{constant time}, - because QList is \l{implicitly shared}. This makes returning a - QList from a function very fast. If a shared instance is modified, - it will be copied (copy-on-write), and that takes - \l{Algorithmic Complexity}{linear time}. - - \sa operator=() -*/ - -/*! \fn template QList::QList(std::initializer_list args) - \since 4.8 - - Construct a list from the std::initializer_list specified by \a args. - - This constructor is only enabled if the compiler supports C++11 initializer - lists. -*/ - -/*! \fn template QList::~QList() - - Destroys the list. References to the values in the list and all - iterators of this list become invalid. -*/ - -/*! \fn template QList &QList::operator=(const QList &other) - - Assigns \a other to this list and returns a reference to this - list. -*/ - -/*! - \fn template QList &QList::operator=(QList &&other) - - Move-assigns \a other to this QList instance. - - \since 5.2 -*/ - -/*! \fn template void QList::swap(QList &other) - \since 4.8 - - Swaps list \a other with this list. This operation is very - fast and never fails. -*/ - -/*! \fn template bool QList::operator==(const QList &other) const - - Returns \c true if \a other is equal to this list; otherwise returns - false. - - Two lists are considered equal if they contain the same values in - the same order. - - This function requires the value type to have an implementation of - \c operator==(). - - \sa operator!=() -*/ - -/*! \fn template bool QList::operator!=(const QList &other) const - - Returns \c true if \a other is not equal to this list; otherwise - returns \c false. - - Two lists are considered equal if they contain the same values in - the same order. - - This function requires the value type to have an implementation of - \c operator==(). - - \sa operator==() -*/ - -/*! \fn template bool operator<(const QList &lhs, const QList &rhs) - \since 5.6 - \relates QList - - Returns \c true if list \a lhs is - \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} - {lexicographically less than} \a rhs; otherwise returns \c false. - - This function requires the value type to have an implementation - of \c operator<(). -*/ - -/*! \fn template bool operator<=(const QList &lhs, const QList &rhs) - \since 5.6 - \relates QList - - Returns \c true if list \a lhs is - \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} - {lexicographically less than or equal to} \a rhs; otherwise returns \c false. - - This function requires the value type to have an implementation - of \c operator<(). -*/ - -/*! \fn template bool operator>(const QList &lhs, const QList &rhs) - \since 5.6 - \relates QList - - Returns \c true if list \a lhs is - \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} - {lexicographically greater than} \a rhs; otherwise returns \c false. - - This function requires the value type to have an implementation - of \c operator<(). -*/ - -/*! \fn template bool operator>=(const QList &lhs, const QList &rhs) - \since 5.6 - \relates QList - - Returns \c true if list \a lhs is - \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} - {lexicographically greater than or equal to} \a rhs; otherwise returns \c false. - - This function requires the value type to have an implementation - of \c operator<(). -*/ - -/*! - \fn template uint qHash(const QList &key, uint seed = 0) - \since 5.6 - \relates QList - - Returns the hash value for \a key, - using \a seed to seed the calculation. - - This function requires qHash() to be overloaded for the value type \c T. -*/ - -/*! - \fn template int QList::size() const - - Returns the number of items in the list. - - \sa isEmpty(), count() -*/ - -/*! \fn template void QList::detach() - - \internal -*/ - -/*! \fn template void QList::detachShared() - - \internal - - like detach(), but does nothing if we're shared_null. - This prevents needless mallocs, and makes QList more exception safe - in case of cleanup work done in destructors on empty lists. -*/ - -/*! \fn template bool QList::isDetached() const - - \internal -*/ - -/*! \fn template void QList::setSharable(bool sharable) - - \internal -*/ - -/*! \fn template bool QList::isSharedWith(const QList &other) const - - \internal -*/ - -/*! \fn template bool QList::isEmpty() const - - Returns \c true if the list contains no items; otherwise returns - false. - - \sa size() -*/ - -/*! \fn template void QList::clear() - - Removes all items from the list. - - \sa removeAll() -*/ - -/*! \fn template const T &QList::at(int i) const - - Returns the item at index position \a i in the list. \a i must be - a valid index position in the list (i.e., 0 <= \a i < size()). - - This function is very fast (\l{Algorithmic Complexity}{constant time}). - - \sa value(), operator[]() -*/ - -/*! \fn template T &QList::operator[](int i) - - Returns the item at index position \a i as a modifiable reference. - \a i must be a valid index position in the list (i.e., 0 <= \a i < - size()). - - If this function is called on a list that is currently being shared, it - will trigger a copy of all elements. Otherwise, this function runs in - \l{Algorithmic Complexity}{constant time}. If you do not want to modify - the list you should use QList::at(). - - \sa at(), value() -*/ - -/*! \fn template const T &QList::operator[](int i) const - - \overload - - Same as at(). This function runs in \l{Algorithmic Complexity}{constant time}. -*/ - -/*! \fn template void QList::reserve(int alloc) - - Reserve space for \a alloc elements. - - If \a alloc is smaller than the current size of the list, nothing will happen. - - Use this function to avoid repetetive reallocation of QList's internal - data if you can predict how many elements will be appended. - Note that the reservation applies only to the internal pointer array. - - \since 4.7 -*/ - -/*! \fn template void QList::append(const T &value) - - Inserts \a value at the end of the list. - - Example: - \snippet code/src_corelib_tools_qlistdata.cpp 6 - - This is the same as list.insert(size(), \a value). - - If this list is not shared, this operation is typically - very fast (amortized \l{Algorithmic Complexity}{constant time}), - because QList preallocates extra space on both sides of its - internal buffer to allow for fast growth at both ends of the list. - - \sa operator<<(), prepend(), insert() -*/ - -/*! \fn template void QList::append(const QList &value) - - \overload - - \since 4.5 - - Appends the items of the \a value list to this list. - - \sa operator<<(), operator+=() -*/ - -/*! \fn template void QList::prepend(const T &value) - - Inserts \a value at the beginning of the list. - - Example: - \snippet code/src_corelib_tools_qlistdata.cpp 7 - - This is the same as list.insert(0, \a value). - - If this list is not shared, this operation is typically - very fast (amortized \l{Algorithmic Complexity}{constant time}), - because QList preallocates extra space on both sides of its - internal buffer to allow for fast growth at both ends of the list. - - \sa append(), insert() -*/ - -/*! \fn template void QList::insert(int i, const T &value) - - Inserts \a value at index position \a i in the list. - - If \a i == 0, the value is prepended to the list. If \a i == size(), - the value is appended to the list. - - Example: - \snippet code/src_corelib_tools_qlistdata.cpp 8 - - \sa append(), prepend(), replace(), removeAt() -*/ - -/*! \fn template QList::iterator QList::insert(iterator before, const T &value) - - \overload - - Inserts \a value in front of the item pointed to by the - iterator \a before. Returns an iterator pointing at the inserted - item. Note that the iterator passed to the function will be - invalid after the call; the returned iterator should be used - instead. -*/ - -/*! \fn template void QList::replace(int i, const T &value) - - Replaces the item at index position \a i with \a value. \a i must - be a valid index position in the list (i.e., 0 <= \a i < size()). - - \sa operator[](), removeAt() -*/ - -/*! - \fn template int QList::removeAll(const T &value) - - Removes all occurrences of \a value in the list and returns the - number of entries removed. - - Example: - \snippet code/src_corelib_tools_qlistdata.cpp 9 - - This function requires the value type to have an implementation of - \c operator==(). - - \sa removeOne(), removeAt(), takeAt(), replace() -*/ - -/*! - \fn template bool QList::removeOne(const T &value) - \since 4.4 - - Removes the first occurrence of \a value in the list and returns - true on success; otherwise returns \c false. - - Example: - \snippet code/src_corelib_tools_qlistdata.cpp 10 - - This function requires the value type to have an implementation of - \c operator==(). - - \sa removeAll(), removeAt(), takeAt(), replace() -*/ - -/*! \fn template void QList::removeAt(int i) - - Removes the item at index position \a i. \a i must be a valid - index position in the list (i.e., 0 <= \a i < size()). - - \sa takeAt(), removeFirst(), removeLast(), removeOne() -*/ - -/*! \fn template T QList::takeAt(int i) - - Removes the item at index position \a i and returns it. \a i must - be a valid index position in the list (i.e., 0 <= \a i < size()). - - If you don't use the return value, removeAt() is more efficient. - - \sa removeAt(), takeFirst(), takeLast() -*/ - -/*! \fn template T QList::takeFirst() - - Removes the first item in the list and returns it. This is the - same as takeAt(0). This function assumes the list is not empty. To - avoid failure, call isEmpty() before calling this function. - - If this list is not shared, this operation takes - \l {Algorithmic Complexity}{constant time}. - - If you don't use the return value, removeFirst() is more - efficient. - - \sa takeLast(), takeAt(), removeFirst() -*/ - -/*! \fn template T QList::takeLast() - - Removes the last item in the list and returns it. This is the - same as takeAt(size() - 1). This function assumes the list is - not empty. To avoid failure, call isEmpty() before calling this - function. - - If this list is not shared, this operation takes - \l {Algorithmic Complexity}{constant time}. - - If you don't use the return value, removeLast() is more - efficient. - - \sa takeFirst(), takeAt(), removeLast() -*/ - -/*! \fn template void QList::move(int from, int to) - - Moves the item at index position \a from to index position \a to. - - Example: - \snippet code/src_corelib_tools_qlistdata.cpp 11 - - This is the same as insert(\a{to}, takeAt(\a{from})).This function - assumes that both \a from and \a to are at least 0 but less than - size(). To avoid failure, test that both \a from and \a to are at - least 0 and less than size(). - - \sa swap(), insert(), takeAt() -*/ - -/*! \fn template void QList::swap(int i, int j) - - \obsolete Use swapItemsAt() - - \sa move(), swapItemsAt() -*/ - -/*! \fn template void QList::swapItemsAt(int i, int j) - \since 5.13 - - Exchange the item at index position \a i with the item at index - position \a j. This function assumes that both \a i and \a j are - at least 0 but less than size(). To avoid failure, test that both - \a i and \a j are at least 0 and less than size(). - - Example: - \snippet code/src_corelib_tools_qlistdata.cpp 12 - - \sa move() -*/ - -/*! \fn template int QList::indexOf(const T &value, int from = 0) const - - Returns the index position of the first occurrence of \a value in - the list, searching forward from index position \a from. Returns - -1 if no item matched. - - Example: - \snippet code/src_corelib_tools_qlistdata.cpp 13 - - This function requires the value type to have an implementation of - \c operator==(). - - Note that QList uses 0-based indexes, just like C++ arrays. Negative - indexes are not supported with the exception of the value mentioned - above. - - \sa lastIndexOf(), contains() -*/ - -/*! \fn template int QList::lastIndexOf(const T &value, int from = -1) const - - Returns the index position of the last occurrence of \a value in - the list, searching backward from index position \a from. If \a - from is -1 (the default), the search starts at the last item. - Returns -1 if no item matched. - - Example: - \snippet code/src_corelib_tools_qlistdata.cpp 14 - - This function requires the value type to have an implementation of - \c operator==(). - - Note that QList uses 0-based indexes, just like C++ arrays. Negative - indexes are not supported with the exception of the value mentioned - above. - - \sa indexOf() -*/ - -/*! \fn template bool QList::contains(const T &value) const - - Returns \c true if the list contains an occurrence of \a value; - otherwise returns \c false. - - This function requires the value type to have an implementation of - \c operator==(). - - \sa indexOf(), count() -*/ - -/*! \fn template int QList::count(const T &value) const - - Returns the number of occurrences of \a value in the list. - - This function requires the value type to have an implementation of - \c operator==(). - - \sa contains(), indexOf() -*/ - -/*! \fn template bool QList::startsWith(const T &value) const - \since 4.5 - - Returns \c true if this list is not empty and its first - item is equal to \a value; otherwise returns \c false. - - \sa isEmpty(), contains() -*/ - -/*! \fn template bool QList::endsWith(const T &value) const - \since 4.5 - - Returns \c true if this list is not empty and its last - item is equal to \a value; otherwise returns \c false. - - \sa isEmpty(), contains() -*/ - -/*! \fn template QList::iterator QList::begin() - - Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in - the list. - - \sa constBegin(), end() -*/ - -/*! \fn template QList::const_iterator QList::begin() const - - \overload -*/ - -/*! \fn template QList::const_iterator QList::cbegin() const - \since 5.0 - - Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item - in the list. - - \sa begin(), cend() -*/ - -/*! \fn template QList::const_iterator QList::constBegin() const - - Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item - in the list. - - \sa begin(), constEnd() -*/ - -/*! \fn template QList::iterator QList::end() - - Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item - after the last item in the list. - - \sa begin(), constEnd() -*/ - -/*! \fn template const_iterator QList::end() const - - \overload -*/ - -/*! \fn template QList::const_iterator QList::cend() const - \since 5.0 - - Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary - item after the last item in the list. - - \sa cbegin(), end() -*/ - -/*! \fn template QList::const_iterator QList::constEnd() const - - Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary - item after the last item in the list. - - \sa constBegin(), end() -*/ - -/*! \fn template QList::reverse_iterator QList::rbegin() - \since 5.6 - - Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first - item in the list, in reverse order. - - \sa begin(), crbegin(), rend() -*/ - -/*! \fn template QList::const_reverse_iterator QList::rbegin() const - \since 5.6 - \overload -*/ - -/*! \fn template QList::const_reverse_iterator QList::crbegin() const - \since 5.6 - - Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first - item in the list, in reverse order. - - \sa begin(), rbegin(), rend() -*/ - -/*! \fn template QList::reverse_iterator QList::rend() - \since 5.6 - - Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past - the last item in the list, in reverse order. - - \sa end(), crend(), rbegin() -*/ - -/*! \fn template QList::const_reverse_iterator QList::rend() const - \since 5.6 - \overload -*/ - -/*! \fn template QList::const_reverse_iterator QList::crend() const - \since 5.6 - - Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one - past the last item in the list, in reverse order. - - \sa end(), rend(), rbegin() -*/ - -/*! \fn template QList::iterator QList::erase(iterator pos) - - Removes the item associated with the iterator \a pos from the - list, and returns an iterator to the next item in the list (which - may be end()). - - \sa insert(), removeAt() -*/ - -/*! \fn template QList::iterator QList::erase(iterator begin, iterator end) - - \overload - - Removes all the items from \a begin up to (but not including) \a - end. Returns an iterator to the same item that \a end referred to - before the call. -*/ - -/*! \typedef QList::Iterator - - Qt-style synonym for QList::iterator. -*/ - -/*! \typedef QList::ConstIterator - - Qt-style synonym for QList::const_iterator. -*/ - -/*! - \typedef QList::size_type - - Typedef for int. Provided for STL compatibility. -*/ - -/*! - \typedef QList::value_type - - Typedef for T. Provided for STL compatibility. -*/ - -/*! - \typedef QList::difference_type - - Typedef for ptrdiff_t. Provided for STL compatibility. -*/ - -/*! - \typedef QList::pointer - - Typedef for T *. Provided for STL compatibility. -*/ - -/*! - \typedef QList::const_pointer - - Typedef for const T *. Provided for STL compatibility. -*/ - -/*! - \typedef QList::reference - - Typedef for T &. Provided for STL compatibility. -*/ - -/*! - \typedef QList::const_reference - - Typedef for const T &. Provided for STL compatibility. -*/ - -/*! \typedef QList::reverse_iterator - \since 5.6 - - The QList::reverse_iterator typedef provides an STL-style non-const - reverse iterator for QList. - - It is simply a typedef for \c{std::reverse_iterator}. - - \warning Iterators on implicitly shared containers do not work - exactly like STL-iterators. You should avoid copying a container - while iterators are active on that container. For more information, - read \l{Implicit sharing iterator problem}. - - \sa QList::rbegin(), QList::rend(), QList::const_reverse_iterator, QList::iterator -*/ - -/*! \typedef QList::const_reverse_iterator - \since 5.6 - - The QList::const_reverse_iterator typedef provides an STL-style const - reverse iterator for QList. - - It is simply a typedef for \c{std::reverse_iterator}. - - \warning Iterators on implicitly shared containers do not work - exactly like STL-iterators. You should avoid copying a container - while iterators are active on that container. For more information, - read \l{Implicit sharing iterator problem}. - - \sa QList::rbegin(), QList::rend(), QList::reverse_iterator, QList::const_iterator -*/ - -/*! \fn template int QList::count() const - - Returns the number of items in the list. This is effectively the - same as size(). -*/ - -/*! \fn template int QList::length() const - \since 4.5 - - This function is identical to count(). - - \sa count() -*/ - -/*! \fn template T& QList::first() - - Returns a reference to the first item in the list. The list must - not be empty. If the list can be empty, call isEmpty() before - calling this function. - - \sa constFirst(), last(), isEmpty() -*/ - -/*! \fn template const T& QList::first() const - - \overload -*/ - -/*! \fn template const T& QList::constFirst() const - \since 5.6 - - Returns a const reference to the first item in the list. The list must - not be empty. If the list can be empty, call isEmpty() before - calling this function. - - \sa constLast(), isEmpty(), first() -*/ - -/*! \fn template T& QList::last() - - Returns a reference to the last item in the list. The list must - not be empty. If the list can be empty, call isEmpty() before - calling this function. - - \sa constLast(), first(), isEmpty() -*/ - -/*! \fn template const T& QList::last() const - - \overload -*/ - -/*! \fn template const T& QList::constLast() const - \since 5.6 - - Returns a reference to the last item in the list. The list must - not be empty. If the list can be empty, call isEmpty() before - calling this function. - - \sa constFirst(), isEmpty(), last() -*/ - -/*! \fn template void QList::removeFirst() - - Removes the first item in the list. Calling this function is - equivalent to calling removeAt(0). The list must not be empty. If - the list can be empty, call isEmpty() before calling this - function. - - \sa removeAt(), takeFirst() -*/ - -/*! \fn template void QList::removeLast() - - Removes the last item in the list. Calling this function is - equivalent to calling removeAt(size() - 1). The list must not be - empty. If the list can be empty, call isEmpty() before calling - this function. - - \sa removeAt(), takeLast() -*/ - -/*! \fn template T QList::value(int i) const - - Returns the value at index position \a i in the list. - - If the index \a i is out of bounds, the function returns a - \l{default-constructed value}. If you are certain that the index - is going to be within bounds, you can use at() instead, which is - slightly faster. - - \sa at(), operator[]() -*/ - -/*! \fn template T QList::value(int i, const T &defaultValue) const - - \overload - - If the index \a i is out of bounds, the function returns - \a defaultValue. -*/ - -/*! \fn template void QList::push_back(const T &value) - - This function is provided for STL compatibility. It is equivalent - to \l{QList::append()}{append(\a value)}. -*/ - -/*! \fn template void QList::push_front(const T &value) - - This function is provided for STL compatibility. It is equivalent - to \l{QList::prepend()}{prepend(\a value)}. -*/ - -/*! \fn template T& QList::front() - - This function is provided for STL compatibility. It is equivalent - to first(). The list must not be empty. If the list can be empty, - call isEmpty() before calling this function. -*/ - -/*! \fn template const T& QList::front() const - - \overload -*/ - -/*! \fn template T& QList::back() - - This function is provided for STL compatibility. It is equivalent - to last(). The list must not be empty. If the list can be empty, - call isEmpty() before calling this function. -*/ - -/*! \fn template const T& QList::back() const - - \overload -*/ - -/*! \fn template void QList::pop_front() - - This function is provided for STL compatibility. It is equivalent - to removeFirst(). The list must not be empty. If the list can be - empty, call isEmpty() before calling this function. -*/ - -/*! \fn template void QList::pop_back() - - This function is provided for STL compatibility. It is equivalent - to removeLast(). The list must not be empty. If the list can be - empty, call isEmpty() before calling this function. -*/ - -/*! \fn template bool QList::empty() const - - This function is provided for STL compatibility. It is equivalent - to isEmpty() and returns \c true if the list is empty. -*/ - -/*! \fn template QList &QList::operator+=(const QList &other) - - Appends the items of the \a other list to this list and returns a - reference to this list. - - \sa operator+(), append() -*/ - -/*! \fn template void QList::operator+=(const T &value) - - \overload - - Appends \a value to the list. - - \sa append(), operator<<() -*/ - -/*! \fn template QList QList::operator+(const QList &other) const - - Returns a list that contains all the items in this list followed - by all the items in the \a other list. - - \sa operator+=() -*/ - -/*! \fn template QList &QList::operator<<(const QList &other) - - Appends the items of the \a other list to this list and returns a - reference to this list. - - \sa operator+=(), append() -*/ - -/*! \fn template void QList::operator<<(const T &value) - - \overload - - Appends \a value to the list. -*/ - -/*! \class QList::iterator - \inmodule QtCore - \brief The QList::iterator class provides an STL-style non-const iterator for QList and QQueue. - - QList features both \l{STL-style iterators} and \l{Java-style - iterators}. The STL-style iterators are more low-level and more - cumbersome to use; on the other hand, they are slightly faster - and, for developers who already know STL, have the advantage of - familiarity. - - QList\::iterator allows you to iterate over a QList\ (or - QQueue\) and to modify the list item associated with the - iterator. If you want to iterate over a const QList, use - QList::const_iterator instead. It is generally good practice to - use QList::const_iterator on a non-const QList as well, unless - you need to change the QList through the iterator. Const - iterators are slightly faster, and can improve code readability. - - The default QList::iterator constructor creates an uninitialized - iterator. You must initialize it using a QList function like - QList::begin(), QList::end(), or QList::insert() before you can - start iterating. Here's a typical loop that prints all the items - stored in a list: - - \snippet code/src_corelib_tools_qlistdata.cpp 15 - - Let's see a few examples of things we can do with a - QList::iterator that we cannot do with a QList::const_iterator. - Here's an example that increments every value stored in a - QList\ by 2: - - \snippet code/src_corelib_tools_qlistdata.cpp 16 - - Most QList functions accept an integer index rather than an - iterator. For that reason, iterators are rarely useful in - connection with QList. One place where STL-style iterators do - make sense is as arguments to \l{generic algorithms}. - - For example, here's how to delete all the widgets stored in a - QList\: - - \snippet code/src_corelib_tools_qlistdata.cpp 17 - - Multiple iterators can be used on the same list. However, be - aware that any non-const function call performed on the QList - will render all existing iterators undefined. If you need to keep - iterators over a long period of time, we recommend that you use - QLinkedList rather than QList. - - \warning Iterators on implicitly shared containers do not work - exactly like STL-iterators. You should avoid copying a container - while iterators are active on that container. For more information, - read \l{Implicit sharing iterator problem}. - - \sa QList::const_iterator, QMutableListIterator -*/ - -/*! \typedef QList::iterator::iterator_category - - A synonym for \e {std::random_access_iterator_tag} indicating - this iterator is a random access iterator. -*/ - -/*! \typedef QList::iterator::difference_type - - \internal -*/ - -/*! \typedef QList::iterator::value_type - - \internal -*/ - -/*! \typedef QList::iterator::pointer - - \internal -*/ - -/*! \typedef QList::iterator::reference - - \internal -*/ - -/*! \fn template QList::iterator::iterator() - - Constructs an uninitialized iterator. - - Functions like operator*() and operator++() should not be called - on an uninitialized iterator. Use operator=() to assign a value - to it before using it. - - \sa QList::begin(), QList::end() -*/ - -/*! \fn template QList::iterator::iterator(Node *node) - - \internal -*/ - -/*! \fn template QList::iterator::iterator(const iterator &other) - - Constructs a copy of \a other. -*/ - -/*! \fn template T &QList::iterator::operator*() const - - Returns a modifiable reference to the current item. - - You can change the value of an item by using operator*() on the - left side of an assignment, for example: - - \snippet code/src_corelib_tools_qlistdata.cpp 18 - - \sa operator->() -*/ - -/*! \fn template T *QList::iterator::operator->() const - - Returns a pointer to the current item. - - \sa operator*() -*/ - -/*! \fn template T &QList::iterator::operator[](difference_type j) const - - Returns a modifiable reference to the item at position *this + - \a{j}. - - This function is provided to make QList iterators behave like C++ - pointers. - - \sa operator+() -*/ - -/*! - \fn template bool QList::iterator::operator==(const iterator &other) const - \fn template bool QList::iterator::operator==(const const_iterator &other) const - - Returns \c true if \a other points to the same item as this - iterator; otherwise returns \c false. - - \sa operator!=() -*/ - -/*! - \fn template bool QList::iterator::operator!=(const iterator &other) const - \fn template bool QList::iterator::operator!=(const const_iterator &other) const - - Returns \c true if \a other points to a different item than this - iterator; otherwise returns \c false. - - \sa operator==() -*/ - -/*! - \fn template bool QList::iterator::operator<(const iterator& other) const - \fn template bool QList::iterator::operator<(const const_iterator& other) const - - Returns \c true if the item pointed to by this iterator is less than - the item pointed to by the \a other iterator. -*/ - -/*! - \fn template bool QList::iterator::operator<=(const iterator& other) const - \fn template bool QList::iterator::operator<=(const const_iterator& other) const - - Returns \c true if the item pointed to by this iterator is less than - or equal to the item pointed to by the \a other iterator. -*/ - -/*! - \fn template bool QList::iterator::operator>(const iterator& other) const - \fn template bool QList::iterator::operator>(const const_iterator& other) const - - Returns \c true if the item pointed to by this iterator is greater - than the item pointed to by the \a other iterator. -*/ - -/*! - \fn template bool QList::iterator::operator>=(const iterator& other) const - \fn template bool QList::iterator::operator>=(const const_iterator& other) const - - Returns \c true if the item pointed to by this iterator is greater - than or equal to the item pointed to by the \a other iterator. -*/ - -/*! \fn template QList::iterator &QList::iterator::operator++() - - The prefix ++ operator (\c{++it}) advances the iterator to the - next item in the list and returns an iterator to the new current - item. - - Calling this function on QList::end() leads to undefined results. - - \sa operator--() -*/ - -/*! \fn template QList::iterator QList::iterator::operator++(int) - - \overload - - The postfix ++ operator (\c{it++}) advances the iterator to the - next item in the list and returns an iterator to the previously - current item. -*/ - -/*! \fn template QList::iterator &QList::iterator::operator--() - - The prefix -- operator (\c{--it}) makes the preceding item - current and returns an iterator to the new current item. - - Calling this function on QList::begin() leads to undefined results. - - \sa operator++() -*/ - -/*! \fn template QList::iterator QList::iterator::operator--(int) - - \overload - - The postfix -- operator (\c{it--}) makes the preceding item - current and returns an iterator to the previously current item. -*/ - -/*! \fn template QList::iterator &QList::iterator::operator+=(difference_type j) - - Advances the iterator by \a j items. (If \a j is negative, the - iterator goes backward.) - - \sa operator-=(), operator+() -*/ - -/*! \fn template QList::iterator &QList::iterator::operator-=(difference_type j) - - Makes the iterator go back by \a j items. (If \a j is negative, - the iterator goes forward.) - - \sa operator+=(), operator-() -*/ - -/*! \fn template QList::iterator QList::iterator::operator+(difference_type j) const - - Returns an iterator to the item at \a j positions forward from - this iterator. (If \a j is negative, the iterator goes backward.) - - \sa operator-(), operator+=() -*/ - -/*! \fn template QList::iterator QList::iterator::operator-(difference_type j) const - - Returns an iterator to the item at \a j positions backward from - this iterator. (If \a j is negative, the iterator goes forward.) - - \sa operator+(), operator-=() -*/ - -/*! \fn template int QList::iterator::operator-(iterator other) const - - Returns the number of items between the item pointed to by \a - other and the item pointed to by this iterator. -*/ - -/*! \class QList::const_iterator - \inmodule QtCore - \brief The QList::const_iterator class provides an STL-style const iterator for QList and QQueue. - - QList provides both \l{STL-style iterators} and \l{Java-style - iterators}. The STL-style iterators are more low-level and more - cumbersome to use; on the other hand, they are slightly faster - and, for developers who already know STL, have the advantage of - familiarity. - - QList\::const_iterator allows you to iterate over a - QList\ (or a QQueue\). If you want to modify the QList as - you iterate over it, use QList::iterator instead. It is generally - good practice to use QList::const_iterator on a non-const QList - as well, unless you need to change the QList through the - iterator. Const iterators are slightly faster, and can improve - code readability. - - The default QList::const_iterator constructor creates an - uninitialized iterator. You must initialize it using a QList - function like QList::constBegin(), QList::constEnd(), or - QList::insert() before you can start iterating. Here's a typical - loop that prints all the items stored in a list: - - \snippet code/src_corelib_tools_qlistdata.cpp 19 - - Most QList functions accept an integer index rather than an - iterator. For that reason, iterators are rarely useful in - connection with QList. One place where STL-style iterators do - make sense is as arguments to \l{generic algorithms}. - - For example, here's how to delete all the widgets stored in a - QList\: - - \snippet code/src_corelib_tools_qlistdata.cpp 20 - - Multiple iterators can be used on the same list. However, be - aware that any non-const function call performed on the QList - will render all existing iterators undefined. If you need to keep - iterators over a long period of time, we recommend that you use - QLinkedList rather than QList. - - \warning Iterators on implicitly shared containers do not work - exactly like STL-iterators. You should avoid copying a container - while iterators are active on that container. For more information, - read \l{Implicit sharing iterator problem}. - - \sa QList::iterator, QListIterator -*/ - -/*! \fn template QList::const_iterator::const_iterator() - - Constructs an uninitialized iterator. - - Functions like operator*() and operator++() should not be called - on an uninitialized iterator. Use operator=() to assign a value - to it before using it. - - \sa QList::constBegin(), QList::constEnd() -*/ - -/*! \typedef QList::const_iterator::iterator_category - - A synonym for \e {std::random_access_iterator_tag} indicating - this iterator is a random access iterator. -*/ - -/*! \typedef QList::const_iterator::difference_type - - \internal -*/ - -/*! \typedef QList::const_iterator::value_type - - \internal -*/ - -/*! \typedef QList::const_iterator::pointer - - \internal -*/ - -/*! \typedef QList::const_iterator::reference - - \internal -*/ - -/*! \fn template QList::const_iterator::const_iterator(Node *node) - - \internal -*/ - -/*! \fn template QList::const_iterator::const_iterator(const const_iterator &other) - - Constructs a copy of \a other. -*/ - -/*! \fn template QList::const_iterator::const_iterator(const iterator &other) - - Constructs a copy of \a other. -*/ - -/*! \fn template const T &QList::const_iterator::operator*() const - - Returns the current item. - - \sa operator->() -*/ - -/*! \fn template const T *QList::const_iterator::operator->() const - - Returns a pointer to the current item. - - \sa operator*() -*/ - -/*! \fn template const T &QList::const_iterator::operator[](difference_type j) const - - Returns the item at position *this + \a{j}. - - This function is provided to make QList iterators behave like C++ - pointers. - - \sa operator+() -*/ - -/*! \fn template bool QList::const_iterator::operator==(const const_iterator &other) const - - Returns \c true if \a other points to the same item as this - iterator; otherwise returns \c false. - - \sa operator!=() -*/ - -/*! \fn template bool QList::const_iterator::operator!=(const const_iterator &other) const - - Returns \c true if \a other points to a different item than this - iterator; otherwise returns \c false. - - \sa operator==() -*/ - -/*! - \fn template bool QList::const_iterator::operator<(const const_iterator& other) const - - Returns \c true if the item pointed to by this iterator is less than - the item pointed to by the \a other iterator. -*/ - -/*! - \fn template bool QList::const_iterator::operator<=(const const_iterator& other) const - - Returns \c true if the item pointed to by this iterator is less than - or equal to the item pointed to by the \a other iterator. -*/ - -/*! - \fn template bool QList::const_iterator::operator>(const const_iterator& other) const - - Returns \c true if the item pointed to by this iterator is greater - than the item pointed to by the \a other iterator. -*/ - -/*! - \fn template bool QList::const_iterator::operator>=(const const_iterator& other) const - - Returns \c true if the item pointed to by this iterator is greater - than or equal to the item pointed to by the \a other iterator. -*/ - -/*! \fn template QList::const_iterator &QList::const_iterator::operator++() - - The prefix ++ operator (\c{++it}) advances the iterator to the - next item in the list and returns an iterator to the new current - item. - - Calling this function on QList::end() leads to undefined results. - - \sa operator--() -*/ - -/*! \fn template QList::const_iterator QList::const_iterator::operator++(int) - - \overload - - The postfix ++ operator (\c{it++}) advances the iterator to the - next item in the list and returns an iterator to the previously - current item. -*/ - -/*! \fn template QList::const_iterator &QList::const_iterator::operator--() - - The prefix -- operator (\c{--it}) makes the preceding item - current and returns an iterator to the new current item. - - Calling this function on QList::begin() leads to undefined results. - - \sa operator++() -*/ - -/*! \fn template QList::const_iterator QList::const_iterator::operator--(int) - - \overload - - The postfix -- operator (\c{it--}) makes the preceding item - current and returns an iterator to the previously current item. -*/ - -/*! \fn template QList::const_iterator &QList::const_iterator::operator+=(difference_type j) - - Advances the iterator by \a j items. (If \a j is negative, the - iterator goes backward.) - - \sa operator-=(), operator+() -*/ - -/*! \fn template QList::const_iterator &QList::const_iterator::operator-=(difference_type j) - - Makes the iterator go back by \a j items. (If \a j is negative, - the iterator goes forward.) - - \sa operator+=(), operator-() -*/ - -/*! \fn template QList::const_iterator QList::const_iterator::operator+(difference_type j) const - - Returns an iterator to the item at \a j positions forward from - this iterator. (If \a j is negative, the iterator goes backward.) - - \sa operator-(), operator+=() -*/ - -/*! \fn template QList::const_iterator QList::const_iterator::operator-(difference_type j) const - - Returns an iterator to the item at \a j positions backward from - this iterator. (If \a j is negative, the iterator goes forward.) - - \sa operator+(), operator-=() -*/ - -/*! \fn template int QList::const_iterator::operator-(const_iterator other) const - - Returns the number of items between the item pointed to by \a - other and the item pointed to by this iterator. -*/ - -/*! \fn template QDataStream &operator<<(QDataStream &out, const QList &list) - \relates QList - - Writes the list \a list to stream \a out. - - This function requires the value type to implement \c - operator<<(). - - \sa{Serializing Qt Data Types}{Format of the QDataStream operators} -*/ - -/*! \fn template QDataStream &operator>>(QDataStream &in, QList &list) - \relates QList - - Reads a list from stream \a in into \a list. - - This function requires the value type to implement \c - operator>>(). - - \sa{Serializing Qt Data Types}{Format of the QDataStream operators} -*/ - -/*! \fn template QList QList::fromVector(const QVector &vector) - - Returns a QList object with the data contained in \a vector. - - Example: - - \snippet code/src_corelib_tools_qlistdata.cpp 21 - - \include containers-range-constructor.qdocinc - - \sa fromSet(), toVector(), QVector::toList() -*/ - -/*! \fn template QVector QList::toVector() const - - Returns a QVector object with the data contained in this QList. - - Example: - - \snippet code/src_corelib_tools_qlistdata.cpp 22 - - \include containers-range-constructor.qdocinc - - \sa toSet(), fromVector(), QVector::fromList() -*/ - -/*! \fn template QList QList::fromSet(const QSet &set) - - Returns a QList object with the data contained in \a set. The - order of the elements in the QList is undefined. - - Example: - - \snippet code/src_corelib_tools_qlistdata.cpp 23 - - \include containers-range-constructor.qdocinc - - \sa fromVector(), toSet(), QSet::toList() -*/ - -/*! \fn template QSet QList::toSet() const - - Returns a QSet object with the data contained in this QList. - Since QSet doesn't allow duplicates, the resulting QSet might be - smaller than the original list was. - - Example: - - \snippet code/src_corelib_tools_qlistdata.cpp 24 - - \include containers-range-constructor.qdocinc - - \sa toVector(), fromSet(), QSet::fromList() -*/ - -/*! \fn template QList QList::fromStdList(const std::list &list) - - Returns a QList object with the data contained in \a list. The - order of the elements in the QList is the same as in \a list. - - Example: - - \snippet code/src_corelib_tools_qlistdata.cpp 25 - - \include containers-range-constructor.qdocinc - - \sa toStdList(), QVector::fromStdVector() -*/ - -/*! \fn template std::list QList::toStdList() const - - Returns a std::list object with the data contained in this QList. - Example: - - \snippet code/src_corelib_tools_qlistdata.cpp 26 - - \include containers-range-constructor.qdocinc - - \sa fromStdList(), QVector::toStdVector() -*/ - QT_END_NAMESPACE diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 5dde80417d..2e9fad3bfe 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -40,1149 +40,17 @@ #ifndef QLIST_H #define QLIST_H -#include -#include -#include -#include -#include #include -#include - -#include -#include -#include -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) -#include -#endif - -#include -#include -#include -#include - -#ifdef Q_CC_MSVC -#pragma warning( push ) -#pragma warning( disable : 4127 ) // "conditional expression is constant" -#endif - -QT_BEGIN_NAMESPACE - - -template class QVector; -template class QSet; - -struct Q_CORE_EXPORT QListData { - // tags for tag-dispatching of QList implementations, - // based on QList's three different memory layouts: - struct NotArrayCompatibleLayout {}; - struct NotIndirectLayout {}; - struct ArrayCompatibleLayout : NotIndirectLayout {}; // data laid out like a C array - struct InlineWithPaddingLayout : NotArrayCompatibleLayout, NotIndirectLayout {}; // data laid out like a C array with padding - struct IndirectLayout : NotArrayCompatibleLayout {}; // data allocated on the heap - - struct Data { - QtPrivate::RefCount ref; - int alloc, begin, end; - void *array[1]; - }; - enum { DataHeaderSize = sizeof(Data) - sizeof(void *) }; - - Data *detach(int alloc); - Data *detach_grow(int *i, int n); - void realloc(int alloc); - void realloc_grow(int growth); - inline void dispose() { dispose(d); } - static void dispose(Data *d); - static const Data shared_null; - Data *d; - void **erase(void **xi); - void **append(int n); - void **append(); - void **append(const QListData &l); - void **prepend(); - void **insert(int i); - void remove(int i); - void remove(int i, int n); - void move(int from, int to); - inline int size() const noexcept { return int(d->end - d->begin); } // q6sizetype - inline bool isEmpty() const noexcept { return d->end == d->begin; } - inline void **at(int i) const noexcept { return d->array + d->begin + i; } - inline void **begin() const noexcept { return d->array + d->begin; } - inline void **end() const noexcept { return d->array + d->end; } -}; - -namespace QtPrivate { - template int indexOf(const QList &list, const U &u, int from); - template int lastIndexOf(const QList &list, const U &u, int from); -} - -template -class QList -{ -public: - struct MemoryLayout - : std::conditional< - // must stay isStatic until ### Qt 6 for BC reasons (don't use !isRelocatable)! - QTypeInfo::isStatic || QTypeInfo::isLarge, - QListData::IndirectLayout, - typename std::conditional< - sizeof(T) == sizeof(void*), - QListData::ArrayCompatibleLayout, - QListData::InlineWithPaddingLayout - >::type>::type {}; -private: - template friend int QtPrivate::indexOf(const QList &list, const U &u, int from); - template friend int QtPrivate::lastIndexOf(const QList &list, const U &u, int from); - struct Node { void *v; -#if defined(Q_CC_BOR) - Q_INLINE_TEMPLATE T &t(); -#else - Q_INLINE_TEMPLATE T &t() - { return *reinterpret_cast(QTypeInfo::isLarge || QTypeInfo::isStatic - ? v : this); } -#endif - }; - - union { QListData p; QListData::Data *d; }; - -public: - inline QList() noexcept : d(const_cast(&QListData::shared_null)) { } - QList(const QList &l); - ~QList(); - QList &operator=(const QList &l); - inline QList(QList &&other) noexcept - : d(other.d) { other.d = const_cast(&QListData::shared_null); } - inline QList &operator=(QList &&other) noexcept - { QList moved(std::move(other)); swap(moved); return *this; } - inline void swap(QList &other) noexcept { qSwap(d, other.d); } - inline QList(std::initializer_list args) - : QList(args.begin(), args.end()) {} - template = true> - QList(InputIterator first, InputIterator last); - bool operator==(const QList &l) const; - inline bool operator!=(const QList &l) const { return !(*this == l); } - - inline int size() const noexcept { return p.size(); } - - inline void detach() { if (d->ref.isShared()) detach_helper(); } - - inline void detachShared() - { - // The "this->" qualification is needed for GCCE. - if (d->ref.isShared() && this->d != &QListData::shared_null) - detach_helper(); - } - - inline bool isDetached() const { return !d->ref.isShared(); } -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - inline void setSharable(bool sharable) - { - if (sharable == d->ref.isSharable()) - return; - if (!sharable) - detach(); - if (d != &QListData::shared_null) - d->ref.setSharable(sharable); - } -#endif - inline bool isSharedWith(const QList &other) const noexcept { return d == other.d; } - - inline bool isEmpty() const noexcept { return p.isEmpty(); } - - void clear(); - - const T &at(int i) const; - const T &operator[](int i) const; - T &operator[](int i); - - void reserve(int size); - void append(const T &t); - void append(const QList &t); - void prepend(const T &t); - void insert(int i, const T &t); - void replace(int i, const T &t); - void removeAt(int i); - int removeAll(const T &t); - bool removeOne(const T &t); - T takeAt(int i); - T takeFirst(); - T takeLast(); - void move(int from, int to); - void swapItemsAt(int i, int j); -#if QT_DEPRECATED_SINCE(5, 13) && QT_VERSION < QT_VERSION_CHECK(6,0,0) - QT_DEPRECATED_X("Use QList::swapItemsAt()") - void swap(int i, int j) { swapItemsAt(i, j); } -#endif - int indexOf(const T &t, int from = 0) const; - int lastIndexOf(const T &t, int from = -1) const; - bool contains(const T &t) const; - int count(const T &t) const; - - class const_iterator; - - class iterator { - public: - Node *i; - typedef std::random_access_iterator_tag iterator_category; - // ### Qt6: use int - typedef qptrdiff difference_type; - typedef T value_type; - typedef T *pointer; - typedef T &reference; - - inline iterator() noexcept : i(nullptr) {} - inline iterator(Node *n) noexcept : i(n) {} -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) - // can't remove it in Qt 5, since doing so would make the type trivial, - // which changes the way it's passed to functions by value. - inline iterator(const iterator &o) noexcept : i(o.i){} - inline iterator &operator=(const iterator &o) noexcept - { i = o.i; return *this; } -#endif - inline T &operator*() const { return i->t(); } - inline T *operator->() const { return &i->t(); } - inline T &operator[](difference_type j) const { return i[j].t(); } - inline bool operator==(const iterator &o) const noexcept { return i == o.i; } - inline bool operator!=(const iterator &o) const noexcept { return i != o.i; } - inline bool operator<(const iterator& other) const noexcept { return i < other.i; } - inline bool operator<=(const iterator& other) const noexcept { return i <= other.i; } - inline bool operator>(const iterator& other) const noexcept { return i > other.i; } - inline bool operator>=(const iterator& other) const noexcept { return i >= other.i; } -#ifndef QT_STRICT_ITERATORS - inline bool operator==(const const_iterator &o) const noexcept - { return i == o.i; } - inline bool operator!=(const const_iterator &o) const noexcept - { return i != o.i; } - inline bool operator<(const const_iterator& other) const noexcept - { return i < other.i; } - inline bool operator<=(const const_iterator& other) const noexcept - { return i <= other.i; } - inline bool operator>(const const_iterator& other) const noexcept - { return i > other.i; } - inline bool operator>=(const const_iterator& other) const noexcept - { return i >= other.i; } -#endif - inline iterator &operator++() { ++i; return *this; } - inline iterator operator++(int) { Node *n = i; ++i; return n; } - inline iterator &operator--() { i--; return *this; } - inline iterator operator--(int) { Node *n = i; i--; return n; } - inline iterator &operator+=(difference_type j) { i+=j; return *this; } - inline iterator &operator-=(difference_type j) { i-=j; return *this; } - inline iterator operator+(difference_type j) const { return iterator(i+j); } - inline iterator operator-(difference_type j) const { return iterator(i-j); } - friend inline iterator operator+(difference_type j, iterator k) { return k + j; } - inline int operator-(iterator j) const { return int(i - j.i); } - }; - friend class iterator; - - class const_iterator { - public: - Node *i; - typedef std::random_access_iterator_tag iterator_category; - // ### Qt6: use int - typedef qptrdiff difference_type; - typedef T value_type; - typedef const T *pointer; - typedef const T &reference; - - inline const_iterator() noexcept : i(nullptr) {} - inline const_iterator(Node *n) noexcept : i(n) {} -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) - // can't remove it in Qt 5, since doing so would make the type trivial, - // which changes the way it's passed to functions by value. - inline const_iterator(const const_iterator &o) noexcept : i(o.i) {} - inline const_iterator &operator=(const const_iterator &o) noexcept - { i = o.i; return *this; } -#endif -#ifdef QT_STRICT_ITERATORS - inline explicit const_iterator(const iterator &o) noexcept : i(o.i) {} -#else - inline const_iterator(const iterator &o) noexcept : i(o.i) {} -#endif - inline const T &operator*() const { return i->t(); } - inline const T *operator->() const { return &i->t(); } - inline const T &operator[](difference_type j) const { return i[j].t(); } - inline bool operator==(const const_iterator &o) const noexcept { return i == o.i; } - inline bool operator!=(const const_iterator &o) const noexcept { return i != o.i; } - inline bool operator<(const const_iterator& other) const noexcept { return i < other.i; } - inline bool operator<=(const const_iterator& other) const noexcept { return i <= other.i; } - inline bool operator>(const const_iterator& other) const noexcept { return i > other.i; } - inline bool operator>=(const const_iterator& other) const noexcept { return i >= other.i; } - inline const_iterator &operator++() { ++i; return *this; } - inline const_iterator operator++(int) { Node *n = i; ++i; return n; } - inline const_iterator &operator--() { i--; return *this; } - inline const_iterator operator--(int) { Node *n = i; i--; return n; } - inline const_iterator &operator+=(difference_type j) { i+=j; return *this; } - inline const_iterator &operator-=(difference_type j) { i-=j; return *this; } - inline const_iterator operator+(difference_type j) const { return const_iterator(i+j); } - inline const_iterator operator-(difference_type j) const { return const_iterator(i-j); } - friend inline const_iterator operator+(difference_type j, const_iterator k) { return k + j; } - inline int operator-(const_iterator j) const { return int(i - j.i); } - }; - friend class const_iterator; - - // stl style - typedef std::reverse_iterator reverse_iterator; - typedef std::reverse_iterator const_reverse_iterator; - inline iterator begin() { detach(); return reinterpret_cast(p.begin()); } - inline const_iterator begin() const noexcept { return reinterpret_cast(p.begin()); } - inline const_iterator cbegin() const noexcept { return reinterpret_cast(p.begin()); } - inline const_iterator constBegin() const noexcept { return reinterpret_cast(p.begin()); } - inline iterator end() { detach(); return reinterpret_cast(p.end()); } - inline const_iterator end() const noexcept { return reinterpret_cast(p.end()); } - inline const_iterator cend() const noexcept { return reinterpret_cast(p.end()); } - inline const_iterator constEnd() const noexcept { return reinterpret_cast(p.end()); } - reverse_iterator rbegin() { return reverse_iterator(end()); } - reverse_iterator rend() { return reverse_iterator(begin()); } - const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } - const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } - const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } - const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } - iterator insert(iterator before, const T &t); - iterator erase(iterator pos); - iterator erase(iterator first, iterator last); - - // more Qt - typedef iterator Iterator; - typedef const_iterator ConstIterator; - inline int count() const { return p.size(); } - inline int length() const { return p.size(); } // Same as count() - inline T& first() { Q_ASSERT(!isEmpty()); return *begin(); } - inline const T& constFirst() const { return first(); } - inline const T& first() const { Q_ASSERT(!isEmpty()); return at(0); } - T& last() { Q_ASSERT(!isEmpty()); return *(--end()); } - const T& last() const { Q_ASSERT(!isEmpty()); return at(count() - 1); } - inline const T& constLast() const { return last(); } - inline void removeFirst() { Q_ASSERT(!isEmpty()); erase(begin()); } - inline void removeLast() { Q_ASSERT(!isEmpty()); erase(--end()); } - inline bool startsWith(const T &t) const { return !isEmpty() && first() == t; } - inline bool endsWith(const T &t) const { return !isEmpty() && last() == t; } - QList mid(int pos, int length = -1) const; - - T value(int i) const; - T value(int i, const T &defaultValue) const; - - // stl compatibility - inline void push_back(const T &t) { append(t); } - inline void push_front(const T &t) { prepend(t); } - inline T& front() { return first(); } - inline const T& front() const { return first(); } - inline T& back() { return last(); } - inline const T& back() const { return last(); } - inline void pop_front() { removeFirst(); } - inline void pop_back() { removeLast(); } - inline bool empty() const { return isEmpty(); } - typedef int size_type; - typedef T value_type; - typedef value_type *pointer; - typedef const value_type *const_pointer; - typedef value_type &reference; - typedef const value_type &const_reference; - // ### Qt6: use int - typedef qptrdiff difference_type; - - // comfort - QList &operator+=(const QList &l); - inline QList operator+(const QList &l) const - { QList n = *this; n += l; return n; } - inline QList &operator+=(const T &t) - { append(t); return *this; } - inline QList &operator<< (const T &t) - { append(t); return *this; } - inline QList &operator<<(const QList &l) - { *this += l; return *this; } - - static QList fromVector(const QVector &vector); - QVector toVector() const; - -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) - Q_DECL_DEPRECATED_X("Use QList(set.begin(), set.end()) instead.") - static QList fromSet(const QSet &set); - Q_DECL_DEPRECATED_X("Use QSet(list.begin(), list.end()) instead.") - QSet toSet() const; - - Q_DECL_DEPRECATED_X("Use QList(list.begin(), list.end()) instead.") - static inline QList fromStdList(const std::list &list) - { return QList(list.begin(), list.end()); } - Q_DECL_DEPRECATED_X("Use std::list(list.begin(), list.end()) instead.") - inline std::list toStdList() const - { return std::list(begin(), end()); } -#endif - -private: - Node *detach_helper_grow(int i, int n); - void detach_helper(int alloc); - void detach_helper(); - void dealloc(QListData::Data *d); - - void node_construct(Node *n, const T &t); - void node_destruct(Node *n); - void node_copy(Node *from, Node *to, Node *src); - void node_destruct(Node *from, Node *to); - - bool isValidIterator(const iterator &i) const noexcept - { - const std::less less = {}; - return !less(i.i, cbegin().i) && !less(cend().i, i.i); - } - -private: - inline bool op_eq_impl(const QList &other, QListData::NotArrayCompatibleLayout) const; - inline bool op_eq_impl(const QList &other, QListData::ArrayCompatibleLayout) const; - inline bool contains_impl(const T &, QListData::NotArrayCompatibleLayout) const; - inline bool contains_impl(const T &, QListData::ArrayCompatibleLayout) const; - inline int count_impl(const T &, QListData::NotArrayCompatibleLayout) const; - inline int count_impl(const T &, QListData::ArrayCompatibleLayout) const; -}; - -#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606 -template ::value_type, - QtPrivate::IfIsInputIterator = true> -QList(InputIterator, InputIterator) -> QList; -#endif - -#if defined(Q_CC_BOR) -template -Q_INLINE_TEMPLATE T &QList::Node::t() -{ return QTypeInfo::isLarge || QTypeInfo::isStatic ? *(T*)v:*(T*)this; } -#endif - -template -Q_INLINE_TEMPLATE void QList::node_construct(Node *n, const T &t) -{ - if (QTypeInfo::isLarge || QTypeInfo::isStatic) n->v = new T(t); - else if (QTypeInfo::isComplex) new (n) T(t); -#if (defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__IBMCPP__)) && !defined(__OPTIMIZE__) - // This violates pointer aliasing rules, but it is known to be safe (and silent) - // in unoptimized GCC builds (-fno-strict-aliasing). The other compilers which - // set the same define are assumed to be safe. - else *reinterpret_cast(n) = t; -#else - // This is always safe, but penaltizes unoptimized builds a lot. - else ::memcpy(n, static_cast(&t), sizeof(T)); -#endif -} - -template -Q_INLINE_TEMPLATE void QList::node_destruct(Node *n) -{ - if (QTypeInfo::isLarge || QTypeInfo::isStatic) delete reinterpret_cast(n->v); - else if (QTypeInfo::isComplex) reinterpret_cast(n)->~T(); -} - -template -Q_INLINE_TEMPLATE void QList::node_copy(Node *from, Node *to, Node *src) -{ - Node *current = from; - if (QTypeInfo::isLarge || QTypeInfo::isStatic) { - QT_TRY { - while(current != to) { - current->v = new T(*reinterpret_cast(src->v)); - ++current; - ++src; - } - } QT_CATCH(...) { - while (current-- != from) - delete reinterpret_cast(current->v); - QT_RETHROW; - } - - } else if (QTypeInfo::isComplex) { - QT_TRY { - while(current != to) { - new (current) T(*reinterpret_cast(src)); - ++current; - ++src; - } - } QT_CATCH(...) { - while (current-- != from) - (reinterpret_cast(current))->~T(); - QT_RETHROW; - } - } else { - if (src != from && to - from > 0) - memcpy(from, src, (to - from) * sizeof(Node)); - } -} - -template -Q_INLINE_TEMPLATE void QList::node_destruct(Node *from, Node *to) -{ - if (QTypeInfo::isLarge || QTypeInfo::isStatic) - while(from != to) --to, delete reinterpret_cast(to->v); - else if (QTypeInfo::isComplex) - while (from != to) --to, reinterpret_cast(to)->~T(); -} - -template -Q_INLINE_TEMPLATE QList &QList::operator=(const QList &l) -{ - if (d != l.d) { - QList tmp(l); - tmp.swap(*this); - } - return *this; -} -template -inline typename QList::iterator QList::insert(iterator before, const T &t) -{ - Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid"); - - int iBefore = int(before.i - reinterpret_cast(p.begin())); - Node *n = nullptr; - if (d->ref.isShared()) - n = detach_helper_grow(iBefore, 1); - else - n = reinterpret_cast(p.insert(iBefore)); - QT_TRY { - node_construct(n, t); - } QT_CATCH(...) { - p.remove(iBefore); - QT_RETHROW; - } - return n; -} -template -inline typename QList::iterator QList::erase(iterator it) -{ - Q_ASSERT_X(isValidIterator(it), "QList::erase", "The specified iterator argument 'it' is invalid"); - if (d->ref.isShared()) { - int offset = int(it.i - reinterpret_cast(p.begin())); - it = begin(); // implies detach() - it += offset; - } - node_destruct(it.i); - return reinterpret_cast(p.erase(reinterpret_cast(it.i))); -} -template -inline const T &QList::at(int i) const -{ Q_ASSERT_X(i >= 0 && i < p.size(), "QList::at", "index out of range"); - return reinterpret_cast(p.at(i))->t(); } -template -inline const T &QList::operator[](int i) const -{ Q_ASSERT_X(i >= 0 && i < p.size(), "QList::operator[]", "index out of range"); - return reinterpret_cast(p.at(i))->t(); } -template -inline T &QList::operator[](int i) -{ Q_ASSERT_X(i >= 0 && i < p.size(), "QList::operator[]", "index out of range"); - detach(); return reinterpret_cast(p.at(i))->t(); } -template -inline void QList::removeAt(int i) -{ -#if !QT_DEPRECATED_SINCE(5, 15) - Q_ASSERT_X(i >= 0 && i < p.size(), "QList::removeAt", "index out of range"); -#elif !defined(QT_NO_DEBUG) - if (i < 0 || i >= p.size()) - qWarning("QList::removeAt(): Index out of range."); -#endif - detach(); - node_destruct(reinterpret_cast(p.at(i))); p.remove(i); -} -template -inline T QList::takeAt(int i) -{ Q_ASSERT_X(i >= 0 && i < p.size(), "QList::take", "index out of range"); - detach(); Node *n = reinterpret_cast(p.at(i)); T t = std::move(n->t()); node_destruct(n); - p.remove(i); return t; } -template -inline T QList::takeFirst() -{ T t = std::move(first()); removeFirst(); return t; } -template -inline T QList::takeLast() -{ T t = std::move(last()); removeLast(); return t; } - -template -Q_OUTOFLINE_TEMPLATE void QList::reserve(int alloc) -{ - if (d->alloc < alloc) { - if (d->ref.isShared()) - detach_helper(alloc); - else - p.realloc(alloc); - } -} - -template -Q_OUTOFLINE_TEMPLATE void QList::append(const T &t) -{ - if (d->ref.isShared()) { - Node *n = detach_helper_grow(INT_MAX, 1); - QT_TRY { - node_construct(n, t); - } QT_CATCH(...) { - --d->end; - QT_RETHROW; - } - } else { - if (QTypeInfo::isLarge || QTypeInfo::isStatic) { - Node *n = reinterpret_cast(p.append()); - QT_TRY { - node_construct(n, t); - } QT_CATCH(...) { - --d->end; - QT_RETHROW; - } - } else { - Node *n, copy; - node_construct(©, t); // t might be a reference to an object in the array - QT_TRY { - n = reinterpret_cast(p.append());; - } QT_CATCH(...) { - node_destruct(©); - QT_RETHROW; - } - *n = copy; - } - } -} - -template -inline void QList::prepend(const T &t) -{ - if (d->ref.isShared()) { - Node *n = detach_helper_grow(0, 1); - QT_TRY { - node_construct(n, t); - } QT_CATCH(...) { - ++d->begin; - QT_RETHROW; - } - } else { - if (QTypeInfo::isLarge || QTypeInfo::isStatic) { - Node *n = reinterpret_cast(p.prepend()); - QT_TRY { - node_construct(n, t); - } QT_CATCH(...) { - ++d->begin; - QT_RETHROW; - } - } else { - Node *n, copy; - node_construct(©, t); // t might be a reference to an object in the array - QT_TRY { - n = reinterpret_cast(p.prepend());; - } QT_CATCH(...) { - node_destruct(©); - QT_RETHROW; - } - *n = copy; - } - } -} - -template -inline void QList::insert(int i, const T &t) -{ -#if !QT_DEPRECATED_SINCE(5, 15) - Q_ASSERT_X(i >= 0 && i <= p.size(), "QList::insert", "index out of range"); -#elif !defined(QT_NO_DEBUG) - if (i < 0 || i > p.size()) - qWarning("QList::insert(): Index out of range."); -#endif - if (d->ref.isShared()) { - Node *n = detach_helper_grow(i, 1); - QT_TRY { - node_construct(n, t); - } QT_CATCH(...) { - p.remove(i); - QT_RETHROW; - } - } else { - if (QTypeInfo::isLarge || QTypeInfo::isStatic) { - Node *n = reinterpret_cast(p.insert(i)); - QT_TRY { - node_construct(n, t); - } QT_CATCH(...) { - p.remove(i); - QT_RETHROW; - } - } else { - Node *n, copy; - node_construct(©, t); // t might be a reference to an object in the array - QT_TRY { - n = reinterpret_cast(p.insert(i));; - } QT_CATCH(...) { - node_destruct(©); - QT_RETHROW; - } - *n = copy; - } - } -} - -template -inline void QList::replace(int i, const T &t) -{ - Q_ASSERT_X(i >= 0 && i < p.size(), "QList::replace", "index out of range"); - detach(); - reinterpret_cast(p.at(i))->t() = t; -} - -template -inline void QList::swapItemsAt(int i, int j) -{ - Q_ASSERT_X(i >= 0 && i < p.size() && j >= 0 && j < p.size(), - "QList::swap", "index out of range"); - detach(); - qSwap(d->array[d->begin + i], d->array[d->begin + j]); -} - -template -inline void QList::move(int from, int to) -{ - Q_ASSERT_X(from >= 0 && from < p.size() && to >= 0 && to < p.size(), - "QList::move", "index out of range"); - detach(); - p.move(from, to); -} - -template -Q_OUTOFLINE_TEMPLATE QList QList::mid(int pos, int alength) const -{ - using namespace QtPrivate; - switch (QContainerImplHelper::mid(size(), &pos, &alength)) { - case QContainerImplHelper::Null: - case QContainerImplHelper::Empty: - return QList(); - case QContainerImplHelper::Full: - return *this; - case QContainerImplHelper::Subset: - break; - } - - QList cpy; - if (alength <= 0) - return cpy; - cpy.reserve(alength); - cpy.d->end = alength; - QT_TRY { - cpy.node_copy(reinterpret_cast(cpy.p.begin()), - reinterpret_cast(cpy.p.end()), - reinterpret_cast(p.begin() + pos)); - } QT_CATCH(...) { - // restore the old end - cpy.d->end = 0; - QT_RETHROW; - } - return cpy; -} +#include +#if !defined(QT_NO_JAVA_STYLE_ITERATORS) template -Q_OUTOFLINE_TEMPLATE T QList::value(int i) const -{ - if (i < 0 || i >= p.size()) { - return T(); - } - return reinterpret_cast(p.at(i))->t(); -} - +using QMutableListIterator = QMutableVectorIterator; template -Q_OUTOFLINE_TEMPLATE T QList::value(int i, const T& defaultValue) const -{ - return ((i < 0 || i >= p.size()) ? defaultValue : reinterpret_cast(p.at(i))->t()); -} - -template -Q_OUTOFLINE_TEMPLATE typename QList::Node *QList::detach_helper_grow(int i, int c) -{ - Node *n = reinterpret_cast(p.begin()); - QListData::Data *x = p.detach_grow(&i, c); - QT_TRY { - node_copy(reinterpret_cast(p.begin()), - reinterpret_cast(p.begin() + i), n); - } QT_CATCH(...) { - p.dispose(); - d = x; - QT_RETHROW; - } - QT_TRY { - node_copy(reinterpret_cast(p.begin() + i + c), - reinterpret_cast(p.end()), n + i); - } QT_CATCH(...) { - node_destruct(reinterpret_cast(p.begin()), - reinterpret_cast(p.begin() + i)); - p.dispose(); - d = x; - QT_RETHROW; - } - - if (!x->ref.deref()) - dealloc(x); - - return reinterpret_cast(p.begin() + i); -} - -template -Q_OUTOFLINE_TEMPLATE void QList::detach_helper(int alloc) -{ - Node *n = reinterpret_cast(p.begin()); - QListData::Data *x = p.detach(alloc); - QT_TRY { - node_copy(reinterpret_cast(p.begin()), reinterpret_cast(p.end()), n); - } QT_CATCH(...) { - p.dispose(); - d = x; - QT_RETHROW; - } - - if (!x->ref.deref()) - dealloc(x); -} - -template -Q_OUTOFLINE_TEMPLATE void QList::detach_helper() -{ - detach_helper(d->alloc); -} - -template -Q_OUTOFLINE_TEMPLATE QList::QList(const QList &l) - : d(l.d) -{ - if (!d->ref.ref()) { - p.detach(d->alloc); - - QT_TRY { - node_copy(reinterpret_cast(p.begin()), - reinterpret_cast(p.end()), - reinterpret_cast(l.p.begin())); - } QT_CATCH(...) { - QListData::dispose(d); - QT_RETHROW; - } - } -} - -template -Q_OUTOFLINE_TEMPLATE QList::~QList() -{ - if (!d->ref.deref()) - dealloc(d); -} - -template -template > -QList::QList(InputIterator first, InputIterator last) - : QList() -{ - QtPrivate::reserveIfForwardIterator(this, first, last); - std::copy(first, last, std::back_inserter(*this)); -} - -template -Q_OUTOFLINE_TEMPLATE bool QList::operator==(const QList &l) const -{ - if (d == l.d) - return true; - if (p.size() != l.p.size()) - return false; - return this->op_eq_impl(l, MemoryLayout()); -} - -template -inline bool QList::op_eq_impl(const QList &l, QListData::NotArrayCompatibleLayout) const -{ - Node *i = reinterpret_cast(p.begin()); - Node *e = reinterpret_cast(p.end()); - Node *li = reinterpret_cast(l.p.begin()); - for (; i != e; ++i, ++li) { - if (!(i->t() == li->t())) - return false; - } - return true; -} - -template -inline bool QList::op_eq_impl(const QList &l, QListData::ArrayCompatibleLayout) const -{ - const T *lb = reinterpret_cast(l.p.begin()); - const T *b = reinterpret_cast(p.begin()); - const T *e = reinterpret_cast(p.end()); - return std::equal(b, e, QT_MAKE_CHECKED_ARRAY_ITERATOR(lb, l.p.size())); -} - -template -Q_OUTOFLINE_TEMPLATE void QList::dealloc(QListData::Data *data) -{ - node_destruct(reinterpret_cast(data->array + data->begin), - reinterpret_cast(data->array + data->end)); - QListData::dispose(data); -} - - -template -Q_OUTOFLINE_TEMPLATE void QList::clear() -{ - *this = QList(); -} - -template -Q_OUTOFLINE_TEMPLATE int QList::removeAll(const T &_t) -{ - int index = indexOf(_t); - if (index == -1) - return 0; - - const T t = _t; - detach(); - - Node *i = reinterpret_cast(p.at(index)); - Node *e = reinterpret_cast(p.end()); - Node *n = i; - node_destruct(i); - while (++i != e) { - if (i->t() == t) - node_destruct(i); - else - *n++ = *i; - } - - int removedCount = int(e - n); - d->end -= removedCount; - return removedCount; -} - -template -Q_OUTOFLINE_TEMPLATE bool QList::removeOne(const T &_t) -{ - int index = indexOf(_t); - if (index != -1) { - removeAt(index); - return true; - } - return false; -} - -template -Q_OUTOFLINE_TEMPLATE typename QList::iterator QList::erase(typename QList::iterator afirst, - typename QList::iterator alast) -{ - Q_ASSERT_X(isValidIterator(afirst), "QList::erase", "The specified iterator argument 'afirst' is invalid"); - Q_ASSERT_X(isValidIterator(alast), "QList::erase", "The specified iterator argument 'alast' is invalid"); - - if (d->ref.isShared()) { - // ### A block is erased and a detach is needed. We should shrink and only copy relevant items. - int offsetfirst = int(afirst.i - reinterpret_cast(p.begin())); - int offsetlast = int(alast.i - reinterpret_cast(p.begin())); - afirst = begin(); // implies detach() - alast = afirst; - afirst += offsetfirst; - alast += offsetlast; - } - - for (Node *n = afirst.i; n < alast.i; ++n) - node_destruct(n); - int idx = afirst - begin(); - p.remove(idx, alast - afirst); - return begin() + idx; -} - -template -Q_OUTOFLINE_TEMPLATE QList &QList::operator+=(const QList &l) -{ - if (!l.isEmpty()) { - if (d == &QListData::shared_null) { - *this = l; - } else { - Node *n = (d->ref.isShared()) - ? detach_helper_grow(INT_MAX, l.size()) - : reinterpret_cast(p.append(l.p)); - QT_TRY { - node_copy(n, reinterpret_cast(p.end()), - reinterpret_cast(l.p.begin())); - } QT_CATCH(...) { - // restore the old end - d->end -= int(reinterpret_cast(p.end()) - n); - QT_RETHROW; - } - } - } - return *this; -} - -template -inline void QList::append(const QList &t) -{ - *this += t; -} - -template -Q_OUTOFLINE_TEMPLATE int QList::indexOf(const T &t, int from) const -{ - return QtPrivate::indexOf(*this, t, from); -} - -namespace QtPrivate -{ -template -int indexOf(const QList &list, const U &u, int from) -{ - typedef typename QList::Node Node; - - if (from < 0) - from = qMax(from + list.p.size(), 0); - if (from < list.p.size()) { - Node *n = reinterpret_cast(list.p.at(from -1)); - Node *e = reinterpret_cast(list.p.end()); - while (++n != e) - if (n->t() == u) - return int(n - reinterpret_cast(list.p.begin())); - } - return -1; -} -} - -template -Q_OUTOFLINE_TEMPLATE int QList::lastIndexOf(const T &t, int from) const -{ - return QtPrivate::lastIndexOf(*this, t, from); -} - -namespace QtPrivate -{ -template -int lastIndexOf(const QList &list, const U &u, int from) -{ - typedef typename QList::Node Node; - - if (from < 0) - from += list.p.size(); - else if (from >= list.p.size()) - from = list.p.size()-1; - if (from >= 0) { - Node *b = reinterpret_cast(list.p.begin()); - Node *n = reinterpret_cast(list.p.at(from + 1)); - while (n-- != b) { - if (n->t() == u) - return int(n - b); - } - } - return -1; -} -} - -template -Q_OUTOFLINE_TEMPLATE bool QList::contains(const T &t) const -{ - return contains_impl(t, MemoryLayout()); -} - -template -inline bool QList::contains_impl(const T &t, QListData::NotArrayCompatibleLayout) const -{ - Node *e = reinterpret_cast(p.end()); - Node *i = reinterpret_cast(p.begin()); - for (; i != e; ++i) - if (i->t() == t) - return true; - return false; -} - -template -inline bool QList::contains_impl(const T &t, QListData::ArrayCompatibleLayout) const -{ - const T *b = reinterpret_cast(p.begin()); - const T *e = reinterpret_cast(p.end()); - return std::find(b, e, t) != e; -} - -template -Q_OUTOFLINE_TEMPLATE int QList::count(const T &t) const -{ - return this->count_impl(t, MemoryLayout()); -} - -template -inline int QList::count_impl(const T &t, QListData::NotArrayCompatibleLayout) const -{ - int c = 0; - Node *e = reinterpret_cast(p.end()); - Node *i = reinterpret_cast(p.begin()); - for (; i != e; ++i) - if (i->t() == t) - ++c; - return c; -} - -template -inline int QList::count_impl(const T &t, QListData::ArrayCompatibleLayout) const -{ - return int(std::count(reinterpret_cast(p.begin()), - reinterpret_cast(p.end()), - t)); -} - -template -Q_OUTOFLINE_TEMPLATE QVector QList::toVector() const -{ - return QVector(begin(), end()); -} - -template -QList QList::fromVector(const QVector &vector) -{ - return vector.toList(); -} - -template -Q_OUTOFLINE_TEMPLATE QList QVector::toList() const -{ - return QList(begin(), end()); -} - -template -QVector QVector::fromList(const QList &list) -{ - return list.toVector(); -} - -Q_DECLARE_SEQUENTIAL_ITERATOR(List) -Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List) - -template -uint qHash(const QList &key, uint seed = 0) - noexcept(noexcept(qHashRange(key.cbegin(), key.cend(), seed))) -{ - return qHashRange(key.cbegin(), key.cend(), seed); -} - -template -bool operator<(const QList &lhs, const QList &rhs) - noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end()))) -{ - return std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end()); -} - -template -inline bool operator>(const QList &lhs, const QList &rhs) - noexcept(noexcept(lhs < rhs)) -{ - return rhs < lhs; -} - -template -inline bool operator<=(const QList &lhs, const QList &rhs) - noexcept(noexcept(lhs < rhs)) -{ - return !(lhs > rhs); -} - -template -inline bool operator>=(const QList &lhs, const QList &rhs) - noexcept(noexcept(lhs < rhs)) -{ - return !(lhs < rhs); -} - -QT_END_NAMESPACE +using QListIterator = QVectorIterator; +#endif #include #include -#ifdef Q_CC_MSVC -#pragma warning( pop ) -#endif - #endif // QLIST_H diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 45f7c5b76b..366eb15813 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -317,9 +317,6 @@ public: inline QVector &operator<<(T &&t) { append(std::move(t)); return *this; } - static QVector fromList(const QList &list); - QList toList() const; - #if QT_VERSION < QT_VERSION_CHECK(6,0,0) Q_DECL_DEPRECATED_X("Use QVector(vector.begin(), vector.end()) instead.") static inline QVector fromStdVector(const std::vector &vector) @@ -328,6 +325,14 @@ public: inline std::vector toStdVector() const { return std::vector(d->begin(), d->end()); } #endif + + // Consider deprecating in 6.4 or later + static QVector fromList(const QVector &list) { return list; } + QVector toList() const { return *this; } + + static inline QVector fromVector(const QVector &vector) { return vector; } + inline QVector toVector() const { return *this; } + private: // ### Qt6: remove methods, they are unused void reallocData(const int size, const int alloc, QArrayData::AllocationOptions options = QArrayData::Default); diff --git a/src/dbus/qdbusmisc.cpp b/src/dbus/qdbusmisc.cpp index eb8f61c783..ce1546db92 100644 --- a/src/dbus/qdbusmisc.cpp +++ b/src/dbus/qdbusmisc.cpp @@ -153,7 +153,7 @@ int qDBusParametersForMethod(const QList ¶meterTypes, QVector::ConstIterator it = parameterTypes.constBegin(); QList::ConstIterator end = parameterTypes.constEnd(); for ( ; it != end; ++it) { - const QByteArray &type = *it; + QByteArray type = *it; if (type.endsWith('*')) { errorMsg = QLatin1String("Pointers are not supported: ") + QLatin1String(type); return -1; @@ -180,6 +180,9 @@ int qDBusParametersForMethod(const QList ¶meterTypes, QVector\n" "class QByteArray;\n" - "template class QList;\n" - "template class QMap;\n" "class QString;\n" "class QStringList;\n" "class QVariant;\n" diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index e7dcfac403..c45d41dab5 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -112,7 +112,7 @@ void QListModel::insert(int row, QListWidgetItem *item) QList::iterator it; it = sortedInsertionIterator(items.begin(), items.end(), item->view->sortOrder(), item); - row = qMax(it - items.begin(), 0); + row = qMax(it - items.begin(), 0); } else { if (row < 0) row = 0; @@ -391,7 +391,7 @@ void QListModel::ensureSorted(int column, Qt::SortOrder order, int start, int en --tmpitepos; lit = tmp.begin() + tmpitepos; lit = sortedInsertionIterator(lit, tmp.end(), order, item); - int newRow = qMax(lit - tmp.begin(), 0); + int newRow = qMax(lit - tmp.begin(), 0); lit = tmp.insert(lit, item); if (newRow != oldRow) { changed = true; diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index a2d6e7798d..68338228b2 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -646,7 +646,7 @@ void QTreeModel::ensureSorted(int column, Qt::SortOrder order, lit = lst.begin() + tmpitepos; lit = sortedInsertionIterator(lit, lst.end(), order, item); - int newRow = qMax(lit - lst.begin(), 0); + int newRow = qMax(lit - lst.begin(), 0); if ((newRow < oldRow) && !(*item < *lst.at(oldRow - 1)) && !(*lst.at(oldRow - 1) < *item )) newRow = oldRow; diff --git a/sync.profile b/sync.profile index b1c7e0f328..9c7a6e150c 100644 --- a/sync.profile +++ b/sync.profile @@ -53,6 +53,7 @@ "qconfig.h" => "QtConfig", "qplugin.h" => "QtPlugin", "qalgorithms.h" => "QtAlgorithms", + "qlist.h" => "QList", "qcontainerfwd.h" => "QtContainerFwd", "qdebug.h" => "QtDebug", "qevent.h" => "QtEvents", diff --git a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp index 84ebd46886..8c4e1c16f3 100644 --- a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp +++ b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp @@ -714,16 +714,17 @@ void tst_QtConcurrentFilter::filteredReduced() QCOMPARE(sum, 6); } + auto push_back = static_cast::*)(const int &)>(&QVector::push_back); // functor-member { - QList list2 = QtConcurrent::filteredReduced(list, KeepEvenIntegers(), &QList::push_back, QtConcurrent::OrderedReduce); + QList list2 = QtConcurrent::filteredReduced(list, KeepEvenIntegers(), push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } { QList list2 = QtConcurrent::filteredReduced(list.begin(), list.end(), KeepEvenIntegers(), - &QList::push_back, + push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } @@ -731,19 +732,19 @@ void tst_QtConcurrentFilter::filteredReduced() QList list2 = QtConcurrent::filteredReduced(list.constBegin(), list.constEnd(), KeepEvenIntegers(), - &QList::push_back, + push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } { - QList list2 = QtConcurrent::blockingFilteredReduced(list, KeepEvenIntegers(), &QList::push_back, QtConcurrent::OrderedReduce); + QList list2 = QtConcurrent::blockingFilteredReduced(list, KeepEvenIntegers(), push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } { QList list2 = QtConcurrent::blockingFilteredReduced(list.begin(), list.end(), KeepEvenIntegers(), - &QList::push_back, + push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } @@ -751,7 +752,7 @@ void tst_QtConcurrentFilter::filteredReduced() QList list2 = QtConcurrent::blockingFilteredReduced(list.constBegin(), list.constEnd(), KeepEvenIntegers(), - &QList::push_back, + push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } @@ -805,12 +806,15 @@ void tst_QtConcurrentFilter::filteredReduced() } // member-member + + auto push_back_number = static_cast::*)(const Number &)>(&QVector::push_back); + { QList numbers; numbers << 1 << 2 << 3 << 4; QList list2 = QtConcurrent::filteredReduced(numbers, &Number::isEven, - &QList::push_back, QtConcurrent::OrderedReduce); + push_back_number, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } { @@ -819,7 +823,7 @@ void tst_QtConcurrentFilter::filteredReduced() QList list2 = QtConcurrent::filteredReduced(numbers.begin(), numbers.end(), &Number::isEven, - &QList::push_back, + push_back_number, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } @@ -829,7 +833,7 @@ void tst_QtConcurrentFilter::filteredReduced() QList list2 = QtConcurrent::filteredReduced(numbers.constBegin(), numbers.constEnd(), &Number::isEven, - &QList::push_back, + push_back_number, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } @@ -838,7 +842,7 @@ void tst_QtConcurrentFilter::filteredReduced() numbers << 1 << 2 << 3 << 4; QList list2 = QtConcurrent::blockingFilteredReduced(numbers, &Number::isEven, - &QList::push_back, QtConcurrent::OrderedReduce); + push_back_number, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } { @@ -847,7 +851,7 @@ void tst_QtConcurrentFilter::filteredReduced() QList list2 = QtConcurrent::blockingFilteredReduced(numbers.begin(), numbers.end(), &Number::isEven, - &QList::push_back, + push_back_number, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } @@ -857,21 +861,21 @@ void tst_QtConcurrentFilter::filteredReduced() QList list2 = QtConcurrent::blockingFilteredReduced(numbers.constBegin(), numbers.constEnd(), &Number::isEven, - &QList::push_back, + push_back_number, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } // function-member { - QList list2 = QtConcurrent::filteredReduced(list, keepEvenIntegers, &QList::push_back, QtConcurrent::OrderedReduce); + QList list2 = QtConcurrent::filteredReduced(list, keepEvenIntegers, push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } { QList list2 = QtConcurrent::filteredReduced(list.begin(), list.end(), keepEvenIntegers, - &QList::push_back, + push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } @@ -879,19 +883,19 @@ void tst_QtConcurrentFilter::filteredReduced() QList list2 = QtConcurrent::filteredReduced(list.constBegin(), list.constEnd(), keepEvenIntegers, - &QList::push_back, + push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } { - QList list2 = QtConcurrent::blockingFilteredReduced(list, keepEvenIntegers, &QList::push_back, QtConcurrent::OrderedReduce); + QList list2 = QtConcurrent::blockingFilteredReduced(list, keepEvenIntegers, push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } { QList list2 = QtConcurrent::blockingFilteredReduced(list.begin(), list.end(), keepEvenIntegers, - &QList::push_back, + push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } @@ -899,7 +903,7 @@ void tst_QtConcurrentFilter::filteredReduced() QList list2 = QtConcurrent::blockingFilteredReduced(list.constBegin(), list.constEnd(), keepEvenIntegers, - &QList::push_back, + push_back, QtConcurrent::OrderedReduce); QCOMPARE(list2, QList() << 2 << 4); } diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp index 383de0b2ce..d9cbae1ac2 100644 --- a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp +++ b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp @@ -1381,11 +1381,13 @@ void tst_QtConcurrentMap::mappedReduced() QCOMPARE(sum3, 14); } + auto push_back = static_cast::*)(const int &)>(&QVector::push_back); + // functor-member { QList list2 = QtConcurrent::mappedReduced(list, IntSquare(), - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list2, QList() << 1 << 4 << 9); @@ -1393,14 +1395,14 @@ void tst_QtConcurrentMap::mappedReduced() QList list3 = QtConcurrent::mappedReduced(list.constBegin(), list.constEnd(), IntSquare(), - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list3, QList() << 1 << 4 << 9); QList list4 = QtConcurrent::mappedReduced(QList(list), IntSquare(), - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1 << 4 << 9); @@ -1463,20 +1465,20 @@ void tst_QtConcurrentMap::mappedReduced() { QList list2 = QtConcurrent::mappedReduced(numberList, &Number::toInt, - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list2, QList() << 1 << 2 << 3); QList list3 = QtConcurrent::mappedReduced(numberList.constBegin(), numberList.constEnd(), &Number::toInt, - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list3, QList() << 1 << 2 << 3); QList list4 = QtConcurrent::mappedReduced(QList(numberList), &Number::toInt, - &QList::push_back, OrderedReduce); + push_back, OrderedReduce); QCOMPARE(list4, QList() << 1 << 2 << 3); } { @@ -1503,7 +1505,7 @@ void tst_QtConcurrentMap::mappedReduced() { QList list2 = QtConcurrent::mappedReduced(list, intSquare, - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list2, QList() << 1 << 4 << 9); @@ -1511,14 +1513,14 @@ void tst_QtConcurrentMap::mappedReduced() QList list3 = QtConcurrent::mappedReduced(list.constBegin(), list.constEnd(), intSquare, - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list3, QList() << 1 << 4 << 9); QList list4 = QtConcurrent::mappedReduced(QList(list), intSquare, - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1 << 4 << 9); @@ -1759,11 +1761,13 @@ void tst_QtConcurrentMap::blocking_mappedReduced() QCOMPARE(sum3, 14); } + auto push_back = static_cast::*)(const int &)>(&QVector::push_back); + // functor-member { QList list2 = QtConcurrent::blockingMappedReduced(list, IntSquare(), - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list2, QList() << 1 << 4 << 9); @@ -1771,14 +1775,14 @@ void tst_QtConcurrentMap::blocking_mappedReduced() QList list3 = QtConcurrent::blockingMappedReduced(list.constBegin(), list.constEnd(), IntSquare(), - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list3, QList() << 1 << 4 << 9); QList list4 = QtConcurrent::blockingMappedReduced(QList(list), IntSquare(), - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1 << 4 << 9); @@ -1842,20 +1846,20 @@ void tst_QtConcurrentMap::blocking_mappedReduced() { QList list2 = QtConcurrent::blockingMappedReduced(numberList, &Number::toInt, - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list2, QList() << 1 << 2 << 3); QList list3 = QtConcurrent::blockingMappedReduced(numberList.constBegin(), numberList.constEnd(), &Number::toInt, - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list3, QList() << 1 << 2 << 3); QList list4 = QtConcurrent::blockingMappedReduced(QList(numberList), &Number::toInt, - &QList::push_back, OrderedReduce); + push_back, OrderedReduce); QCOMPARE(list4, QList() << 1 << 2 << 3); } { @@ -1882,7 +1886,7 @@ void tst_QtConcurrentMap::blocking_mappedReduced() { QList list2 = QtConcurrent::blockingMappedReduced(list, intSquare, - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list2, QList() << 1 << 4 << 9); @@ -1890,14 +1894,14 @@ void tst_QtConcurrentMap::blocking_mappedReduced() QList list3 = QtConcurrent::blockingMappedReduced(list.constBegin(), list.constEnd(), intSquare, - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list3, QList() << 1 << 4 << 9); QList list4 = QtConcurrent::blockingMappedReduced(QList(list), intSquare, - &QList::push_back, + push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1 << 4 << 9); @@ -2118,7 +2122,6 @@ public: }; Q_DECLARE_METATYPE(QVector); -Q_DECLARE_METATYPE(QList); void tst_QtConcurrentMap::functionOverloads() { diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 60000316cc..c83e7af503 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -1320,13 +1320,13 @@ void tst_QMetaObject::normalizedSignature_data() QTest::newRow("function ptr spaces") << "void foo( void ( * ) ( void ))" << "void foo(void(*)())"; QTest::newRow("function ptr void*") << "void foo(void(*)(void*))" << "void foo(void(*)(void*))"; QTest::newRow("function ptr void* spaces") << "void foo( void ( * ) ( void * ))" << "void foo(void(*)(void*))"; - QTest::newRow("template args") << " void foo( QMap, QList) " - << "void foo(QMap,QList)"; + QTest::newRow("template args") << " void foo( QMap, QVector) " + << "void foo(QMap,QVector)"; QTest::newRow("void template args") << " void foo( Foo, Bar ) " << "void foo(Foo,Bar)"; QTest::newRow("void* template args") << " void foo( Foo, Bar ) " << "void foo(Foo,Bar)"; - QTest::newRow("rettype") << "QList foo()" << "QListfoo()"; + QTest::newRow("rettype") << "QVector foo()" << "QVectorfoo()"; QTest::newRow("rettype void template") << "Foo foo()" << "Foofoo()"; QTest::newRow("const rettype") << "const QString *foo()" << "const QString*foo()"; QTest::newRow("const ref") << "const QString &foo()" << "const QString&foo()"; @@ -1337,15 +1337,16 @@ void tst_QMetaObject::normalizedSignature_data() QTest::newRow("const4") << "void foo(const int)" << "void foo(int)"; QTest::newRow("const5") << "void foo(const int, int const, const int &, int const &)" << "void foo(int,int,int,int)"; - QTest::newRow("const6") << "void foo(QList)" << "void foo(QList)"; - QTest::newRow("const7") << "void foo(QList)" << "void foo(QList)"; - QTest::newRow("const8") << "void foo(QList)" << "void foo(QList)"; + QTest::newRow("const6") << "void foo(QVector)" << "void foo(QVector)"; + QTest::newRow("const7") << "void foo(QVector)" << "void foo(QVector)"; + QTest::newRow("const8") << "void foo(QVector)" << "void foo(QVector)"; QTest::newRow("const9") << "void foo(const Foo)" << "void foo(Foo)"; QTest::newRow("const10") << "void foo(Fooconst)" << "void foo(Foo)"; QTest::newRow("const11") << "void foo(Foo *const)" << "void foo(Foo*const)"; QTest::newRow("const12") << "void foo(Fooconst*const *const)" << "void foo(Foo*const*const)"; QTest::newRow("const13") << "void foo(const Foo&)" << "void foo(Foo)"; QTest::newRow("const14") << "void foo(Fooconst&)" << "void foo(Foo)"; + QTest::newRow("QList") << "void foo(QList)" << "void foo(QVector)"; QTest::newRow("invalid1") << "a( b" << "a(b"; } @@ -1367,13 +1368,13 @@ void tst_QMetaObject::normalizedType_data() QTest::newRow("white") << " int " << "int"; QTest::newRow("const1") << "int const *" << "const int*"; QTest::newRow("const2") << "const int *" << "const int*"; - QTest::newRow("template1") << "QList" << "QList"; - QTest::newRow("template2") << "QList" << "QList"; + QTest::newRow("template1") << "QVector" << "QVector"; + QTest::newRow("template2") << "QVector" << "QVector"; QTest::newRow("template3") << "QMap" << "QMap"; QTest::newRow("template4") << "const QMap &" << "QMap"; - QTest::newRow("template5") << "QList< ::Foo::Bar>" << "QList< ::Foo::Bar>"; - QTest::newRow("template6") << "QList<::Foo::Bar>" << "QList<::Foo::Bar>"; - QTest::newRow("template7") << "QList >" << "QList >"; + QTest::newRow("template5") << "QVector< ::Foo::Bar>" << "QVector< ::Foo::Bar>"; + QTest::newRow("template6") << "QVector<::Foo::Bar>" << "QVector<::Foo::Bar>"; + QTest::newRow("template7") << "QVector >" << "QVector >"; QTest::newRow("template8") << "QMap" << "QMap"; QTest::newRow("template9") << "QPair , QPair > >" << "QPair,QPair > >"; QTest::newRow("value1") << "const QString &" << "QString"; @@ -1387,6 +1388,7 @@ void tst_QMetaObject::normalizedType_data() QTest::newRow("struct2") << "struct foo const*" << "const foo*"; QTest::newRow("enum") << "enum foo" << "foo"; QTest::newRow("void") << "void" << "void"; + QTest::newRow("QList") << "QList" << "QVector"; } void tst_QMetaObject::normalizedType() diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 5b576fe154..91ea83be3d 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -460,7 +460,7 @@ void tst_QObject::connectSlotsByName() sender.setObjectName("Sender"); QTest::ignoreMessage(QtWarningMsg, "QMetaObject::connectSlotsByName: No matching signal for on_child_signal()"); - QTest::ignoreMessage(QtWarningMsg, "QMetaObject::connectSlotsByName: Connecting slot on_Sender_signalManyParams() with the first of the following compatible signals: (\"signalManyParams(int,int,int,QString,bool)\", \"signalManyParams(int,int,int,QString,bool,bool)\")"); + QTest::ignoreMessage(QtWarningMsg, "QMetaObject::connectSlotsByName: Connecting slot on_Sender_signalManyParams() with the first of the following compatible signals: QVector(\"signalManyParams(int,int,int,QString,bool)\", \"signalManyParams(int,int,int,QString,bool,bool)\")"); QMetaObject::connectSlotsByName(&receiver); receiver.called_slots.clear(); diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index a9adda2750..507b2e8d78 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -84,10 +84,6 @@ void foo() #include "qvector.h" #include "qqueue.h" -QT_BEGIN_NAMESPACE -template class QList; -QT_END_NAMESPACE - class tst_Collections : public QObject { Q_OBJECT @@ -551,19 +547,12 @@ void tst_Collections::list() list << "foo" << "bar"; QVERIFY(!list.isEmpty()); - list.insert(-1, "lessthanzero"); - QCOMPARE(list.at(0), QString("lessthanzero")); - list.insert(0, "atzero"); QCOMPARE(list.at(0), QString("atzero")); int listCount = list.count(); list.insert(listCount, "atcount"); QCOMPARE(list.at(listCount), QString("atcount")); - - listCount = list.count(); - list.insert(listCount + 1, "beyondcount"); - QCOMPARE(list.at(listCount), QString("beyondcount")); } { @@ -2336,12 +2325,6 @@ void populate(QLinkedList &container) container << 1 << 2 << 4 << 8; } -template <> -void populate(QVector &container) -{ - container << 1 << 2 << 4 << 8; -} - template <> void populate(QMap &container) { diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp index 4b085d387d..7a1e13e83d 100644 --- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp +++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp @@ -579,9 +579,6 @@ struct ContainerDuplicatedValuesStrategy> : ContainerAccep template struct ContainerDuplicatedValuesStrategy> : ContainerAcceptsDuplicateValues {}; -template -struct ContainerDuplicatedValuesStrategy> : ContainerAcceptsDuplicateValues {}; - template struct ContainerDuplicatedValuesStrategy> : ContainerAcceptsDuplicateValues {}; diff --git a/tests/auto/corelib/tools/qlist/.gitignore b/tests/auto/corelib/tools/qlist/.gitignore deleted file mode 100644 index df208b6e78..0000000000 --- a/tests/auto/corelib/tools/qlist/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tst_qlist diff --git a/tests/auto/corelib/tools/qlist/qlist.pro b/tests/auto/corelib/tools/qlist/qlist.pro deleted file mode 100644 index 118c607880..0000000000 --- a/tests/auto/corelib/tools/qlist/qlist.pro +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG += testcase -TARGET = tst_qlist -QT = core testlib -qtConfig(c++14): CONFIG += c++14 -qtConfig(c++1z): CONFIG += c++1z -SOURCES = $$PWD/tst_qlist.cpp diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp deleted file mode 100644 index cc9a3a16d1..0000000000 --- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp +++ /dev/null @@ -1,2115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include - -template -class is_qlist_array_memory_layout { - struct No { char c; }; - struct Yes { No n[2]; }; - Q_STATIC_ASSERT(sizeof(No) != sizeof(Yes)); - static No check(...); - static Yes check(MemoryLayout); -public: - enum { value = sizeof(check(typename QList::MemoryLayout())) == sizeof(Yes) }; -}; - -struct Movable { - Movable(char input = 'j') - : i(input) - , state(Constructed) - { - ++liveCount; - } - Movable(const Movable &other) - : i(other.i) - , state(Constructed) - { - check(other.state, Constructed); - ++liveCount; - } - - ~Movable() - { - check(state, Constructed); - i = 0; - --liveCount; - state = Destructed; - } - - bool operator ==(const Movable &other) const - { - check(state, Constructed); - check(other.state, Constructed); - return i == other.i; - } - - bool operator<(const Movable &other) const - { - check(state, Constructed); - check(other.state, Constructed); - return i < other.i; - } - - Movable &operator=(const Movable &other) - { - check(state, Constructed); - check(other.state, Constructed); - i = other.i; - return *this; - } - char i; - - static int getLiveCount() { return liveCount; } -private: - static int liveCount; - - enum State { Constructed = 106, Destructed = 110 }; - uchar state; - - static void check(const uchar state1, const uchar state2) - { - QCOMPARE(state1, state2); - } -}; - -Q_STATIC_ASSERT(sizeof(Movable) < sizeof(void*)); - -int Movable::liveCount = 0; - -QT_BEGIN_NAMESPACE -Q_DECLARE_TYPEINFO(Movable, Q_MOVABLE_TYPE); -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(Movable); - -int qHash(const Movable& movable) -{ - return qHash(movable.i); -} - -struct Optimal -{ - Optimal(char input = 'j') - : i(input), - state(Constructed) - { - ++liveCount; - } - Optimal(const Optimal &other) - : i(other.i), - state(Constructed) - { - check(other.state, Constructed); - ++liveCount; - } - - ~Optimal() - { - check(state, Constructed); - i = 0; - --liveCount; - state = Destructed; - } - - bool operator ==(const Optimal &other) const - { - check(state, Constructed); - check(other.state, Constructed); - return i == other.i; - } - - bool operator<(const Optimal &other) const - { - check(state, Constructed); - check(other.state, Constructed); - return i < other.i; - } - - Optimal &operator=(const Optimal &other) - { - check(state, Constructed); - check(other.state, Constructed); - i = other.i; - return *this; - } - char i; - - static int getLiveCount() { return liveCount; } -private: - static int liveCount; - - enum State { Constructed = 106, Destructed = 110 }; - uchar state; - char padding[sizeof(void*) - 2]; - - static void check(const uchar state1, const uchar state2) - { - QCOMPARE(state1, state2); - } -}; - -Q_STATIC_ASSERT(sizeof(Optimal) == sizeof(void*)); - -int Optimal::liveCount = 0; - -QT_BEGIN_NAMESPACE -Q_DECLARE_TYPEINFO(Optimal, Q_MOVABLE_TYPE); -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(Optimal); - -int qHash(const Optimal& key) -{ - return qHash(key.i); -} - -struct Complex -{ - Complex(int val = 0) - : value(val) - , checkSum(this) - { - ++liveCount; - } - - Complex(Complex const &other) - : value(other.value) - , checkSum(this) - { - ++liveCount; - } - - Complex &operator=(Complex const &other) - { - check(); other.check(); - - value = other.value; - return *this; - } - - ~Complex() - { - --liveCount; - check(); - } - - operator int() const { return value; } - - bool operator==(Complex const &other) const - { - check(); other.check(); - return value == other.value; - } - - bool operator<(Complex const &other) const - { - check(); other.check(); - return value < other.value; - } - - void check() const - { - QVERIFY(this == checkSum); - } - - static int getLiveCount() { return liveCount; } -private: - static int liveCount; - - int value; - void *checkSum; -}; - -int Complex::liveCount = 0; - -Q_DECLARE_METATYPE(Complex); - -// Tests depend on the fact that: -Q_STATIC_ASSERT(!QTypeInfo::isStatic); -Q_STATIC_ASSERT(!QTypeInfo::isComplex); -Q_STATIC_ASSERT(!QTypeInfo::isStatic); -Q_STATIC_ASSERT(QTypeInfo::isComplex); -Q_STATIC_ASSERT(!QTypeInfo::isStatic); -Q_STATIC_ASSERT(QTypeInfo::isComplex); -Q_STATIC_ASSERT(QTypeInfo::isStatic); -Q_STATIC_ASSERT(QTypeInfo::isComplex); -// iow: -Q_STATIC_ASSERT(( is_qlist_array_memory_layout ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout ::value)); - -Q_STATIC_ASSERT((!is_qlist_array_memory_layout ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout ::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout ::value)); - -Q_STATIC_ASSERT(( is_qlist_array_memory_layout ::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout ::value)); - -Q_STATIC_ASSERT((!is_qlist_array_memory_layout ::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout ::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout ::value)); - -class tst_QList : public QObject -{ - Q_OBJECT - -private slots: - void lengthOptimal() const; - void lengthMovable() const; - void lengthComplex() const; - void lengthSignature() const; - void appendOptimal() const; - void appendMovable() const; - void appendComplex() const; - void prepend() const; - void midOptimal() const; - void midMovable() const; - void midComplex() const; - void atOptimal() const; - void atMovable() const; - void atComplex() const; - void firstOptimal() const; - void firstMovable() const; - void firstComplex() const; - void lastOptimal() const; - void lastMovable() const; - void lastComplex() const; - void constFirst() const; - void constLast() const; - void cpp17ctad() const; - void beginOptimal() const; - void beginMovable() const; - void beginComplex() const; - void endOptimal() const; - void endMovable() const; - void endComplex() const; - void containsOptimal() const; - void containsMovable() const; - void containsComplex() const; - void countOptimal() const; - void countMovable() const; - void countComplex() const; - void emptyOptimal() const; - void emptyMovable() const; - void emptyComplex() const; - void endsWithOptimal() const; - void endsWithMovable() const; - void endsWithComplex() const; - void lastIndexOfOptimal() const; - void lastIndexOfMovable() const; - void lastIndexOfComplex() const; - void moveOptimal() const; - void moveMovable() const; - void moveComplex() const; - void removeAllOptimal() const; - void removeAllMovable() const; - void removeAllComplex() const; - void removeAtOptimal() const; - void removeAtMovable() const; - void removeAtComplex() const; - void removeOneOptimal() const; - void removeOneMovable() const; - void removeOneComplex() const; - void replaceOptimal() const; - void replaceMovable() const; - void replaceComplex() const; - void reverseIteratorsOptimal() const; - void reverseIteratorsMovable() const; - void reverseIteratorsComplex() const; - void startsWithOptimal() const; - void startsWithMovable() const; - void startsWithComplex() const; - void swapOptimal() const; - void swapMovable() const; - void swapComplex() const; - void takeAtOptimal() const; - void takeAtMovable() const; - void takeAtComplex() const; - void takeFirstOptimal() const; - void takeFirstMovable() const; - void takeFirstComplex() const; - void takeLastOptimal() const; - void takeLastMovable() const; - void takeLastComplex() const; -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) - void toSetOptimal() const; - void toSetMovable() const; - void toSetComplex() const; - void toStdListOptimal() const; - void toStdListMovable() const; - void toStdListComplex() const; -#endif - void toVectorOptimal() const; - void toVectorMovable() const; - void toVectorComplex() const; - void valueOptimal() const; - void valueMovable() const; - void valueComplex() const; - - void testOperatorsOptimal() const; - void testOperatorsMovable() const; - void testOperatorsComplex() const; - void testSTLIteratorsOptimal() const; - void testSTLIteratorsMovable() const; - void testSTLIteratorsComplex() const; - - void initializeList() const; - - void constSharedNullOptimal() const; - void constSharedNullMovable() const; - void constSharedNullComplex() const; - void setSharableInt_data() const; - void setSharableInt() const; - void setSharableComplex_data() const; - void setSharableComplex() const; - void eraseValidIteratorsOnSharedList() const; - void insertWithValidIteratorsOnSharedList() const; - - void qhashOptimal() const { qhash(); } - void qhashMovable() const { qhash(); } - void qhashComplex() const { qhash(); } - void reserve() const; -private: - template void length() const; - template void append() const; - template void mid() const; - template void at() const; - template void first() const; - template void last() const; - template void begin() const; - template void end() const; - template void contains() const; - template void count() const; - template void empty() const; - template void endsWith() const; - template void lastIndexOf() const; - template void move() const; - template void qhash() const; - template void removeAll() const; - template void removeAt() const; - template void removeOne() const; - template void replace() const; - template void reverseIterators() const; - template void startsWith() const; - template void swap() const; - template void takeAt() const; - template void takeFirst() const; - template void takeLast() const; -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) - template void toSet() const; - template void toStdList() const; -#endif - template void toVector() const; - template void value() const; - - template void testOperators() const; - template void testSTLIterators() const; - - template void constSharedNull() const; - - int dummyForGuard; -}; - -template struct SimpleValue -{ - static T at(int index) - { - return values[index % maxSize]; - } - static const uint maxSize = 7; - static const T values[maxSize]; -}; - -template<> -const Optimal SimpleValue::values[] = { 10, 20, 30, 40, 100, 101, 102 }; -template<> -const Movable SimpleValue::values[] = { 10, 20, 30, 40, 100, 101, 102 }; -template<> -const Complex SimpleValue::values[] = { 10, 20, 30, 40, 100, 101, 102 }; - -// Make some macros for the tests to use in order to be slightly more readable... -#define T_FOO SimpleValue::at(0) -#define T_BAR SimpleValue::at(1) -#define T_BAZ SimpleValue::at(2) -#define T_CAT SimpleValue::at(3) -#define T_DOG SimpleValue::at(4) -#define T_BLAH SimpleValue::at(5) -#define T_WEEE SimpleValue::at(6) - -template -void tst_QList::length() const -{ - /* Empty list. */ - { - const QList list; - QCOMPARE(list.length(), 0); - } - - /* One entry. */ - { - QList list; - list.append(T_FOO); - QCOMPARE(list.length(), 1); - } - - /* Two entries. */ - { - QList list; - list.append(T_FOO); - list.append(T_BAR); - QCOMPARE(list.length(), 2); - } - - /* Three entries. */ - { - QList list; - list.append(T_FOO); - list.append(T_BAR); - list.append(T_BAZ); - QCOMPARE(list.length(), 3); - } -} - -void tst_QList::lengthOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - length(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::lengthMovable() const -{ - const int liveCount = Movable::getLiveCount(); - length(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::lengthComplex() const -{ - const int liveCount = Complex::getLiveCount(); - length(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QList::lengthSignature() const -{ - /* Constness. */ - { - const QList list; - /* The function should be const. */ - list.length(); - } -} - -template -void tst_QList::append() const -{ - /* test append(const QList &) function */ - T one(T_FOO); - T two(T_BAR); - T three(T_BAZ); - T four(T_CAT); - QList list1; - QList list2; - QList listTotal; - list1.append(one); - list1.append(two); - list2.append(three); - list2.append(four); - list1.append(list2); - listTotal.append(one); - listTotal.append(two); - listTotal.append(three); - listTotal.append(four); - QCOMPARE(list1, listTotal); -} - -void tst_QList::appendOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - append(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::appendMovable() const -{ - const int liveCount = Movable::getLiveCount(); - append(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::appendComplex() const -{ - const int liveCount = Complex::getLiveCount(); - append(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QList::prepend() const -{ - QList list; - int *t1 = new int(0); - list.prepend(t1); - QVERIFY(list.size() == 1); - QVERIFY(list.at(0) == t1); - int *t2 = new int(0); - list.prepend(t2); - QVERIFY(list.size() == 2); - QVERIFY(list.at(0) == t2); - QVERIFY(list.at(1) == t1); - int *t3 = new int(0); - list.prepend(t3); - QVERIFY(list.size() == 3); - QVERIFY(list.at(0) == t3); - QVERIFY(list.at(1) == t2); - QVERIFY(list.at(2) == t1); - list.removeAll(t2); - delete t2; - QVERIFY(list.size() == 2); - QVERIFY(list.at(0) == t3); - QVERIFY(list.at(1) == t1); - int *t4 = new int(0); - list.prepend(t4); - QVERIFY(list.size() == 3); - QVERIFY(list.at(0) == t4); - QVERIFY(list.at(1) == t3); - QVERIFY(list.at(2) == t1); - qDeleteAll(list); - list.clear(); -} - -template -void tst_QList::mid() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ << T_CAT << T_DOG << T_BLAH << T_WEEE; - - QCOMPARE(list.mid(3, 3), - QList() << T_CAT << T_DOG << T_BLAH); - - QList list1; - QCOMPARE(list1.mid(1, 1).length(), 0); -} - -void tst_QList::midOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - mid(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::midMovable() const -{ - const int liveCount = Movable::getLiveCount(); - mid(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::midComplex() const -{ - const int liveCount = Complex::getLiveCount(); - mid(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::at() const -{ - // test at() and make sure it functions correctly with some simple list manipulation. - QList list; - - // create a list - list << T_FOO << T_BAR << T_BAZ; - QVERIFY(list.size() == 3); - QCOMPARE(list.at(0), T_FOO); - QCOMPARE(list.at(1), T_BAR); - QCOMPARE(list.at(2), T_BAZ); - - // append an item - list << T_CAT; - QVERIFY(list.size() == 4); - QCOMPARE(list.at(0), T_FOO); - QCOMPARE(list.at(1), T_BAR); - QCOMPARE(list.at(2), T_BAZ); - QCOMPARE(list.at(3), T_CAT); - - // remove an item - list.removeAt(1); - QVERIFY(list.size() == 3); - QCOMPARE(list.at(0), T_FOO); - QCOMPARE(list.at(1), T_BAZ); - QCOMPARE(list.at(2), T_CAT); -} - -void tst_QList::atOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - at(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::atMovable() const -{ - const int liveCount = Movable::getLiveCount(); - at(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::atComplex() const -{ - const int liveCount = Complex::getLiveCount(); - at(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::first() const -{ - QList list; - list << T_FOO << T_BAR; - - QCOMPARE(list.first(), T_FOO); - - // remove an item, make sure it still works - list.pop_front(); - QVERIFY(list.size() == 1); - QCOMPARE(list.first(), T_BAR); -} - -void tst_QList::firstOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - first(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::firstMovable() const -{ - const int liveCount = Movable::getLiveCount(); - first(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::firstComplex() const -{ - const int liveCount = Complex::getLiveCount(); - first(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QList::constFirst() const -{ - // Based on tst_QVector::constFirst() - QList list; - list << 69 << 42 << 3; - - // test it starts ok - QCOMPARE(list.constFirst(), 69); - QVERIFY(list.isDetached()); - - QList listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constFirst(), 69); - QCOMPARE(listCopy.constFirst(), 69); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - // test removal changes - list.removeAt(0); - QVERIFY(list.isDetached()); - QVERIFY(!list.isSharedWith(listCopy)); - QCOMPARE(list.constFirst(), 42); - QCOMPARE(listCopy.constFirst(), 69); - - listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constFirst(), 42); - QCOMPARE(listCopy.constFirst(), 42); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - // test prepend changes - list.prepend(23); - QVERIFY(list.isDetached()); - QVERIFY(!list.isSharedWith(listCopy)); - QCOMPARE(list.constFirst(), 23); - QCOMPARE(listCopy.constFirst(), 42); - - listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constFirst(), 23); - QCOMPARE(listCopy.constFirst(), 23); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); -} - -void tst_QList::constLast() const -{ - // Based on tst_QVector::constLast() - QList list; - list << 69 << 42 << 3; - - // test it starts ok - QCOMPARE(list.constLast(), 3); - QVERIFY(list.isDetached()); - - QList listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constLast(), 3); - QCOMPARE(listCopy.constLast(), 3); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - // test removal changes - list.removeLast(); - QVERIFY(list.isDetached()); - QVERIFY(!list.isSharedWith(listCopy)); - QCOMPARE(list.constLast(), 42); - QCOMPARE(listCopy.constLast(), 3); - - listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constLast(), 42); - QCOMPARE(listCopy.constLast(), 42); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - // test prepend changes - list.append(23); - QVERIFY(list.isDetached()); - QVERIFY(!list.isSharedWith(listCopy)); - QCOMPARE(list.constLast(), 23); - QCOMPARE(listCopy.constLast(), 42); - - listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constLast(), 23); - QCOMPARE(listCopy.constLast(), 23); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); -} - -void tst_QList::cpp17ctad() const -{ -#ifdef __cpp_deduction_guides -#define QVERIFY_IS_LIST_OF(obj, Type) \ - QVERIFY2((std::is_same>::value), \ - QMetaType::typeName(qMetaTypeId())) -#define CHECK(Type, One, Two, Three) \ - do { \ - const Type v[] = {One, Two, Three}; \ - QList v1 = {One, Two, Three}; \ - QVERIFY_IS_LIST_OF(v1, Type); \ - QList v2(v1.begin(), v1.end()); \ - QVERIFY_IS_LIST_OF(v2, Type); \ - QList v3(std::begin(v), std::end(v)); \ - QVERIFY_IS_LIST_OF(v3, Type); \ - } while (false) \ - /*end*/ - CHECK(int, 1, 2, 3); - CHECK(double, 1.0, 2.0, 3.0); - CHECK(QString, QStringLiteral("one"), QStringLiteral("two"), QStringLiteral("three")); -#undef QVERIFY_IS_LIST_OF -#undef CHECK -#else - QSKIP("This test requires C++17 Constructor Template Argument Deduction support enabled in the compiler."); -#endif -} - -template -void tst_QList::last() const -{ - QList list; - list << T_FOO << T_BAR; - - QCOMPARE(list.last(), T_BAR); - - // remove an item, make sure it still works - list.pop_back(); - QVERIFY(list.size() == 1); - QCOMPARE(list.last(), T_FOO); -} - -void tst_QList::lastOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - last(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::lastMovable() const -{ - const int liveCount = Movable::getLiveCount(); - last(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::lastComplex() const -{ - const int liveCount = Complex::getLiveCount(); - last(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::begin() const -{ - QList list; - list << T_FOO << T_BAR; - - QCOMPARE(*list.begin(), T_FOO); - - // remove an item, make sure it still works - list.pop_front(); - QVERIFY(list.size() == 1); - QCOMPARE(*list.begin(), T_BAR); -} - -void tst_QList::beginOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - begin(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::beginMovable() const -{ - const int liveCount = Movable::getLiveCount(); - begin(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::beginComplex() const -{ - const int liveCount = Complex::getLiveCount(); - begin(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::end() const -{ - QList list; - list << T_FOO << T_BAR; - - QCOMPARE(*--list.end(), T_BAR); - - // remove an item, make sure it still works - list.pop_back(); - QVERIFY(list.size() == 1); - QCOMPARE(*--list.end(), T_FOO); -} - -void tst_QList::endOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - end(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::endMovable() const -{ - const int liveCount = Movable::getLiveCount(); - end(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::endComplex() const -{ - const int liveCount = Complex::getLiveCount(); - end(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::contains() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - QVERIFY(list.contains(T_FOO)); - QVERIFY(list.contains(T_BLAH) != true); - - // add it and make sure it matches - list.append(T_BLAH); - QVERIFY(list.contains(T_BLAH)); -} - -void tst_QList::containsOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - contains(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::containsMovable() const -{ - const int liveCount = Movable::getLiveCount(); - contains(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::containsComplex() const -{ - const int liveCount = Complex::getLiveCount(); - contains(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::count() const -{ - QList list; - - // starts empty - QVERIFY(list.count() == 0); - - // goes up - list.append(T_FOO); - QVERIFY(list.count() == 1); - - // and up - list.append(T_BAR); - QVERIFY(list.count() == 2); - - // and down - list.pop_back(); - QVERIFY(list.count() == 1); - - // and empty. :) - list.pop_back(); - QVERIFY(list.count() == 0); -} - -void tst_QList::countOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - count(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::countMovable() const -{ - const int liveCount = Movable::getLiveCount(); - count(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::countComplex() const -{ - const int liveCount = Complex::getLiveCount(); - count(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::empty() const -{ - QList list; - - // make sure it starts empty - QVERIFY(list.empty()); - - // and doesn't stay empty - list.append(T_FOO); - QVERIFY(!list.empty()); - - // and goes back to being empty - list.pop_back(); - QVERIFY(list.empty()); -} - -void tst_QList::emptyOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - empty(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::emptyMovable() const -{ - const int liveCount = Movable::getLiveCount(); - empty(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::emptyComplex() const -{ - const int liveCount = Complex::getLiveCount(); - empty(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::endsWith() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // test it returns correctly in both cases - QVERIFY(list.endsWith(T_BAZ)); - QVERIFY(!list.endsWith(T_BAR)); - - // remove an item and make sure the end item changes - list.pop_back(); - QVERIFY(list.endsWith(T_BAR)); -} - -void tst_QList::endsWithOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - endsWith(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::endsWithMovable() const -{ - const int liveCount = Movable::getLiveCount(); - endsWith(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::endsWithComplex() const -{ - const int liveCount = Complex::getLiveCount(); - endsWith(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::lastIndexOf() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // one instance of the target item - QVERIFY(list.lastIndexOf(T_BAZ) == 2); - - // shouldn't find this - QVERIFY(list.lastIndexOf(T_WEEE) == -1); - - // multiple instances - list.append(T_BAZ); - list.append(T_BAZ); - QVERIFY(list.lastIndexOf(T_BAZ) == 4); - - // search from the middle to find the last one - QVERIFY(list.lastIndexOf(T_BAZ, 3) == 3); - - // try to find none - QVERIFY(list.lastIndexOf(T_BAZ, 1) == -1); -} - -void tst_QList::lastIndexOfOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - lastIndexOf(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::lastIndexOfMovable() const -{ - const int liveCount = Movable::getLiveCount(); - lastIndexOf(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::lastIndexOfComplex() const -{ - const int liveCount = Complex::getLiveCount(); - lastIndexOf(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::move() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // move an item - list.move(0, list.count() - 1); - QCOMPARE(list, QList() << T_BAR << T_BAZ << T_FOO); - - // move it back - list.move(list.count() - 1, 0); - QCOMPARE(list, QList() << T_FOO << T_BAR << T_BAZ); - - // move an item in the middle - list.move(1, 0); - QCOMPARE(list, QList() << T_BAR << T_FOO << T_BAZ); -} - -void tst_QList::moveOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - move(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::moveMovable() const -{ - const int liveCount = Movable::getLiveCount(); - move(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::moveComplex() const -{ - const int liveCount = Complex::getLiveCount(); - move(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::removeAll() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // remove one instance - list.removeAll(T_BAR); - QCOMPARE(list, QList() << T_FOO << T_BAZ); - - // many instances - list << T_FOO << T_BAR << T_BAZ << T_FOO << T_BAR << T_BAZ << T_FOO << T_BAR << T_BAZ; - list.removeAll(T_BAR); - QCOMPARE(list, QList() << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ); - - // try remove something that doesn't exist - list.removeAll(T_WEEE); - QCOMPARE(list, QList() << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ); -} - -void tst_QList::removeAllOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - removeAll(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::removeAllMovable() const -{ - const int liveCount = Movable::getLiveCount(); - removeAll(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::removeAllComplex() const -{ - const int liveCount = Complex::getLiveCount(); - removeAll(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::removeAt() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // middle - list.removeAt(1); - QCOMPARE(list, QList() << T_FOO << T_BAZ); - - // start - list.removeAt(0); - QCOMPARE(list, QList() << T_BAZ); - - // final - list.removeAt(0); - QCOMPARE(list, QList()); -} - -void tst_QList::removeAtOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - removeAt(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::removeAtMovable() const -{ - const int liveCount = Movable::getLiveCount(); - removeAt(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::removeAtComplex() const -{ - const int liveCount = Complex::getLiveCount(); - removeAt(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::removeOne() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // middle - list.removeOne(T_BAR); - QCOMPARE(list, QList() << T_FOO << T_BAZ); - - // start - list.removeOne(T_FOO); - QCOMPARE(list, QList() << T_BAZ); - - // last - list.removeOne(T_BAZ); - QCOMPARE(list, QList()); - - // make sure it really only removes one :) - list << T_FOO << T_FOO; - list.removeOne(T_FOO); - QCOMPARE(list, QList() << T_FOO); - - // try remove something that doesn't exist - list.removeOne(T_WEEE); - QCOMPARE(list, QList() << T_FOO); -} - -void tst_QList::removeOneOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - removeOne(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::removeOneMovable() const -{ - const int liveCount = Movable::getLiveCount(); - removeOne(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::removeOneComplex() const -{ - const int liveCount = Complex::getLiveCount(); - removeOne(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::replace() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // start - list.replace(0, T_CAT); - QCOMPARE(list, QList() << T_CAT - << T_BAR << T_BAZ); - - // middle - list.replace(1, T_DOG); - QCOMPARE(list, QList() << T_CAT - << T_DOG << T_BAZ); - - // end - list.replace(2, T_BLAH); - QCOMPARE(list, QList() << T_CAT - << T_DOG << T_BLAH); -} - -void tst_QList::replaceOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - replace(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::replaceMovable() const -{ - const int liveCount = Movable::getLiveCount(); - replace(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::replaceComplex() const -{ - const int liveCount = Complex::getLiveCount(); - replace(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::reverseIterators() const -{ - QList v; - v << T_CAT << T_DOG << T_BLAH << T_BAZ; - QList vr = v; - std::reverse(vr.begin(), vr.end()); - const QList &cvr = vr; - QVERIFY(std::equal(v.begin(), v.end(), vr.rbegin())); - QVERIFY(std::equal(v.begin(), v.end(), vr.crbegin())); - QVERIFY(std::equal(v.begin(), v.end(), cvr.rbegin())); - QVERIFY(std::equal(vr.rbegin(), vr.rend(), v.begin())); - QVERIFY(std::equal(vr.crbegin(), vr.crend(), v.begin())); - QVERIFY(std::equal(cvr.rbegin(), cvr.rend(), v.begin())); -} - -void tst_QList::reverseIteratorsOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - reverseIterators(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::reverseIteratorsMovable() const -{ - const int liveCount = Movable::getLiveCount(); - reverseIterators(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::reverseIteratorsComplex() const -{ - const int liveCount = Complex::getLiveCount(); - reverseIterators(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::startsWith() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // make sure it starts ok - QVERIFY(list.startsWith(T_FOO)); - - // remove an item - list.removeFirst(); - QVERIFY(list.startsWith(T_BAR)); -} - -void tst_QList::startsWithOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - startsWith(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::startsWithMovable() const -{ - const int liveCount = Movable::getLiveCount(); - startsWith(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::startsWithComplex() const -{ - const int liveCount = Complex::getLiveCount(); - startsWith(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::swap() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // swap - list.swapItemsAt(0, 2); - QCOMPARE(list, QList() << T_BAZ << T_BAR << T_FOO); - - // swap again - list.swapItemsAt(1, 2); - QCOMPARE(list, QList() << T_BAZ << T_FOO << T_BAR); - - QList list2; - list2 << T_DOG << T_BLAH; - - list.swap(list2); - QCOMPARE(list, QList() << T_DOG << T_BLAH); - QCOMPARE(list2, QList() << T_BAZ << T_FOO << T_BAR); -} - -void tst_QList::swapOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - swap(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::swapMovable() const -{ - const int liveCount = Movable::getLiveCount(); - swap(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::swapComplex() const -{ - const int liveCount = Complex::getLiveCount(); - swap(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::takeAt() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - QCOMPARE(list.takeAt(0), T_FOO); - QVERIFY(list.size() == 2); - QCOMPARE(list.takeAt(1), T_BAZ); - QVERIFY(list.size() == 1); - QCOMPARE(list.takeAt(0), T_BAR); - QVERIFY(list.size() == 0); -} - -void tst_QList::takeAtOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - takeAt(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::takeAtMovable() const -{ - const int liveCount = Movable::getLiveCount(); - takeAt(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::takeAtComplex() const -{ - const int liveCount = Complex::getLiveCount(); - takeAt(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::takeFirst() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - QCOMPARE(list.takeFirst(), T_FOO); - QVERIFY(list.size() == 2); - QCOMPARE(list.takeFirst(), T_BAR); - QVERIFY(list.size() == 1); - QCOMPARE(list.takeFirst(), T_BAZ); - QVERIFY(list.size() == 0); -} - -void tst_QList::takeFirstOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - takeFirst(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::takeFirstMovable() const -{ - const int liveCount = Movable::getLiveCount(); - takeFirst(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::takeFirstComplex() const -{ - const int liveCount = Complex::getLiveCount(); - takeFirst(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::takeLast() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - QCOMPARE(list.takeLast(), T_BAZ); - QCOMPARE(list.takeLast(), T_BAR); - QCOMPARE(list.takeLast(), T_FOO); -} - -void tst_QList::takeLastOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - takeLast(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::takeLastMovable() const -{ - const int liveCount = Movable::getLiveCount(); - takeLast(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::takeLastComplex() const -{ - const int liveCount = Complex::getLiveCount(); - takeLast(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) -template -void tst_QList::toSet() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // no duplicates - QCOMPARE(list.toSet(), QSet() << T_FOO << T_BAR << T_BAZ); - QCOMPARE(list, QList() << T_FOO << T_BAR << T_BAZ); - - // duplicates (is this more of a QSet test?) - list << T_FOO << T_BAR << T_BAZ; - QCOMPARE(list.toSet(), QSet() << T_FOO << T_BAR << T_BAZ); - QCOMPARE(list, QList() << T_FOO << T_BAR << T_BAZ - << T_FOO << T_BAR << T_BAZ); -} - -void tst_QList::toSetOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - toSet(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::toSetMovable() const -{ - const int liveCount = Movable::getLiveCount(); - toSet(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::toSetComplex() const -{ - const int liveCount = Complex::getLiveCount(); - toSet(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::toStdList() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // yuck. - std::list slist; - slist.push_back(T_FOO); - slist.push_back(T_BAR); - slist.push_back(T_BAZ); - - QCOMPARE(list.toStdList(), slist); - QCOMPARE(list, QList() << T_FOO << T_BAR << T_BAZ); -} - -void tst_QList::toStdListOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - toStdList(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::toStdListMovable() const -{ - const int liveCount = Movable::getLiveCount(); - toStdList(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::toStdListComplex() const -{ - const int liveCount = Complex::getLiveCount(); - toStdList(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} -#endif - -template -void tst_QList::toVector() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - QCOMPARE(list.toVector(), QVector() << T_FOO << T_BAR << T_BAZ); -} - -void tst_QList::toVectorOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - toVector(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::toVectorMovable() const -{ - const int liveCount = Movable::getLiveCount(); - toVector(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::toVectorComplex() const -{ - const int liveCount = Complex::getLiveCount(); - toVector(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::value() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - // test real values - QCOMPARE(list.value(0), T_FOO); - QCOMPARE(list.value(2), T_BAZ); - - // test empty default - QCOMPARE(list.value(3), T()); - QCOMPARE(list.value(-1), T()); - - // test defaults - T defaultT(T_WEEE); - QCOMPARE(list.value(-1, defaultT), defaultT); - QCOMPARE(list.value(3, defaultT), defaultT); -} - -void tst_QList::valueOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - value(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::valueMovable() const -{ - const int liveCount = Movable::getLiveCount(); - value(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::valueComplex() const -{ - const int liveCount = Complex::getLiveCount(); - value(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::testOperators() const -{ - QList list; - list << T_FOO << T_BAR << T_BAZ; - - QList listtwo; - listtwo << T_FOO << T_BAR << T_BAZ; - - // test equal - QVERIFY(list == listtwo); - - // not equal - listtwo.append(T_CAT); - QVERIFY(list != listtwo); - - // += - list += listtwo; - QVERIFY(list.size() == 7); - QVERIFY(listtwo.size() == 4); - QCOMPARE(list, QList() << T_FOO << T_BAR << T_BAZ - << T_FOO << T_BAR << T_BAZ << T_CAT); - - // = - list = listtwo; - QCOMPARE(list, listtwo); - QCOMPARE(list, QList() << T_FOO << T_BAR << T_BAZ << T_CAT); - - // [] - QCOMPARE(list[0], T_FOO); - QCOMPARE(list[list.size() - 1], T_CAT); - - // <, >, <=, >= - QVERIFY(!(list < listtwo)); - QVERIFY(!(list > listtwo)); - QVERIFY( list <= listtwo); - QVERIFY( list >= listtwo); - listtwo.push_back(T_CAT); - QVERIFY( list < listtwo); - QVERIFY(!(list > listtwo)); - QVERIFY( list <= listtwo); - QVERIFY(!(list >= listtwo)); - QVERIFY(listtwo > list); - QVERIFY(listtwo >= list); -} - -void tst_QList::testOperatorsOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - testOperators(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::testOperatorsMovable() const -{ - const int liveCount = Movable::getLiveCount(); - testOperators(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::testOperatorsComplex() const -{ - const int liveCount = Complex::getLiveCount(); - testOperators(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QList::testSTLIterators() const -{ - QList list; - - // create a list - list << T_FOO << T_BAR << T_BAZ; - typename QList::iterator it = list.begin(); - QCOMPARE(*it, T_FOO); it++; - QCOMPARE(*it, T_BAR); it++; - QCOMPARE(*it, T_BAZ); it++; - QCOMPARE(it, list.end()); it--; - - // walk backwards - QCOMPARE(*it, T_BAZ); it--; - QCOMPARE(*it, T_BAR); it--; - QCOMPARE(*it, T_FOO); - - // test erase - it = list.erase(it); - QVERIFY(list.size() == 2); - QCOMPARE(*it, T_BAR); - - // test multiple erase - it = list.erase(it, it + 2); - QVERIFY(list.size() == 0); - QCOMPARE(it, list.end()); - - // insert again - it = list.insert(it, T_FOO); - QVERIFY(list.size() == 1); - QCOMPARE(*it, T_FOO); - - // insert again - it = list.insert(it, T_BAR); - QVERIFY(list.size() == 2); - QCOMPARE(*it++, T_BAR); - QCOMPARE(*it, T_FOO); -} - -void tst_QList::testSTLIteratorsOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - testSTLIterators(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::testSTLIteratorsMovable() const -{ - const int liveCount = Movable::getLiveCount(); - testSTLIterators(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::testSTLIteratorsComplex() const -{ - const int liveCount = Complex::getLiveCount(); - testSTLIterators(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QList::initializeList() const -{ - QList v1{2,3,4}; - QCOMPARE(v1, QList() << 2 << 3 << 4); - QCOMPARE(v1, (QList{2,3,4})); - - QList> v2{ v1, {1}, QList(), {2,3,4} }; - QList> v3; - v3 << v1 << (QList() << 1) << QList() << v1; - QCOMPARE(v3, v2); -} - -template -void tst_QList::constSharedNull() const -{ - QList list2; -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QList list1; - list1.setSharable(false); - QVERIFY(list1.isDetached()); - - list2.setSharable(true); -#endif - QVERIFY(!list2.isDetached()); -} - -void tst_QList::constSharedNullOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - constSharedNull(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::constSharedNullMovable() const -{ - const int liveCount = Movable::getLiveCount(); - constSharedNull(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::constSharedNullComplex() const -{ - const int liveCount = Complex::getLiveCount(); - constSharedNull(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void generateSetSharableData() -{ -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QTest::addColumn >("list"); - QTest::addColumn("size"); - - QTest::newRow("null") << QList() << 0; - QTest::newRow("non-empty") << (QList() << T(0) << T(1) << T(2) << T(3) << T(4)) << 5; -#endif -} - -template -void runSetSharableTest() -{ -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QFETCH(QList, list); - QFETCH(int, size); - - QVERIFY(!list.isDetached()); // Shared with QTest - - list.setSharable(true); - - QCOMPARE(list.size(), size); - - { - QList copy(list); - QVERIFY(!copy.isDetached()); - QVERIFY(copy.isSharedWith(list)); - } - - list.setSharable(false); - QVERIFY(list.isDetached() || list.isSharedWith(QList())); - - { - QList copy(list); - - QVERIFY(copy.isDetached() || copy.isSharedWith(QList())); - QCOMPARE(copy.size(), size); - QCOMPARE(copy, list); - } - - list.setSharable(true); - - { - QList copy(list); - - QVERIFY(!copy.isDetached()); - QVERIFY(copy.isSharedWith(list)); - } - - for (int i = 0; i < list.size(); ++i) - QCOMPARE(int(list[i]), i); - - QCOMPARE(list.size(), size); -#endif -} - -void tst_QList::setSharableInt_data() const -{ - generateSetSharableData(); -} - -void tst_QList::setSharableComplex_data() const -{ - generateSetSharableData(); -} - -void tst_QList::setSharableInt() const -{ - runSetSharableTest(); -} - -void tst_QList::setSharableComplex() const -{ - runSetSharableTest(); -} - -void tst_QList::eraseValidIteratorsOnSharedList() const -{ - QList a, b; - a.push_back(10); - a.push_back(20); - a.push_back(30); - QList::iterator i = a.begin(); - ++i; - b = a; - a.erase(i); - QCOMPARE(b.size(), 3); - QCOMPARE(a.size(), 2); - QCOMPARE(a.at(0), 10); - QCOMPARE(a.at(1), 30); - - a.push_back(40); - a.push_back(50); - a.push_back(60); - QCOMPARE(a.size(), 5); - i = a.begin(); - b = a; - ++i; - QList::iterator j = i; - ++j; - ++j; - a.erase(i, j); // remove 3 elements - QCOMPARE(b.size(), 5); - QCOMPARE(a.size(), 3); - QCOMPARE(a.at(0), 10); - QCOMPARE(a.at(1), 50); -} - -void tst_QList::insertWithValidIteratorsOnSharedList() const -{ - QList a, b; - a.push_back(10); - a.push_back(20); - a.push_back(30); - QList::iterator i = a.begin(); - ++i; - b = a; - a.insert(i, 15); - QCOMPARE(a.size(), b.size() + 1); - QCOMPARE(b.at(1), 20); - QCOMPARE(a.at(1), 15); -} - -template -void tst_QList::qhash() const -{ - QList l1, l2; - QCOMPARE(qHash(l1), qHash(l2)); - l1 << T_BAR; - l2 << T_BAR; - QCOMPARE(qHash(l1), qHash(l2)); -} - -void tst_QList::reserve() const -{ - // Note: - // This test depends on QList's current behavior that ints are stored in the array itself. - // This test would not work for QList. - int capacity = 100; - QList list; - list.reserve(capacity); - list << 0; - int *data = &list[0]; - - for (int i = 1; i < capacity; i++) { - list << i; - QCOMPARE(&list.at(0), data); - } - - QList copy = list; - list.reserve(capacity / 2); - QCOMPARE(list.size(), capacity); // we didn't shrink the size! - - copy = list; - list.reserve(capacity * 2); - QCOMPARE(list.size(), capacity); - QVERIFY(&list.at(0) != data); -} - -QTEST_APPLESS_MAIN(tst_QList) -#include "tst_qlist.moc" diff --git a/tests/auto/corelib/tools/qlist_strictiterators/qlist_strictiterators.pro b/tests/auto/corelib/tools/qlist_strictiterators/qlist_strictiterators.pro deleted file mode 100644 index e39ad38919..0000000000 --- a/tests/auto/corelib/tools/qlist_strictiterators/qlist_strictiterators.pro +++ /dev/null @@ -1,3 +0,0 @@ -include(../qlist/qlist.pro) -TARGET = tst_qlist_strictiterators -DEFINES += QT_STRICT_ITERATORS tst_QList=tst_QList_StrictIterators diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro index 49b2a1f075..96ec9c8443 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -18,8 +18,6 @@ SUBDIRS=\ qhashfunctions \ qline \ qlinkedlist \ - qlist \ - qlist_strictiterators \ qmakearray \ qmap \ qmap_strictiterators \ diff --git a/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp b/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp index 4b926dcd05..ec3e71ac8f 100644 --- a/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp +++ b/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp @@ -402,7 +402,7 @@ void tst_QDBusMetaType::invalidTypes() else if (qstrcmp(QTest::currentDataTag(), "Invalid7") == 0) QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid7' produces invalid D-BUS signature `()' (Did you forget to call beginStructure() ?)"); else if (qstrcmp(QTest::currentDataTag(), "QList") == 0) - QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `QList' produces invalid D-BUS signature `a' (Did you forget to call beginStructure() ?)"); + QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `QVector' produces invalid D-BUS signature `a' (Did you forget to call beginStructure() ?)"); staticTypes(); staticTypes(); // run twice: the error messages should be printed once only diff --git a/tests/auto/network/ssl/qdtls/tst_qdtls.cpp b/tests/auto/network/ssl/qdtls/tst_qdtls.cpp index 4dfdf14e5b..e43546937e 100644 --- a/tests/auto/network/ssl/qdtls/tst_qdtls.cpp +++ b/tests/auto/network/ssl/qdtls/tst_qdtls.cpp @@ -162,7 +162,6 @@ Q_DECLARE_METATYPE(QSslSocket::SslMode) Q_DECLARE_METATYPE(QSslSocket::PeerVerifyMode) Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QSslKey) -Q_DECLARE_METATYPE(QVector) QT_BEGIN_NAMESPACE diff --git a/tests/auto/network/ssl/qocsp/tst_qocsp.cpp b/tests/auto/network/ssl/qocsp/tst_qocsp.cpp index 9716c04bbb..4eeea76205 100644 --- a/tests/auto/network/ssl/qocsp/tst_qocsp.cpp +++ b/tests/auto/network/ssl/qocsp/tst_qocsp.cpp @@ -60,7 +60,6 @@ using VectorOfErrors = QT_PREPEND_NAMESPACE(QVector); using Latin1String = QT_PREPEND_NAMESPACE(QLatin1String); Q_DECLARE_METATYPE(SslError) -Q_DECLARE_METATYPE(VectorOfErrors) Q_DECLARE_METATYPE(Latin1String) QT_BEGIN_NAMESPACE diff --git a/tests/auto/testlib/selftests/expected_signaldumper.lightxml b/tests/auto/testlib/selftests/expected_signaldumper.lightxml index 443f649bb6..8ce57e4b84 100644 --- a/tests/auto/testlib/selftests/expected_signaldumper.lightxml +++ b/tests/auto/testlib/selftests/expected_signaldumper.lightxml @@ -542,7 +542,7 @@ - ())]]> + ())]]> ())]]> diff --git a/tests/auto/testlib/selftests/expected_signaldumper.tap b/tests/auto/testlib/selftests/expected_signaldumper.tap index e2d664f4f1..39419280d4 100644 --- a/tests/auto/testlib/selftests/expected_signaldumper.tap +++ b/tests/auto/testlib/selftests/expected_signaldumper.tap @@ -134,7 +134,7 @@ ok 18 - slotEmittingSignalOldSyntax(queued) # Signal: SignalSlotClass(_POINTER_) qStringRefSignal ((QString&)@_POINTER_) # Signal: SignalSlotClass(_POINTER_) qStringConstRefSignal (QString(Test string)) # Signal: SignalSlotClass(_POINTER_) qByteArraySignal (QByteArray(Test bytearray)) -# Signal: SignalSlotClass(_POINTER_) qListSignal (QList()) +# Signal: SignalSlotClass(_POINTER_) qListSignal (QVector()) # Signal: SignalSlotClass(_POINTER_) qVectorSignal (QVector()) # Signal: SignalSlotClass(_POINTER_) qVectorRefSignal ((QVector&)@_POINTER_) # Signal: SignalSlotClass(_POINTER_) qVectorConstRefSignal (QVector()) diff --git a/tests/auto/testlib/selftests/expected_signaldumper.teamcity b/tests/auto/testlib/selftests/expected_signaldumper.teamcity index 0fc568e086..15bb4ddfe1 100644 --- a/tests/auto/testlib/selftests/expected_signaldumper.teamcity +++ b/tests/auto/testlib/selftests/expected_signaldumper.teamcity @@ -54,7 +54,7 @@ ##teamcity[testStdOut name='slotEmittingSignalOldSyntax(queued)' out='INFO: Signal: SignalSlotClass(_POINTER_) signalWithoutParameters ()|nINFO: Signal: QEventDispatcherPlatform(_POINTER_) awake ()|nINFO: Signal: SignalSlotClass(_POINTER_) nestedSignal ()' flowId='tst_Signaldumper'] ##teamcity[testFinished name='slotEmittingSignalOldSyntax(queued)' flowId='tst_Signaldumper'] ##teamcity[testStarted name='variousTypes()' flowId='tst_Signaldumper'] -##teamcity[testStdOut name='variousTypes()' out='INFO: Signal: SignalSlotClass(_POINTER_) qStringSignal (QString(Test string))|nINFO: Signal: SignalSlotClass(_POINTER_) qStringRefSignal ((QString&)@_POINTER_)|nINFO: Signal: SignalSlotClass(_POINTER_) qStringConstRefSignal (QString(Test string))|nINFO: Signal: SignalSlotClass(_POINTER_) qByteArraySignal (QByteArray(Test bytearray))|nINFO: Signal: SignalSlotClass(_POINTER_) qListSignal (QList())|nINFO: Signal: SignalSlotClass(_POINTER_) qVectorSignal (QVector())|nINFO: Signal: SignalSlotClass(_POINTER_) qVectorRefSignal ((QVector&)@_POINTER_)|nINFO: Signal: SignalSlotClass(_POINTER_) qVectorConstRefSignal (QVector())|nINFO: Signal: SignalSlotClass(_POINTER_) qVectorConstPointerSignal ((const QVector*)_POINTER_)|nINFO: Signal: SignalSlotClass(_POINTER_) qVectorPointerConstSignal ()|nINFO: Signal: SignalSlotClass(_POINTER_) qVariantSignal (QVariant())|nINFO: Signal: SignalSlotClass(_POINTER_) qVariantSignal (QVariant())' flowId='tst_Signaldumper'] +##teamcity[testStdOut name='variousTypes()' out='INFO: Signal: SignalSlotClass(_POINTER_) qStringSignal (QString(Test string))|nINFO: Signal: SignalSlotClass(_POINTER_) qStringRefSignal ((QString&)@_POINTER_)|nINFO: Signal: SignalSlotClass(_POINTER_) qStringConstRefSignal (QString(Test string))|nINFO: Signal: SignalSlotClass(_POINTER_) qByteArraySignal (QByteArray(Test bytearray))|nINFO: Signal: SignalSlotClass(_POINTER_) qListSignal (QVector())|nINFO: Signal: SignalSlotClass(_POINTER_) qVectorSignal (QVector())|nINFO: Signal: SignalSlotClass(_POINTER_) qVectorRefSignal ((QVector&)@_POINTER_)|nINFO: Signal: SignalSlotClass(_POINTER_) qVectorConstRefSignal (QVector())|nINFO: Signal: SignalSlotClass(_POINTER_) qVectorConstPointerSignal ((const QVector*)_POINTER_)|nINFO: Signal: SignalSlotClass(_POINTER_) qVectorPointerConstSignal ()|nINFO: Signal: SignalSlotClass(_POINTER_) qVariantSignal (QVariant())|nINFO: Signal: SignalSlotClass(_POINTER_) qVariantSignal (QVariant())' flowId='tst_Signaldumper'] ##teamcity[testFinished name='variousTypes()' flowId='tst_Signaldumper'] ##teamcity[testStarted name='deletingSender()' flowId='tst_Signaldumper'] ##teamcity[testStdOut name='deletingSender()' out='INFO: Signal: SignalSlotClass(_POINTER_) signalWithoutParameters ()' flowId='tst_Signaldumper'] diff --git a/tests/auto/testlib/selftests/expected_signaldumper.txt b/tests/auto/testlib/selftests/expected_signaldumper.txt index 0ee8cd38a2..92d609d14c 100644 --- a/tests/auto/testlib/selftests/expected_signaldumper.txt +++ b/tests/auto/testlib/selftests/expected_signaldumper.txt @@ -134,7 +134,7 @@ INFO : tst_Signaldumper::variousTypes() Signal: SignalSlotClass(_POINTER_) qSt INFO : tst_Signaldumper::variousTypes() Signal: SignalSlotClass(_POINTER_) qStringRefSignal ((QString&)@_POINTER_) INFO : tst_Signaldumper::variousTypes() Signal: SignalSlotClass(_POINTER_) qStringConstRefSignal (QString(Test string)) INFO : tst_Signaldumper::variousTypes() Signal: SignalSlotClass(_POINTER_) qByteArraySignal (QByteArray(Test bytearray)) -INFO : tst_Signaldumper::variousTypes() Signal: SignalSlotClass(_POINTER_) qListSignal (QList()) +INFO : tst_Signaldumper::variousTypes() Signal: SignalSlotClass(_POINTER_) qListSignal (QVector()) INFO : tst_Signaldumper::variousTypes() Signal: SignalSlotClass(_POINTER_) qVectorSignal (QVector()) INFO : tst_Signaldumper::variousTypes() Signal: SignalSlotClass(_POINTER_) qVectorRefSignal ((QVector&)@_POINTER_) INFO : tst_Signaldumper::variousTypes() Signal: SignalSlotClass(_POINTER_) qVectorConstRefSignal (QVector()) diff --git a/tests/auto/testlib/selftests/expected_signaldumper.xml b/tests/auto/testlib/selftests/expected_signaldumper.xml index f11a0c3ce6..01b0471268 100644 --- a/tests/auto/testlib/selftests/expected_signaldumper.xml +++ b/tests/auto/testlib/selftests/expected_signaldumper.xml @@ -544,7 +544,7 @@ - ())]]> + ())]]> ())]]> diff --git a/tests/auto/testlib/selftests/expected_signaldumper.xunitxml b/tests/auto/testlib/selftests/expected_signaldumper.xunitxml index cbf7075ba1..6609f518a2 100644 --- a/tests/auto/testlib/selftests/expected_signaldumper.xunitxml +++ b/tests/auto/testlib/selftests/expected_signaldumper.xunitxml @@ -142,7 +142,7 @@ - + @@ -274,7 +274,7 @@ -())]]> +())]]> ())]]> &)@_POINTER_)]]> ())]]> diff --git a/tests/auto/tools/moc/allmocs_baseline_in.json b/tests/auto/tools/moc/allmocs_baseline_in.json index bde5a1c52b..d6b5375c5b 100644 --- a/tests/auto/tools/moc/allmocs_baseline_in.json +++ b/tests/auto/tools/moc/allmocs_baseline_in.json @@ -313,7 +313,7 @@ "read": "flagsList", "scriptable": true, "stored": true, - "type": "QList", + "type": "QVector", "user": false, "write": "setFlagsList" } @@ -340,7 +340,7 @@ "access": "public", "arguments": [ { - "type": "QList >" + "type": "QVector >" } ], "name": "foo", @@ -350,7 +350,7 @@ "access": "public", "arguments": [ { - "type": "QList >" + "type": "QVector >" } ], "name": "foo2", @@ -360,7 +360,7 @@ "access": "public", "arguments": [ { - "type": "QList< ::AAA::BaseA*>" + "type": "QVector< ::AAA::BaseA*>" } ], "name": "bar", @@ -370,7 +370,7 @@ "access": "public", "arguments": [ { - "type": "QList< ::AAA::BaseA*>" + "type": "QVector< ::AAA::BaseA*>" } ], "name": "bar2", @@ -380,7 +380,7 @@ "access": "public", "arguments": [ { - "type": "QList" + "type": "QVector" } ], "name": "bar3", -- cgit v1.2.3