Use structured bindings (C++17 feature)

This commit is contained in:
Mat Sutcliffe
2021-04-17 16:31:39 +01:00
parent 9964f44d25
commit 22301c1a1f
6 changed files with 18 additions and 23 deletions

View File

@@ -1871,10 +1871,10 @@ namespace BlackCore
}
if (callStatistics.isEmpty()) { return QString(); }
for (const auto pair : makePairsRange(as_const(callStatistics)))
for (const auto [key, value] : makePairsRange(as_const(callStatistics)))
{
// key is pair.first, value is pair.second
transformed.push_back({ pair.second, pair.first });
transformed.push_back({ value, key });
}
// sorted by value

View File

@@ -178,10 +178,8 @@ namespace BlackCore
}
QSet<QString> newActiveActions;
for (const auto pair : makePairsRange(as_const(m_configuredActions)))
for (const auto [combination, action] : makePairsRange(as_const(m_configuredActions)))
{
const CHotkeyCombination &combination = pair.first;
const QString &action = pair.second;
if (combination.isSubsetOf(currentCombination))
{
newActiveActions.insert(action);

View File

@@ -420,19 +420,18 @@ namespace BlackGui
{
ui->cb_OtherVersions->clear();
const QMap<QString, CApplicationInfo> otherVersions = CApplicationInfoList::currentApplicationDataDirectoryMapWithoutCurrentVersion();
for (const auto pair : makePairsRange(otherVersions))
for (const auto [dir, info] : makePairsRange(otherVersions))
{
const CApplicationInfo &info(pair.second);
if (info.isNull())
{
const QString infoString = CDirectoryUtils::decodeNormalizedDirectory(pair.first);
const QString infoString = CDirectoryUtils::decodeNormalizedDirectory(dir);
ui->cb_OtherVersions->addItem(infoString);
}
else
{
ui->cb_OtherVersions->addItem(QStringLiteral("swift %1 (%2)").arg(info.getVersionString(), info.getPlatform()));
}
m_otherVersionDirs.push_back(pair.first);
m_otherVersionDirs.push_back(dir);
}
}

View File

@@ -566,11 +566,11 @@ namespace BlackMisc
{
const QMap<QString, int> modelStrings = this->countPerModelString();
CAircraftModelList duplicates;
for (const auto pair : makePairsRange(modelStrings))
for (const auto [string, count] : makePairsRange(modelStrings))
{
if (pair.second > 1)
if (count > 1)
{
duplicates.push_back(this->findByModelString(pair.first, Qt::CaseInsensitive));
duplicates.push_back(this->findByModelString(string, Qt::CaseInsensitive));
}
}
return duplicates;

View File

@@ -53,15 +53,14 @@ namespace BlackMisc
// used simple string JSON generation as it is faster
QString json;
for (const auto pair : makePairsRange(m_modelStringVsCG))
for (const auto [string, cg] : makePairsRange(m_modelStringVsCG))
{
json += QStringLiteral("{ \"type\": \"cg\", \"modelstring\": \"%1\", \"cgft\": %2 },\n").arg(pair.first, pair.second.valueRoundedAsString(CLengthUnit::ft(), 1));
json += QStringLiteral("{ \"type\": \"cg\", \"modelstring\": \"%1\", \"cgft\": %2 },\n").arg(string, cg.valueRoundedAsString(CLengthUnit::ft(), 1));
}
for (const auto pair : makePairsRange(m_modelStringVsSimulatorInfo))
for (const auto [string, sim] : makePairsRange(m_modelStringVsSimulatorInfo))
{
const QString sim = pair.second.toQString(false);
json += QStringLiteral("{ \"type\": \"simulatorupdate\", \"modelstring\": \"%1\", \"simulator\": \"%2\" },\n").arg(pair.first, sim);
json += QStringLiteral("{ \"type\": \"simulatorupdate\", \"modelstring\": \"%1\", \"simulator\": \"%2\" },\n").arg(string, sim.toQString(false));
}
if (json.isEmpty()) { return {}; }

View File

@@ -61,9 +61,9 @@ namespace BlackMisc
{
const SetupsPerCallsign setups = this->getSetupsPerCallsign();
CCallsignSet callsigns;
for (const auto pair : makePairsRange(setups))
for (const auto [callsign, setup] : makePairsRange(setups))
{
if (pair.second.logInterpolation()) { callsigns.insert(pair.first); }
if (setup.logInterpolation()) { callsigns.insert(callsign); }
}
return callsigns;
}
@@ -145,19 +145,18 @@ namespace BlackMisc
void IInterpolationSetupProvider::clearInterpolationLogCallsigns()
{
const SetupsPerCallsign setupsCopy = this->getSetupsPerCallsign();
SetupsPerCallsign setupsCopy = this->getSetupsPerCallsign();
if (setupsCopy.isEmpty()) { return; }
// potential risk, changes inbetween in another thread are missed now
// on the other side, we keep locks for a minimal time frame
SetupsPerCallsign setupsToKeep;
CInterpolationAndRenderingSetupGlobal global = this->getInterpolationSetupGlobal();
for (const auto pair : makePairsRange(setupsCopy))
for (auto [callsign, setup] : makePairsRange(setupsCopy))
{
CInterpolationAndRenderingSetupPerCallsign setup = pair.second;
setup.setLogInterpolation(false);
if (setup.isEqualToGlobal(global)) { continue; }
setupsToKeep.insert(pair.first, setup);
setupsToKeep.insert(callsign, setup);
}
{
QWriteLocker l(&m_lockSetup);