Deprecate {to,from}Std{List,Vector}

ask our users to use the range constructors instead. This will allow
us to remove the include dependency towards <list> and <vector> in
Qt 6.

Change-Id: Id90f2058432e19941de1fa847100a7920432ad71
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Lars Knoll 2019-05-03 11:53:18 +02:00
parent b5547e49cd
commit 82ddecfb17
4 changed files with 25 additions and 1 deletions

View File

@ -51,7 +51,9 @@
#include <algorithm>
#include <initializer_list>
#include <iterator>
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
#include <list>
#endif
#include <stdlib.h>
#include <new>
@ -403,10 +405,14 @@ public:
static QList<T> fromVector(const QVector<T> &vector);
static QList<T> fromSet(const QSet<T> &set);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
Q_DECL_DEPRECATED_X("Use QList<T>(list.begin(), list.end()) instead.")
static inline QList<T> fromStdList(const std::list<T> &list)
{ QList<T> tmp; std::copy(list.begin(), list.end(), std::back_inserter(tmp)); return tmp; }
Q_DECL_DEPRECATED_X("Use std::list<T>(list.begin(), list.end()) instead.")
inline std::list<T> toStdList() const
{ std::list<T> tmp; std::copy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; }
#endif
private:
Node *detach_helper_grow(int i, int n);

View File

@ -49,7 +49,9 @@
#include <iterator>
#include <initializer_list>
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
#include <vector>
#endif
#include <stdlib.h>
#include <string.h>
@ -292,10 +294,14 @@ public:
static QVector<T> fromList(const QList<T> &list);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
Q_DECL_DEPRECATED_X("Use QVector<T>(vector.begin(), vector.end()) instead.")
static inline QVector<T> fromStdVector(const std::vector<T> &vector)
{ QVector<T> tmp; tmp.reserve(int(vector.size())); std::copy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; }
Q_DECL_DEPRECATED_X("Use std::vector<T>(vector.begin(), vector.end()) instead.")
inline std::vector<T> toStdVector() const
{ return std::vector<T>(d->begin(), d->end()); }
#endif
private:
// ### Qt6: remove methods, they are unused
void reallocData(const int size, const int alloc, QArrayData::AllocationOptions options = QArrayData::Default);

View File

@ -367,9 +367,11 @@ private slots:
void toSetOptimal() const;
void toSetMovable() const;
void toSetComplex() const;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
void toStdListOptimal() const;
void toStdListMovable() const;
void toStdListComplex() const;
#endif
void toVectorOptimal() const;
void toVectorMovable() const;
void toVectorComplex() const;
@ -427,7 +429,9 @@ private:
template<typename T> void takeFirst() const;
template<typename T> void takeLast() const;
template<typename T> void toSet() const;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
template<typename T> void toStdList() const;
#endif
template<typename T> void toVector() const;
template<typename T> void value() const;
@ -1633,6 +1637,7 @@ void tst_QList::toSetComplex() const
QCOMPARE(liveCount, Complex::getLiveCount());
}
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
template<typename T>
void tst_QList::toStdList() const
{
@ -1669,6 +1674,7 @@ void tst_QList::toStdListComplex() const
toStdList<Complex>();
QCOMPARE(liveCount, Complex::getLiveCount());
}
#endif
template<typename T>
void tst_QList::toVector() const

View File

@ -257,7 +257,6 @@ private slots:
void fromListInt() const;
void fromListMovable() const;
void fromListCustom() const;
void fromStdVector() const;
void indexOf() const;
void insertInt() const;
void insertMovable() const;
@ -296,7 +295,10 @@ private slots:
void swapMovable() const;
void swapCustom() const;
void toList() const;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
void fromStdVector() const;
void toStdVector() const;
#endif
void value() const;
void testOperators() const;
@ -1426,6 +1428,7 @@ void tst_QVector::fromListCustom() const
QCOMPARE(instancesCount, Custom::counter.loadAcquire());
}
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
void tst_QVector::fromStdVector() const
{
// stl = :(
@ -1439,6 +1442,7 @@ void tst_QVector::fromStdVector() const
// test it converts ok
QCOMPARE(myvec, QVector<QString>() << "aaa" << "bbb" << "ninjas" << "pirates");
}
#endif
void tst_QVector::indexOf() const
{
@ -2331,6 +2335,7 @@ void tst_QVector::toList() const
QCOMPARE(myvec, QVector<QString>() << "A" << "B" << "C");
}
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
void tst_QVector::toStdVector() const
{
QVector<QString> myvec;
@ -2343,6 +2348,7 @@ void tst_QVector::toStdVector() const
QCOMPARE(myvec, QVector<QString>() << "A" << "B" << "C");
}
#endif
void tst_QVector::value() const
{