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

@@ -628,7 +628,7 @@ void CMakeBuildStep::recreateBuildTargetsModel()
m_buildTargets.push_back(m_allTarget);
}
for (const QString &buildTarget : qAsConst(targetList))
for (const QString &buildTarget : std::as_const(targetList))
addItem(buildTarget, specialTargets(usesAllCapsTargets).contains(buildTarget));
updateBuildTargetsModel();

View File

@@ -543,7 +543,7 @@ void CMakeBuildSystem::updateProjectData()
{
QSet<QString> res;
QStringList apps;
for (const auto &target : qAsConst(m_buildTargets)) {
for (const auto &target : std::as_const(m_buildTargets)) {
if (target.targetType == DynamicLibraryType) {
res.insert(target.executable.parentDir().toString());
apps.push_back(target.executable.toUserOutput());
@@ -630,7 +630,7 @@ void CMakeBuildSystem::updateProjectData()
QtSupport::KitHasMergedHeaderPathsWithQmlImportPaths::id(), false).toBool();
QStringList extraHeaderPaths;
QList<QByteArray> moduleMappings;
for (const RawProjectPart &rpp : qAsConst(rpps)) {
for (const RawProjectPart &rpp : std::as_const(rpps)) {
FilePath moduleMapFile = buildConfiguration()->buildDirectory()
.pathAppended("qml_module_mappings/" + rpp.buildSystemTarget);
if (moduleMapFile.exists()) {

View File

@@ -448,7 +448,7 @@ private:
extraGeneratorCombo->clear();
extraGeneratorCombo->addItem(Tr::tr("<none>"), QString());
for (const QString &eg : qAsConst(it->extraGenerators))
for (const QString &eg : std::as_const(it->extraGenerators))
extraGeneratorCombo->addItem(eg, eg);
extraGeneratorCombo->setEnabled(extraGeneratorCombo->count() > 1);

View File

@@ -510,7 +510,7 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
buildConfigurationTypes = buildConfigurationTypesString.split(';');
}
for (auto const &buildType: qAsConst(buildConfigurationTypes)) {
for (auto const &buildType: std::as_const(buildConfigurationTypes)) {
auto data = std::make_unique<DirectoryData>();
data->cmakeHomeDirectory =
@@ -745,7 +745,7 @@ void CMakeProjectPlugin::testCMakeProjectImporterQt()
QFETCH(QString, expectedQmake);
CMakeConfig config;
for (const QString &c : qAsConst(cache)) {
for (const QString &c : std::as_const(cache)) {
const int pos = c.indexOf('=');
Q_ASSERT(pos > 0);
const QString key = c.left(pos);
@@ -802,7 +802,7 @@ void CMakeProjectPlugin::testCMakeProjectImporterToolChain()
QCOMPARE(expectedLanguages.count(), expectedToolChains.count());
CMakeConfig config;
for (const QString &c : qAsConst(cache)) {
for (const QString &c : std::as_const(cache)) {
const int pos = c.indexOf('=');
Q_ASSERT(pos > 0);
const QString key = c.left(pos);

View File

@@ -321,7 +321,7 @@ void CMakeToolItemModel::removeCMakeTool(const Id &id)
void CMakeToolItemModel::apply()
{
for (const Id &id : qAsConst(m_removedItems))
for (const Id &id : std::as_const(m_removedItems))
CMakeToolManager::deregisterCMakeTool(id);
QList<CMakeToolTreeItem *> toRegister;
@@ -338,7 +338,7 @@ void CMakeToolItemModel::apply()
}
});
for (CMakeToolTreeItem *item : qAsConst(toRegister)) {
for (CMakeToolTreeItem *item : std::as_const(toRegister)) {
CMakeTool::Detection detection = item->m_autodetected ? CMakeTool::AutoDetection
: CMakeTool::ManualDetection;
auto cmake = std::make_unique<CMakeTool>(detection, item->m_id);

View File

@@ -212,7 +212,7 @@ void CMakeToolManager::listDetectedCMake(const QString &detectionSource, QString
{
QTC_ASSERT(logMessage, return);
QStringList logMessages{Tr::tr("CMake:")};
for (const auto &tool : qAsConst(d->m_cmakeTools)) {
for (const auto &tool : std::as_const(d->m_cmakeTools)) {
if (tool->detectionSource() == detectionSource)
logMessages.append(tool->displayName());
}

View File

@@ -68,7 +68,7 @@ static std::vector<std::unique_ptr<CMakeTool>> autoDetectCMakeTools()
const QStringList execs = env.appendExeExtensions(QLatin1String("cmake"));
FilePaths suspects;
for (const FilePath &base : qAsConst(path)) {
for (const FilePath &base : std::as_const(path)) {
if (base.isEmpty())
continue;
@@ -80,7 +80,7 @@ static std::vector<std::unique_ptr<CMakeTool>> autoDetectCMakeTools()
}
std::vector<std::unique_ptr<CMakeTool>> found;
for (const FilePath &command : qAsConst(suspects)) {
for (const FilePath &command : std::as_const(suspects)) {
auto item = std::make_unique<CMakeTool>(CMakeTool::AutoDetection, CMakeTool::createId());
item->setFilePath(command);
item->setDisplayName(Tr::tr("System CMake at %1").arg(command.toUserOutput()));

View File

@@ -44,7 +44,7 @@ QWidget *ConfigModelItemDelegate::createEditor(QWidget *parent, const QStyleOpti
edit->setAttribute(Qt::WA_MacSmallSize);
edit->setFocusPolicy(Qt::StrongFocus);
edit->setAutoFillBackground(true);
for (const QString &s : qAsConst(data.values))
for (const QString &s : std::as_const(data.values))
edit->addItem(s);
return edit;
} else if (data.type == ConfigModel::DataItem::BOOLEAN) {