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: I88edd91395849574436299b8badda21bb93bea39
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marc Mutz
2022-10-07 14:46:06 +02:00
parent 90de29d530
commit 8eb4d52342
498 changed files with 1270 additions and 1270 deletions

View File

@@ -127,7 +127,7 @@ public:
fn.append(nodes.first()->sha);
nodes.removeFirst();
for (const BranchNode *n : qAsConst(nodes))
for (const BranchNode *n : std::as_const(nodes))
fn.append(n->name);
return fn;
@@ -390,7 +390,7 @@ Qt::ItemFlags BranchModel::flags(const QModelIndex &index) const
void BranchModel::clear()
{
for (BranchNode *root : qAsConst(d->rootNode->children)) {
for (BranchNode *root : std::as_const(d->rootNode->children)) {
while (root->count())
delete root->children.takeLast();
}

View File

@@ -392,7 +392,7 @@ bool BranchView::checkout()
QList<Stash> stashes;
client->synchronousStashList(m_repository, &stashes);
for (const Stash &stash : qAsConst(stashes)) {
for (const Stash &stash : std::as_const(stashes)) {
if (stash.message.startsWith(popMessageStart)) {
branchCheckoutDialog.foundStashForNextBranch();
break;
@@ -428,7 +428,7 @@ bool BranchView::checkout()
QList<Stash> stashes;
QString stashName;
client->synchronousStashList(m_repository, &stashes);
for (const Stash &stash : qAsConst(stashes)) {
for (const Stash &stash : std::as_const(stashes)) {
if (stash.message.startsWith(popMessageStart)) {
stashName = stash.name;
break;

View File

@@ -908,7 +908,7 @@ void GerritModel::resultRetrieved(const QByteArray &output)
std::stable_sort(changes.begin(), changes.end(), gerritChangeLessThan);
numberIndexHash.clear();
for (const GerritChangePtr &c : qAsConst(changes)) {
for (const GerritChangePtr &c : std::as_const(changes)) {
// Avoid duplicate entries for example in the (unlikely)
// case people do self-reviews.
if (!itemForNumber(c->number)) {

View File

@@ -103,7 +103,7 @@ bool GerritRemoteChooser::updateRemotes(bool forceReload)
void GerritRemoteChooser::addRemote(const GerritServer &server, const QString &name)
{
if (!m_allowDups) {
for (const auto &remote : qAsConst(m_remotes)) {
for (const auto &remote : std::as_const(m_remotes)) {
if (remote.second == server)
return;
}

View File

@@ -1796,7 +1796,7 @@ QString GitClient::synchronousTopic(const FilePath &workingDirectory) const
const QString dereference("^{}");
QString remoteBranch;
for (const QString &ref : qAsConst(references)) {
for (const QString &ref : std::as_const(references)) {
int derefInd = ref.indexOf(dereference);
if (ref.startsWith(tagStart))
return ref.mid(tagStart.size(), (derefInd == -1) ? -1 : derefInd - tagStart.size());
@@ -1968,7 +1968,7 @@ bool GitClient::stashNameFromMessage(const FilePath &workingDirectory,
QList<Stash> stashes;
if (!synchronousStashList(workingDirectory, &stashes, errorMessage))
return false;
for (const Stash &s : qAsConst(stashes)) {
for (const Stash &s : std::as_const(stashes)) {
if (s.message == message) {
*name = s.name;
return true;
@@ -2321,7 +2321,7 @@ void GitClient::updateSubmodulesIfNeeded(const FilePath &workingDirectory, bool
void GitClient::finishSubmoduleUpdate()
{
for (const FilePath &submoduleDir : qAsConst(m_updatedSubmodules))
for (const FilePath &submoduleDir : std::as_const(m_updatedSubmodules))
endStashScope(submoduleDir);
m_updatedSubmodules.clear();
}

View File

@@ -108,7 +108,7 @@ public:
}
single.matchingLine = text;
for (const auto &match : qAsConst(matches)) {
for (const auto &match : std::as_const(matches)) {
single.matchStart = match.matchStart;
single.matchLength = match.matchLength;
single.regexpCapturedTexts = match.regexpCapturedTexts;

View File

@@ -138,7 +138,7 @@ void GitRebaseHighlighter::highlightBlock(const QString &text)
setFormat(match.capturedStart(), match.capturedLength(), formatForCategory(Format_Change));
}
} else {
for (const RebaseAction &action : qAsConst(m_actions)) {
for (const RebaseAction &action : std::as_const(m_actions)) {
const QRegularExpressionMatch match = action.exp.match(text);
if (match.hasMatch()) {
const int len = match.capturedLength();

View File

@@ -1689,15 +1689,15 @@ void GitPluginPrivate::updateActions(VcsBasePluginPrivate::ActionState as)
// Note: This menu is visible if there is no repository. Only
// 'Create Repository'/'Show' actions should be available.
const QString fileName = Utils::quoteAmpersands(state.currentFileName());
for (ParameterAction *fileAction : qAsConst(m_fileActions))
for (ParameterAction *fileAction : std::as_const(m_fileActions))
fileAction->setParameter(fileName);
// If the current file looks like a patch, offer to apply
m_applyCurrentFilePatchAction->setParameter(state.currentPatchFileDisplayName());
const QString projectName = state.currentProjectName();
for (ParameterAction *projectAction : qAsConst(m_projectActions))
for (ParameterAction *projectAction : std::as_const(m_projectActions))
projectAction->setParameter(projectName);
for (QAction *repositoryAction : qAsConst(m_repositoryActions))
for (QAction *repositoryAction : std::as_const(m_repositoryActions))
repositoryAction->setEnabled(repositoryEnabled);
m_submoduleUpdateAction->setVisible(repositoryEnabled