diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-11-11 16:26:04 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-11-18 22:01:16 +0100 |
commit | d45b9beffa79db3ad4b67439e9caf40843f50c1a (patch) | |
tree | 8b04745f1a571b9b6f16217bd063364e1ec92046 | |
parent | c6f7a403e3c89bfbf8ed6d39b8d54c6ec809dbbd (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.
This is a 6.4 re-run of the script we ran in dev, in order to avoid
conflicts between the branches when cherry-picking.
Change-Id: I5eca3df3179dfb2b2682c75a479ba9a4259cc703
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r-- | examples/statemachine/animation/stickman/animation.cpp | 2 | ||||
-rw-r--r-- | examples/statemachine/animation/sub-attaq/animationmanager.cpp | 4 | ||||
-rw-r--r-- | examples/statemachine/animation/sub-attaq/graphicsscene.cpp | 6 | ||||
-rw-r--r-- | src/scxml/qscxmlcompiler.cpp | 20 | ||||
-rw-r--r-- | src/scxml/qscxmlcompiler_p.h | 2 | ||||
-rw-r--r-- | src/scxml/qscxmltabledata.cpp | 16 | ||||
-rw-r--r-- | src/scxmlqml/eventconnection.cpp | 4 | ||||
-rw-r--r-- | src/statemachine/qstatemachine.cpp | 12 | ||||
-rw-r--r-- | src/statemachineqml/childrenprivate_p.h | 2 | ||||
-rw-r--r-- | tests/auto/compiled/tst_compiled.cpp | 2 | ||||
-rw-r--r-- | tools/qscxmlc/generator.cpp | 2 | ||||
-rw-r--r-- | tools/qscxmlc/qscxmlc.cpp | 4 | ||||
-rw-r--r-- | tools/qscxmlc/scxmlcppdumper.cpp | 4 |
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 |