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]
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())
cout << "Found Jeanette" << Qt::endl;
//! [10]
@ -150,7 +150,7 @@ for (i = set.begin(); i != set.end(); ++i)
//! [12]
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())
cout << "Found Jeanette" << Qt::endl;
//! [12]
@ -161,7 +161,7 @@ QSet<QString> set;
set << "red" << "green" << "blue" << ... << "black";
QList<QString> list = set.toList();
qSort(list);
std::sort(list.begin(), list.end());
//! [13]

View File

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

View File

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

View File

@ -666,7 +666,7 @@
\li \b{Logarithmic time:} O(log \e n). A function that runs in
logarithmic time is a function whose running time is
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
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
STL-style iterators can be used as arguments to \l{generic
algorithms}. For example, here's how to find an item in the list
using the qFind() algorithm:
algorithms}. For example, here's how to find an item in the list:
\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
STL-style iterators can be used as arguments to \l{generic
algorithms}. For example, here's how to find an item in the list
using the qFind() algorithm:
algorithms}. For example, here's how to find an item in the list:
\snippet code/src_corelib_tools_qlinkedlist.cpp 15

View File

@ -1912,7 +1912,7 @@
\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
sorted hierarchy of items to be exposed to views without modifying the structure of the
source model. To provide custom sorting behavior, reimplement the

View File

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

View File

@ -67,7 +67,6 @@ void foo()
#include <algorithm>
#include "qalgorithms.h"
#include "qbitarray.h"
#include "qbytearray.h"
#include "qcache.h"
@ -191,16 +190,6 @@ void tst_Collections::list()
QVERIFY(list.size() == 6);
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;
QListIterator<int> i(list);
@ -996,16 +985,8 @@ void tst_Collections::vector()
v.append(2);
QVERIFY(*v.begin() == 2);
v.prepend(1);
v << 3 << 4 << 5 << 6;
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());
QVERIFY(*v.begin() == 1);
QVERIFY(*(v.begin() + 1) == 2);
v.clear();
v << 1 << 2 << 3;

View File

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

View File

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

View File

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

View File

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

View File

@ -32,7 +32,6 @@
#include <QtCore/qiterator.h>
#include <QtCore/qdebug.h>
#include <QtCore/qatomic.h>
#include <QtCore/qalgorithms.h>
#include <QtCore/qlist.h>
#include <QtCore/private/qtools_p.h>
@ -263,9 +262,9 @@ public:
//static QRawVector<T> fromList(const QList<T> &list);
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
{ 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:
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 n = l - f;
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 *b = m_begin + m_size - n;
while (i != b) {

View File

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

View File

@ -83,7 +83,7 @@ int main(int argc, char**argv)
// disconnected
exit(0);
}
qFill(buf, buf + bufsize, 0);
std::fill(buf, buf + bufsize, 0);
ret = socketEngine->read(buf, available);
if (ret > 0) {
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
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
stream << QStringLiteral("#if !defined(QT_OPENGL_ES_2)") << endl;

View File

@ -291,7 +291,7 @@ void LegacySpecParser::parseFunctions(QTextStream &stream)
}
m_versions = versions.toList();
qSort(m_versions);
std::sort(m_versions.begin(), m_versions.end());
}
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)
{
QList<InputType> lst = cfg.maxInputSet.toList();
qSort(lst);
std::sort(lst.begin(), lst.end());
minInput = lst.first();
maxInput = lst.last();
@ -230,7 +230,7 @@ static QVector<Generator::TransitionSequence> convertToSequences(const Transitio
return sequences;
QList<InputType> keys = transitions.keys();
qSort(keys);
std::sort(keys.begin(), keys.end());
int i = 0;
Generator::TransitionSequence sequence;
sequence.first = keys.at(0);
@ -359,7 +359,7 @@ void Generator::generateTransitions(CodeBlock &body, const TransitionMap &transi
}
} else {
QList<InputType> keys = transitions.keys();
qSort(keys);
std::sort(keys.begin(), keys.end());
body << "switch (ch.unicode()) {";
body.indent();

View File

@ -384,7 +384,7 @@ QSet<int> NFA::epsilonClosure(const QSet<int> &initialClosure) const
QStack<int> stateStack;
stateStack.resize(closure.count());
qCopy(closure.constBegin(), closure.constEnd(), stateStack.begin());
std::copy(closure.constBegin(), closure.constEnd(), stateStack.begin());
while (!stateStack.isEmpty()) {
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");;
}
QByteArray ba;
qSort(list);
std::sort(list.begin(), list.end());
foreach(QByteArray a, list)
ba += a;
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))
list += QByteArray(" { 0x" + QByteArray::number(m.uc, 16) + ", 0x" + QByteArray::number(m.b5, 16) + " }\n");;
ba = QByteArray();
qSort(list);
std::sort(list.begin(), list.end());;
foreach(QByteArray a, list)
ba += a;
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);
if (!l.isEmpty()) {
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());
for (int j = 0; j < l.size(); ++j) {
@ -2864,7 +2864,7 @@ static QByteArray createLigatureInfo()
QList<Ligature> l = ligatureHashes.value(uc);
if (!l.isEmpty()) {
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());
for (int j = 0; j < l.size(); ++j) {