summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-10-06 11:39:54 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-10-07 14:37:04 +0200
commit3ecd6ad4cd0bcec11e17f69e9e5d25057634b048 (patch)
tree3b31726e55e548e8f1643243715daa4305972995
parent8f8aacdeadea1ddf92923f6183c4c67925a25db2 (diff)
Port from qAsConst() to std::as_const()
We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace. Task-number: QTBUG-99313 Change-Id: I4b4548c9d4a13337731159c1e1184e48bb0a328b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--examples/statemachine/animation/stickman/animation.cpp2
-rw-r--r--examples/statemachine/animation/sub-attaq/animationmanager.cpp4
-rw-r--r--examples/statemachine/animation/sub-attaq/graphicsscene.cpp6
-rw-r--r--src/scxml/qscxmlcompiler.cpp20
-rw-r--r--src/scxml/qscxmlcompiler_p.h2
-rw-r--r--src/scxml/qscxmltabledata.cpp16
-rw-r--r--src/scxmlqml/eventconnection.cpp4
-rw-r--r--src/statemachine/qstatemachine.cpp12
-rw-r--r--src/statemachineqml/childrenprivate_p.h2
-rw-r--r--tests/auto/compiled/tst_compiled.cpp2
-rw-r--r--tools/qscxmlc/generator.cpp2
-rw-r--r--tools/qscxmlc/qscxmlc.cpp4
-rw-r--r--tools/qscxmlc/scxmlcppdumper.cpp4
13 files changed, 40 insertions, 40 deletions
diff --git a/examples/statemachine/animation/stickman/animation.cpp b/examples/statemachine/animation/stickman/animation.cpp
index b02a7e9..9109732 100644
--- a/examples/statemachine/animation/stickman/animation.cpp
+++ b/examples/statemachine/animation/stickman/animation.cpp
@@ -110,7 +110,7 @@ void Animation::save(QIODevice *device) const
QDataStream stream(device);
stream << m_name;
stream << m_frames.size();
- for (const Frame *frame : qAsConst(m_frames)) {
+ for (const Frame *frame : std::as_const(m_frames)) {
stream << frame->nodeCount();
for (int i = 0; i < frame->nodeCount(); ++i)
stream << frame->nodePos(i);
diff --git a/examples/statemachine/animation/sub-attaq/animationmanager.cpp b/examples/statemachine/animation/sub-attaq/animationmanager.cpp
index 4be1706..2064eac 100644
--- a/examples/statemachine/animation/sub-attaq/animationmanager.cpp
+++ b/examples/statemachine/animation/sub-attaq/animationmanager.cpp
@@ -37,14 +37,14 @@ void AnimationManager::unregisterAllAnimations()
void AnimationManager::pauseAll()
{
- for (QAbstractAnimation *animation : qAsConst(animations)) {
+ for (QAbstractAnimation *animation : std::as_const(animations)) {
if (animation->state() == QAbstractAnimation::Running)
animation->pause();
}
}
void AnimationManager::resumeAll()
{
- for (QAbstractAnimation *animation : qAsConst(animations)) {
+ for (QAbstractAnimation *animation : std::as_const(animations)) {
if (animation->state() == QAbstractAnimation::Paused)
animation->resume();
}
diff --git a/examples/statemachine/animation/sub-attaq/graphicsscene.cpp b/examples/statemachine/animation/sub-attaq/graphicsscene.cpp
index 0c31623..13c8b09 100644
--- a/examples/statemachine/animation/sub-attaq/graphicsscene.cpp
+++ b/examples/statemachine/animation/sub-attaq/graphicsscene.cpp
@@ -229,21 +229,21 @@ void GraphicsScene::onSubMarineExecutionFinished()
void GraphicsScene::clearScene()
{
- for (SubMarine *sub : qAsConst(submarines)) {
+ for (SubMarine *sub : std::as_const(submarines)) {
// make sure to not go into onSubMarineExecutionFinished
sub->disconnect(this);
sub->destroy();
sub->deleteLater();
}
- for (Torpedo *torpedo : qAsConst(torpedos)) {
+ for (Torpedo *torpedo : std::as_const(torpedos)) {
// make sure to not go into onTorpedoExecutionFinished
torpedo->disconnect(this);
torpedo->destroy();
torpedo->deleteLater();
}
- for (Bomb *bomb : qAsConst(bombs)) {
+ for (Bomb *bomb : std::as_const(bombs)) {
// make sure to not go into onBombExecutionFinished
bomb->disconnect(this);
bomb->destroy();
diff --git a/src/scxml/qscxmlcompiler.cpp b/src/scxml/qscxmlcompiler.cpp
index fdd5aff..ffd0ab6 100644
--- a/src/scxml/qscxmlcompiler.cpp
+++ b/src/scxml/qscxmlcompiler.cpp
@@ -53,7 +53,7 @@ public:
doc->isVerified = true;
m_doc = doc;
- for (DocumentModel::AbstractState *state : qAsConst(doc->allStates)) {
+ for (DocumentModel::AbstractState *state : std::as_const(doc->allStates)) {
if (state->id.isEmpty()) {
continue;
#ifndef QT_NO_DEBUG
@@ -84,7 +84,7 @@ private:
}
} else {
QList<DocumentModel::AbstractState *> initialStates;
- for (const QString &initial : qAsConst(scxml->initial)) {
+ for (const QString &initial : std::as_const(scxml->initial)) {
if (DocumentModel::AbstractState *s = m_stateById.value(initial))
initialStates.append(s);
else
@@ -122,7 +122,7 @@ private:
} else {
Q_ASSERT(state->type == DocumentModel::State::Normal);
QList<DocumentModel::AbstractState *> initialStates;
- for (const QString &initialState : qAsConst(state->initial)) {
+ for (const QString &initialState : std::as_const(state->initial)) {
if (DocumentModel::AbstractState *s = m_stateById.value(initialState)) {
initialStates.append(s);
} else {
@@ -173,7 +173,7 @@ private:
if (int size = transition->targets.size())
transition->targetStates.reserve(size);
- for (const QString &target : qAsConst(transition->targets)) {
+ for (const QString &target : std::as_const(transition->targets)) {
if (DocumentModel::AbstractState *s = m_stateById.value(target)) {
if (transition->targetStates.contains(s)) {
error(transition->xmlLocation, QStringLiteral("duplicate target '%1'").arg(target));
@@ -184,7 +184,7 @@ private:
error(transition->xmlLocation, QStringLiteral("unknown state '%1' in target").arg(target));
}
}
- for (const QString &event : qAsConst(transition->events))
+ for (const QString &event : std::as_const(transition->events))
checkEvent(event, transition->xmlLocation, AllowWildCards);
m_parentNodes.append(transition);
@@ -199,7 +199,7 @@ private:
bool visit(DocumentModel::HistoryState *state) override
{
bool seenTransition = false;
- for (DocumentModel::StateOrTransition *sot : qAsConst(state->children)) {
+ for (DocumentModel::StateOrTransition *sot : std::as_const(state->children)) {
if (DocumentModel::State *s = sot->asState()) {
error(s->xmlLocation, QStringLiteral("history state cannot have substates"));
} else if (DocumentModel::Transition *t = sot->asTransition()) {
@@ -369,7 +369,7 @@ private:
const auto &allChildren = allChildrenOfContainer(container);
QList<DocumentModel::AbstractState *> childStates;
- for (DocumentModel::StateOrTransition *child : qAsConst(allChildren)) {
+ for (DocumentModel::StateOrTransition *child : std::as_const(allChildren)) {
if (DocumentModel::State *s = child->asState())
return s;
else if (DocumentModel::HistoryState *h = child->asHistoryState())
@@ -384,7 +384,7 @@ private:
const auto &allChildren = allChildrenOfContainer(container);
QList<DocumentModel::AbstractState *> childStates;
- for (DocumentModel::StateOrTransition *child : qAsConst(allChildren)) {
+ for (DocumentModel::StateOrTransition *child : std::as_const(allChildren)) {
if (DocumentModel::State *s = child->asState())
childStates.append(s);
else if (DocumentModel::HistoryState *h = child->asHistoryState())
@@ -1161,7 +1161,7 @@ void DocumentModel::Param::accept(DocumentModel::NodeVisitor *visitor)
void DocumentModel::DoneData::accept(DocumentModel::NodeVisitor *visitor)
{
if (visitor->visit(this)) {
- for (Param *param : qAsConst(params))
+ for (Param *param : std::as_const(params))
param->accept(visitor);
}
visitor->endVisit(this);
@@ -1234,7 +1234,7 @@ void DocumentModel::State::accept(DocumentModel::NodeVisitor *visitor)
visitor->visit(onExit);
if (doneData)
doneData->accept(visitor);
- for (Invoke *invoke : qAsConst(invokes))
+ for (Invoke *invoke : std::as_const(invokes))
invoke->accept(visitor);
}
visitor->endVisit(this);
diff --git a/src/scxml/qscxmlcompiler_p.h b/src/scxml/qscxmlcompiler_p.h
index 927764e..498018c 100644
--- a/src/scxml/qscxmlcompiler_p.h
+++ b/src/scxml/qscxmlcompiler_p.h
@@ -475,7 +475,7 @@ public:
void visit(InstructionSequence *sequence)
{
Q_ASSERT(sequence);
- for (Instruction *instruction : qAsConst(*sequence)) {
+ for (Instruction *instruction : std::as_const(*sequence)) {
Q_ASSERT(instruction);
instruction->accept(this);
}
diff --git a/src/scxml/qscxmltabledata.cpp b/src/scxml/qscxmltabledata.cpp
index 2bfe938..81de319 100644
--- a/src/scxml/qscxmltabledata.cpp
+++ b/src/scxml/qscxmltabledata.cpp
@@ -112,13 +112,13 @@ public:
m_parents.reserve(32);
m_allTransitions.resize(doc->allTransitions.size());
m_docTransitionIndices.reserve(doc->allTransitions.size());
- for (auto *t : qAsConst(doc->allTransitions)) {
+ for (auto *t : std::as_const(doc->allTransitions)) {
m_docTransitionIndices.insert(t, m_docTransitionIndices.size());
}
m_docStatesIndices.reserve(doc->allStates.size());
m_transitionsForState.resize(doc->allStates.size());
m_allStates.resize(doc->allStates.size());
- for (DocumentModel::AbstractState *s : qAsConst(doc->allStates)) {
+ for (DocumentModel::AbstractState *s : std::as_const(doc->allStates)) {
m_docStatesIndices.insert(s, m_docStatesIndices.size());
}
@@ -227,7 +227,7 @@ protected: // visitor
}
QList<DocumentModel::AbstractState *> childStates;
- for (DocumentModel::StateOrTransition *sot : qAsConst(node->children)) {
+ for (DocumentModel::StateOrTransition *sot : std::as_const(node->children)) {
if (DocumentModel::AbstractState *s = sot->asAbstractState()) {
childStates.append(s);
}
@@ -284,13 +284,13 @@ protected: // visitor
newState.exitInstructions = generate(state->onExit);
if (!state->invokes.isEmpty()) {
QList<int> factoryIds;
- for (DocumentModel::Invoke *invoke : qAsConst(state->invokes)) {
+ for (DocumentModel::Invoke *invoke : std::as_const(state->invokes)) {
auto ctxt = createContext(QStringLiteral("invoke"));
QList<QScxmlExecutableContent::StringId> namelist;
- for (const QString &name : qAsConst(invoke->namelist))
+ for (const QString &name : std::as_const(invoke->namelist))
namelist += addString(name);
QList<QScxmlExecutableContent::ParameterInfo> params;
- for (DocumentModel::Param *param : qAsConst(invoke->params)) {
+ for (DocumentModel::Param *param : std::as_const(invoke->params)) {
QScxmlExecutableContent::ParameterInfo p;
p.name = addString(param->name);
p.expr = createEvaluatorVariant(QStringLiteral("param"), QStringLiteral("expr"),
@@ -328,7 +328,7 @@ protected: // visitor
visit(state->children);
QList<DocumentModel::AbstractState *> childStates;
- for (DocumentModel::StateOrTransition *sot : qAsConst(state->children)) {
+ for (DocumentModel::StateOrTransition *sot : std::as_const(state->children)) {
if (auto s = sot->asAbstractState()) {
childStates.append(s);
}
@@ -386,7 +386,7 @@ protected: // visitor
newTransition.targets = addStates(transition->targetStates);
QList<int> eventIds;
- for (const QString &event : qAsConst(transition->events))
+ for (const QString &event : std::as_const(transition->events))
eventIds.push_back(addString(event));
newTransition.events = addArray(eventIds);
diff --git a/src/scxmlqml/eventconnection.cpp b/src/scxmlqml/eventconnection.cpp
index 3a6dcb1..4171438 100644
--- a/src/scxmlqml/eventconnection.cpp
+++ b/src/scxmlqml/eventconnection.cpp
@@ -93,11 +93,11 @@ QBindable<QScxmlStateMachine*> QScxmlEventConnection::bindableStateMachine()
void QScxmlEventConnection::doConnect()
{
- for (const QMetaObject::Connection &connection : qAsConst(m_connections))
+ for (const QMetaObject::Connection &connection : std::as_const(m_connections))
disconnect(connection);
m_connections.clear();
if (m_stateMachine) {
- for (const QString &event : qAsConst(m_events.value())) {
+ for (const QString &event : std::as_const(m_events.value())) {
m_connections.append(m_stateMachine->connectToEvent(event, this,
&QScxmlEventConnection::occurred));
}
diff --git a/src/statemachine/qstatemachine.cpp b/src/statemachine/qstatemachine.cpp
index 86548b4..65d8660 100644
--- a/src/statemachine/qstatemachine.cpp
+++ b/src/statemachine/qstatemachine.cpp
@@ -517,7 +517,7 @@ QList<QAbstractTransition*> QStateMachinePrivate::selectTransitions(QEvent *even
Q_Q(const QStateMachine);
QVarLengthArray<QAbstractState *> configuration_sorted;
- for (QAbstractState *s : qAsConst(configuration)) {
+ for (QAbstractState *s : std::as_const(configuration)) {
if (isAtomic(s))
configuration_sorted.append(s);
}
@@ -525,7 +525,7 @@ QList<QAbstractTransition*> QStateMachinePrivate::selectTransitions(QEvent *even
QList<QAbstractTransition*> enabledTransitions;
const_cast<QStateMachine *>(q)->beginSelectTransitions(event);
- for (QAbstractState *state : qAsConst(configuration_sorted)) {
+ for (QAbstractState *state : std::as_const(configuration_sorted)) {
QList<QState *> lst = getProperAncestors(state, nullptr);
if (QState *grp = toStandardState(state))
lst.prepend(grp);
@@ -592,7 +592,7 @@ void QStateMachinePrivate::removeConflictingTransitions(QList<QAbstractTransitio
filteredTransitions.reserve(enabledTransitions.size());
std::sort(enabledTransitions.begin(), enabledTransitions.end(), transitionStateEntryLessThan);
- for (QAbstractTransition *t1 : qAsConst(enabledTransitions)) {
+ for (QAbstractTransition *t1 : std::as_const(enabledTransitions)) {
bool t1Preempted = false;
const QSet<QAbstractState*> exitSetT1 = computeExitSet_Unordered(t1, cache);
QList<QAbstractTransition*>::iterator t2It = filteredTransitions.begin();
@@ -750,7 +750,7 @@ QSet<QAbstractState*> QStateMachinePrivate::computeExitSet_Unordered(QAbstractTr
Q_ASSERT(domain != nullptr);
}
- for (QAbstractState* s : qAsConst(configuration)) {
+ for (QAbstractState* s : std::as_const(configuration)) {
if (isDescendant(s, domain))
statesToExit.insert(s);
}
@@ -1078,9 +1078,9 @@ void QStateMachinePrivate::addDescendantStatesToEnter(QAbstractState *state,
if (defaultHistoryContent.isEmpty()) {
setError(QStateMachine::NoDefaultStateInHistoryStateError, h);
} else {
- for (QAbstractState *s : qAsConst(defaultHistoryContent))
+ for (QAbstractState *s : std::as_const(defaultHistoryContent))
addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry);
- for (QAbstractState *s : qAsConst(defaultHistoryContent))
+ for (QAbstractState *s : std::as_const(defaultHistoryContent))
addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry);
#ifdef QSTATEMACHINE_DEBUG
qDebug() << q_func() << ": initial history targets for" << state << ':' << defaultHistoryContent;
diff --git a/src/statemachineqml/childrenprivate_p.h b/src/statemachineqml/childrenprivate_p.h
index 54f8cc7..c6de691 100644
--- a/src/statemachineqml/childrenprivate_p.h
+++ b/src/statemachineqml/childrenprivate_p.h
@@ -130,7 +130,7 @@ public:
static void clear(QQmlListProperty<QObject> *prop)
{
auto &children = static_cast<Self *>(prop->data)->children;
- for (QObject *oldItem : qAsConst(children))
+ for (QObject *oldItem : std::as_const(children))
Handler::unparentItem(prop, oldItem);
children.clear();
diff --git a/tests/auto/compiled/tst_compiled.cpp b/tests/auto/compiled/tst_compiled.cpp
index 36e0f1a..cf48cda 100644
--- a/tests/auto/compiled/tst_compiled.cpp
+++ b/tests/auto/compiled/tst_compiled.cpp
@@ -54,7 +54,7 @@ void tst_Compiled::stateNames()
QCOMPARE(stateMachine.stateNames(false), ids1States);
- for (const QString &state : qAsConst(ids1States)) {
+ for (const QString &state : std::as_const(ids1States)) {
QVariant prop = stateMachine.property(state.toUtf8().constData());
QVERIFY(!prop.isNull());
QVERIFY(prop.isValid());
diff --git a/tools/qscxmlc/generator.cpp b/tools/qscxmlc/generator.cpp
index 419e5da..bbc4c64 100644
--- a/tools/qscxmlc/generator.cpp
+++ b/tools/qscxmlc/generator.cpp
@@ -664,7 +664,7 @@ void Generator::generateCode()
fprintf(out, "// a) You are using a NOTIFY signal that does not exist. Fix it.\n");
fprintf(out, "// b) You are using a NOTIFY signal that does exist (in a parent class) but has a non-empty parameter list. This is a moc limitation.\n");
fprintf(out, "[[maybe_unused]] static void checkNotifySignalValidity_%s(%s *t) {\n", qualifiedClassNameIdentifier.constData(), cdef->qualified.constData());
- for (const QByteArray &nonClassSignal : qAsConst(cdef->nonClassSignalList))
+ for (const QByteArray &nonClassSignal : std::as_const(cdef->nonClassSignalList))
fprintf(out, " t->%s();\n", nonClassSignal.constData());
fprintf(out, "}\n");
}
diff --git a/tools/qscxmlc/qscxmlc.cpp b/tools/qscxmlc/qscxmlc.cpp
index f8e7a15..fdf89a1 100644
--- a/tools/qscxmlc/qscxmlc.cpp
+++ b/tools/qscxmlc/qscxmlc.cpp
@@ -68,7 +68,7 @@ static void collectAllDocuments(DocumentModel::ScxmlDocument *doc,
QList<DocumentModel::ScxmlDocument *> *docs)
{
docs->append(doc);
- for (DocumentModel::ScxmlDocument *subDoc : qAsConst(doc->allSubDocuments))
+ for (DocumentModel::ScxmlDocument *subDoc : std::as_const(doc->allSubDocuments))
collectAllDocuments(subDoc, docs);
}
@@ -192,7 +192,7 @@ int run(const QStringList &arguments)
docs.pop_front();
- for (DocumentModel::ScxmlDocument *doc : qAsConst(docs)) {
+ for (DocumentModel::ScxmlDocument *doc : std::as_const(docs)) {
auto name = doc->root->name;
auto prefix = name;
if (name.isEmpty()) {
diff --git a/tools/qscxmlc/scxmlcppdumper.cpp b/tools/qscxmlc/scxmlcppdumper.cpp
index 5e19d33..46eb496 100644
--- a/tools/qscxmlc/scxmlcppdumper.cpp
+++ b/tools/qscxmlc/scxmlcppdumper.cpp
@@ -512,7 +512,7 @@ void CppDumper::writeImplStart()
<< Qt::endl;
QStringList includes;
- for (DocumentModel::ScxmlDocument *doc : qAsConst(m_translationUnit->allDocuments)) {
+ for (DocumentModel::ScxmlDocument *doc : std::as_const(m_translationUnit->allDocuments)) {
switch (doc->root->dataModel) {
case DocumentModel::Scxml::NullDataModel:
includes += l("QScxmlNullDataModel");
@@ -534,7 +534,7 @@ void CppDumper::writeImplStart()
cpp << Qt::endl
<< QStringLiteral("#include <qscxmlinvokableservice.h>") << Qt::endl
<< QStringLiteral("#include <qscxmltabledata.h>") << Qt::endl;
- for (const QString &inc : qAsConst(includes)) {
+ for (const QString &inc : std::as_const(includes)) {
cpp << l("#include <") << inc << l(">") << Qt::endl;
}
cpp << Qt::endl