Remove usages of deprecated APIs from QtAlgorithms

Task-number: QTBUG-76491
Change-Id: I9dab736a0cbd2e86588919640c26e8ce6b3674d0
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
Sona Kurazyan 2019-06-20 17:40:45 +02:00
parent fabf9239e0
commit ff2b2032a0
21 changed files with 35 additions and 58 deletions

View File

@ -131,7 +131,7 @@ while (i != set.end()) {
//! [10] //! [10]
QSet<QString> set; QSet<QString> set;
... ...
QSet<QString>::iterator it = qFind(set.begin(), set.end(), "Jeanette"); QSet<QString>::iterator it = std::find(set.begin(), set.end(), "Jeanette");
if (it != set.end()) if (it != set.end())
cout << "Found Jeanette" << Qt::endl; cout << "Found Jeanette" << Qt::endl;
//! [10] //! [10]
@ -150,7 +150,7 @@ for (i = set.begin(); i != set.end(); ++i)
//! [12] //! [12]
QSet<QString> set; QSet<QString> set;
... ...
QSet<QString>::iterator it = qFind(set.begin(), set.end(), "Jeanette"); QSet<QString>::iterator it = std::find(set.begin(), set.end(), "Jeanette");
if (it != set.constEnd()) if (it != set.constEnd())
cout << "Found Jeanette" << Qt::endl; cout << "Found Jeanette" << Qt::endl;
//! [12] //! [12]
@ -161,7 +161,7 @@ QSet<QString> set;
set << "red" << "green" << "blue" << ... << "black"; set << "red" << "green" << "blue" << ... << "black";
QList<QString> list = set.toList(); QList<QString> list = set.toList();
qSort(list); std::sort(list.begin(), list.end());
//! [13] //! [13]

View File

@ -119,8 +119,8 @@ for (i = list.begin(); i != list.end(); ++i)
//! [8] //! [8]
QLinkedList<QString> list; QLinkedList<QString> list;
... ...
QLinkedList<QString>::iterator it = qFind(list.begin(), QLinkedList<QString>::iterator it = std::find(list.begin(),
list.end(), "Joel"); list.end(), "Joel");
if (it != list.end()) if (it != list.end())
cout << "Found Joel" << Qt::endl; cout << "Found Joel" << Qt::endl;
//! [8] //! [8]
@ -189,8 +189,8 @@ for (i = list.constBegin(); i != list.constEnd(); ++i)
//! [15] //! [15]
QLinkedList<QString> list; QLinkedList<QString> list;
... ...
QLinkedList<QString>::iterator it = qFind(list.constBegin(), QLinkedList<QString>::const_iterator it = std::find(list.constBegin(),
list.constEnd(), "Joel"); list.constEnd(), "Joel");
if (it != list.constEnd()) if (it != list.constEnd())
cout << "Found Joel" << Qt::endl; cout << "Found Joel" << Qt::endl;
//! [15] //! [15]

View File

@ -247,7 +247,7 @@ QSet<int> set;
set << 20 << 30 << 40 << ... << 70; set << 20 << 30 << 40 << ... << 70;
QList<int> list = QList<int>::fromSet(set); QList<int> list = QList<int>::fromSet(set);
qSort(list); std::sort(list.begin(), list.end());
//! [23] //! [23]

View File

@ -666,7 +666,7 @@
\li \b{Logarithmic time:} O(log \e n). A function that runs in \li \b{Logarithmic time:} O(log \e n). A function that runs in
logarithmic time is a function whose running time is logarithmic time is a function whose running time is
proportional to the logarithm of the number of items in the proportional to the logarithm of the number of items in the
container. One example is qBinaryFind(). container. One example is the binary search algorithm.
\li \b{Linear time:} O(\e n). A function that runs in linear time \li \b{Linear time:} O(\e n). A function that runs in linear time
will execute in a time directly proportional to the number of will execute in a time directly proportional to the number of

View File

@ -742,8 +742,7 @@ const QLinkedListData QLinkedListData::shared_null = {
\snippet code/src_corelib_tools_qlinkedlist.cpp 7 \snippet code/src_corelib_tools_qlinkedlist.cpp 7
STL-style iterators can be used as arguments to \l{generic STL-style iterators can be used as arguments to \l{generic
algorithms}. For example, here's how to find an item in the list algorithms}. For example, here's how to find an item in the list:
using the qFind() algorithm:
\snippet code/src_corelib_tools_qlinkedlist.cpp 8 \snippet code/src_corelib_tools_qlinkedlist.cpp 8
@ -987,8 +986,7 @@ const QLinkedListData QLinkedListData::shared_null = {
\snippet code/src_corelib_tools_qlinkedlist.cpp 14 \snippet code/src_corelib_tools_qlinkedlist.cpp 14
STL-style iterators can be used as arguments to \l{generic STL-style iterators can be used as arguments to \l{generic
algorithms}. For example, here's how to find an item in the list algorithms}. For example, here's how to find an item in the list:
using the qFind() algorithm:
\snippet code/src_corelib_tools_qlinkedlist.cpp 15 \snippet code/src_corelib_tools_qlinkedlist.cpp 15

View File

@ -1912,7 +1912,7 @@
\section3 Custom sorting models \section3 Custom sorting models
QSortFilterProxyModel instances use Qt's built-in qStableSort() function to set up QSortFilterProxyModel instances use std::stable_sort() function to set up
mappings between items in the source model and those in the proxy model, allowing a mappings between items in the source model and those in the proxy model, allowing a
sorted hierarchy of items to be exposed to views without modifying the structure of the sorted hierarchy of items to be exposed to views without modifying the structure of the
source model. To provide custom sorting behavior, reimplement the source model. To provide custom sorting behavior, reimplement the

View File

@ -28,7 +28,6 @@
#include <QTest> #include <QTest>
#include <QtAlgorithms>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QRandomGenerator> #include <QRandomGenerator>

View File

@ -67,7 +67,6 @@ void foo()
#include <algorithm> #include <algorithm>
#include "qalgorithms.h"
#include "qbitarray.h" #include "qbitarray.h"
#include "qbytearray.h" #include "qbytearray.h"
#include "qcache.h" #include "qcache.h"
@ -191,16 +190,6 @@ void tst_Collections::list()
QVERIFY(list.size() == 6); QVERIFY(list.size() == 6);
QVERIFY(list.end() - list.begin() == list.size()); QVERIFY(list.end() - list.begin() == list.size());
#if !defined(Q_CC_MSVC) && !defined(Q_CC_SUN)
QVERIFY(std::binary_search(list.begin(), list.end(), 2) == true);
QVERIFY(std::binary_search(list.begin(), list.end(), 9) == false);
#endif
QVERIFY(qBinaryFind(list.begin(), list.end(), 2) == list.begin() + 1);
QVERIFY(qLowerBound(list.begin(), list.end(), 2) == list.begin() + 1);
QVERIFY(qUpperBound(list.begin(), list.end(), 2) == list.begin() + 2);
QVERIFY(qBinaryFind(list.begin(), list.end(), 9) == list.end());
QVERIFY(qLowerBound(list.begin(), list.end(), 9) == list.end());
QVERIFY(qUpperBound(list.begin(), list.end(), 9) == list.end());
{ {
int sum = 0; int sum = 0;
QListIterator<int> i(list); QListIterator<int> i(list);
@ -996,16 +985,8 @@ void tst_Collections::vector()
v.append(2); v.append(2);
QVERIFY(*v.begin() == 2); QVERIFY(*v.begin() == 2);
v.prepend(1); v.prepend(1);
QVERIFY(*v.begin() == 1);
v << 3 << 4 << 5 << 6; QVERIFY(*(v.begin() + 1) == 2);
QVERIFY(std::binary_search(v.begin(), v.end(), 2) == true);
QVERIFY(std::binary_search(v.begin(), v.end(), 9) == false);
QVERIFY(qBinaryFind(v.begin(), v.end(), 2) == v.begin() + 1);
QVERIFY(qLowerBound(v.begin(), v.end(), 2) == v.begin() + 1);
QVERIFY(qUpperBound(v.begin(), v.end(), 2) == v.begin() + 2);
QVERIFY(qBinaryFind(v.begin(), v.end(), 9) == v.end());
QVERIFY(qLowerBound(v.begin(), v.end(), 9) == v.end());
QVERIFY(qUpperBound(v.begin(), v.end(), 9) == v.end());
v.clear(); v.clear();
v << 1 << 2 << 3; v << 1 << 2 << 3;

View File

@ -192,7 +192,7 @@ static void doTestData(const QString &testString, const QList<int> &expectedBrea
// test toPreviousBoundary() // test toPreviousBoundary()
{ {
QList<int> expectedBreakPositionsRev = expectedBreakPositions; QList<int> expectedBreakPositionsRev = expectedBreakPositions;
std::sort(expectedBreakPositionsRev.begin(), expectedBreakPositionsRev.end(), qGreater<int>()); std::sort(expectedBreakPositionsRev.begin(), expectedBreakPositionsRev.end(), std::greater<int>());
QList<int> actualBreakPositions; QList<int> actualBreakPositions;
boundaryFinder.toEnd(); boundaryFinder.toEnd();

View File

@ -155,7 +155,7 @@ void tst_QKeyEvent::modifiers_data()
modifierCombinations.append(modifierCombination); modifierCombinations.append(modifierCombination);
} }
qSort(modifierCombinations.begin(), modifierCombinations.end(), orderByModifier); std::sort(modifierCombinations.begin(), modifierCombinations.end(), orderByModifier);
QTest::addColumn<Qt::KeyboardModifiers>("modifiers"); QTest::addColumn<Qt::KeyboardModifiers>("modifiers");
foreach (const QVector<int> combination, modifierCombinations) { foreach (const QVector<int> combination, modifierCombinations) {

View File

@ -86,7 +86,7 @@ static const MacSpecialKey * const MacSpecialKeyEntriesEnd = entries + NumEntrie
static QChar macSymbolForQtKey(int key) static QChar macSymbolForQtKey(int key)
{ {
const MacSpecialKey *i = qBinaryFind(entries, MacSpecialKeyEntriesEnd, key); const MacSpecialKey *i = std::lower_bound(entries, MacSpecialKeyEntriesEnd, key);
if (i == MacSpecialKeyEntriesEnd) if (i == MacSpecialKeyEntriesEnd)
return QChar(); return QChar();
return QChar(i->macSymbol); return QChar(i->macSymbol);

View File

@ -711,7 +711,7 @@ void tst_QSslSocket::sslErrors()
const auto socketSslErrors = socket->sslErrors(); const auto socketSslErrors = socket->sslErrors();
for (const QSslError &err : socketSslErrors) for (const QSslError &err : socketSslErrors)
sslErrors << err.error(); sslErrors << err.error();
qSort(sslErrors); std::sort(sslErrors.begin(), sslErrors.end());
QVERIFY(sslErrors.contains(QSslError::HostNameMismatch)); QVERIFY(sslErrors.contains(QSslError::HostNameMismatch));
QVERIFY(sslErrors.contains(FLUKE_CERTIFICATE_ERROR)); QVERIFY(sslErrors.contains(FLUKE_CERTIFICATE_ERROR));
@ -721,7 +721,7 @@ void tst_QSslSocket::sslErrors()
const auto sslErrorsSpyErrors = qvariant_cast<QList<QSslError> >(qAsConst(sslErrorsSpy).first().first()); const auto sslErrorsSpyErrors = qvariant_cast<QList<QSslError> >(qAsConst(sslErrorsSpy).first().first());
for (const QSslError &err : sslErrorsSpyErrors) for (const QSslError &err : sslErrorsSpyErrors)
emittedErrors << err.error(); emittedErrors << err.error();
qSort(emittedErrors); std::sort(emittedErrors.begin(), emittedErrors.end());
QCOMPARE(sslErrors, emittedErrors); QCOMPARE(sslErrors, emittedErrors);
// check the same errors were emitted by peerVerifyError // check the same errors were emitted by peerVerifyError
@ -730,7 +730,7 @@ void tst_QSslSocket::sslErrors()
const QList<QVariantList> &peerVerifyList = peerVerifyErrorSpy; const QList<QVariantList> &peerVerifyList = peerVerifyErrorSpy;
for (const QVariantList &args : peerVerifyList) for (const QVariantList &args : peerVerifyList)
peerErrors << qvariant_cast<QSslError>(args.first()).error(); peerErrors << qvariant_cast<QSslError>(args.first()).error();
qSort(peerErrors); std::sort(peerErrors.begin(), peerErrors.end());
QCOMPARE(sslErrors, peerErrors); QCOMPARE(sslErrors, peerErrors);
} }

View File

@ -32,7 +32,6 @@
#include <QtCore/qiterator.h> #include <QtCore/qiterator.h>
#include <QtCore/qdebug.h> #include <QtCore/qdebug.h>
#include <QtCore/qatomic.h> #include <QtCore/qatomic.h>
#include <QtCore/qalgorithms.h>
#include <QtCore/qlist.h> #include <QtCore/qlist.h>
#include <QtCore/private/qtools_p.h> #include <QtCore/private/qtools_p.h>
@ -263,9 +262,9 @@ public:
//static QRawVector<T> fromList(const QList<T> &list); //static QRawVector<T> fromList(const QList<T> &list);
static inline QRawVector<T> fromStdVector(const std::vector<T> &vector) static inline QRawVector<T> fromStdVector(const std::vector<T> &vector)
{ QRawVector<T> tmp; qCopy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; } { QRawVector<T> tmp; std::copy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; }
inline std::vector<T> toStdVector() const inline std::vector<T> toStdVector() const
{ std::vector<T> tmp; qCopy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; } { std::vector<T> tmp; std::copy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; }
private: private:
T *allocate(int alloc); T *allocate(int alloc);
@ -568,7 +567,7 @@ typename QRawVector<T>::iterator QRawVector<T>::erase(iterator abegin, iterator
int l = int(aend - m_begin); int l = int(aend - m_begin);
int n = l - f; int n = l - f;
if (QTypeInfo<T>::isComplex) { if (QTypeInfo<T>::isComplex) {
qCopy(m_begin + l, m_begin + m_size, m_begin + f); std::copy(m_begin + l, m_begin + m_size, m_begin + f);
T *i = m_begin + m_size; T *i = m_begin + m_size;
T *b = m_begin + m_size - n; T *b = m_begin + m_size - n;
while (i != b) { while (i != b) {

View File

@ -908,7 +908,7 @@ void tst_qnetworkreply::httpsRequestChain()
qint64 average = (elapsed / count); qint64 average = (elapsed / count);
qSort(helper.timeList); std::sort(helper.timeList.begin(), helper.timeList.end());
qint64 median = helper.timeList.at(5); qint64 median = helper.timeList.at(5);
qDebug() << "Total:" << elapsed << " Average:" << average << " Median:" << median; qDebug() << "Total:" << elapsed << " Average:" << average << " Median:" << median;

View File

@ -83,7 +83,7 @@ int main(int argc, char**argv)
// disconnected // disconnected
exit(0); exit(0);
} }
qFill(buf, buf + bufsize, 0); std::fill(buf, buf + bufsize, 0);
ret = socketEngine->read(buf, available); ret = socketEngine->read(buf, available);
if (ret > 0) { if (ret > 0) {
printf("%s", buf); printf("%s", buf);

View File

@ -184,7 +184,7 @@ void CodeGenerator::writeCoreFactoryImplementation(const QString &fileName) cons
// Get the set of version functions classes we need to create // Get the set of version functions classes we need to create
QList<Version> versions = m_parser->versions(); QList<Version> versions = m_parser->versions();
qSort(versions.begin(), versions.end(), qGreater<Version>()); std::sort(m_versions.begin(), m_versions.end(), std::greater<Version>());
// Outout the #include statements // Outout the #include statements
stream << QStringLiteral("#if !defined(QT_OPENGL_ES_2)") << endl; stream << QStringLiteral("#if !defined(QT_OPENGL_ES_2)") << endl;

View File

@ -291,7 +291,7 @@ void LegacySpecParser::parseFunctions(QTextStream &stream)
} }
m_versions = versions.toList(); m_versions = versions.toList();
qSort(m_versions); std::sort(m_versions.begin(), m_versions.end());
} }
bool LegacySpecParser::inDeprecationException(const QString &functionName) const bool LegacySpecParser::inDeprecationException(const QString &functionName) const

View File

@ -183,7 +183,7 @@ Generator::Generator(const DFA &_dfa, const Config &config)
: dfa(_dfa), cfg(config) : dfa(_dfa), cfg(config)
{ {
QList<InputType> lst = cfg.maxInputSet.toList(); QList<InputType> lst = cfg.maxInputSet.toList();
qSort(lst); std::sort(lst.begin(), lst.end());
minInput = lst.first(); minInput = lst.first();
maxInput = lst.last(); maxInput = lst.last();
@ -230,7 +230,7 @@ static QVector<Generator::TransitionSequence> convertToSequences(const Transitio
return sequences; return sequences;
QList<InputType> keys = transitions.keys(); QList<InputType> keys = transitions.keys();
qSort(keys); std::sort(keys.begin(), keys.end());
int i = 0; int i = 0;
Generator::TransitionSequence sequence; Generator::TransitionSequence sequence;
sequence.first = keys.at(0); sequence.first = keys.at(0);
@ -359,7 +359,7 @@ void Generator::generateTransitions(CodeBlock &body, const TransitionMap &transi
} }
} else { } else {
QList<InputType> keys = transitions.keys(); QList<InputType> keys = transitions.keys();
qSort(keys); std::sort(keys.begin(), keys.end());
body << "switch (ch.unicode()) {"; body << "switch (ch.unicode()) {";
body.indent(); body.indent();

View File

@ -384,7 +384,7 @@ QSet<int> NFA::epsilonClosure(const QSet<int> &initialClosure) const
QStack<int> stateStack; QStack<int> stateStack;
stateStack.resize(closure.count()); stateStack.resize(closure.count());
qCopy(closure.constBegin(), closure.constEnd(), stateStack.begin()); std::copy(closure.constBegin(), closure.constEnd(), stateStack.begin());
while (!stateStack.isEmpty()) { while (!stateStack.isEmpty()) {
int t = stateStack.pop(); int t = stateStack.pop();

View File

@ -128,7 +128,7 @@ int main(int argc, char **argv)
list += QByteArray(" { 0x" + QByteArray::number(m.b5, 16) + ", 0x" + QByteArray::number(m.uc, 16) + " }\n");; list += QByteArray(" { 0x" + QByteArray::number(m.b5, 16) + ", 0x" + QByteArray::number(m.uc, 16) + " }\n");;
} }
QByteArray ba; QByteArray ba;
qSort(list); std::sort(list.begin(), list.end());
foreach(QByteArray a, list) foreach(QByteArray a, list)
ba += a; ba += a;
qDebug() << "struct B5Map b5_to_uc_map = {\n" << ba + "\n};"; qDebug() << "struct B5Map b5_to_uc_map = {\n" << ba + "\n};";
@ -138,7 +138,7 @@ int main(int argc, char **argv)
if (!b5_ok.contains(m.uc)) if (!b5_ok.contains(m.uc))
list += QByteArray(" { 0x" + QByteArray::number(m.uc, 16) + ", 0x" + QByteArray::number(m.b5, 16) + " }\n");; list += QByteArray(" { 0x" + QByteArray::number(m.uc, 16) + ", 0x" + QByteArray::number(m.b5, 16) + " }\n");;
ba = QByteArray(); ba = QByteArray();
qSort(list); std::sort(list.begin(), list.end());;
foreach(QByteArray a, list) foreach(QByteArray a, list)
ba += a; ba += a;
qDebug() << "struct B5Map uc_to_b5_map = {\n" << ba + "\n};"; qDebug() << "struct B5Map uc_to_b5_map = {\n" << ba + "\n};";

View File

@ -2832,7 +2832,7 @@ static QByteArray createLigatureInfo()
QList<Ligature> l = ligatureHashes.value(uc); QList<Ligature> l = ligatureHashes.value(uc);
if (!l.isEmpty()) { if (!l.isEmpty()) {
Q_ASSERT(!QChar::requiresSurrogates(uc)); Q_ASSERT(!QChar::requiresSurrogates(uc));
qSort(l); // needed for bsearch in ligatureHelper code std::sort(l.begin(), l.end()); // needed for bsearch in ligatureHelper code
ligatures.append(l.size()); ligatures.append(l.size());
for (int j = 0; j < l.size(); ++j) { for (int j = 0; j < l.size(); ++j) {
@ -2864,7 +2864,7 @@ static QByteArray createLigatureInfo()
QList<Ligature> l = ligatureHashes.value(uc); QList<Ligature> l = ligatureHashes.value(uc);
if (!l.isEmpty()) { if (!l.isEmpty()) {
Q_ASSERT(QChar::requiresSurrogates(uc)); Q_ASSERT(QChar::requiresSurrogates(uc));
qSort(l); // needed for bsearch in ligatureHelper code std::sort(l.begin(), l.end()); // needed for bsearch in ligatureHelper code
ligatures.append(l.size()); ligatures.append(l.size());
for (int j = 0; j < l.size(); ++j) { for (int j = 0; j < l.size(); ++j) {