Skip to content

Commit 5b8def6

Browse files
committed
Use stl algorithms
1 parent 990052b commit 5b8def6

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,10 +1938,9 @@ void SymbolDatabase::removeSymbolsForTokens(const std::unordered_set<const Token
19381938
}
19391939

19401940
// remove from the indexes
1941-
for (std::size_t i = 0; i < mVariableList.size(); ++i) {
1942-
if (mVariableList[i] && removedVariables.count(mVariableList[i]) != 0)
1943-
mVariableList[i] = nullptr;
1944-
}
1941+
std::replace_if(mVariableList.begin(), mVariableList.end(), [&](const Variable* var) {
1942+
return var && removedVariables.count(var) != 0;
1943+
}, nullptr);
19451944
functionScopes.erase(std::remove_if(functionScopes.begin(),
19461945
functionScopes.end(),
19471946
[&](const Scope* scope) {
@@ -2036,8 +2035,9 @@ void SymbolDatabase::addSymbolsForNewTokenRanges(const std::vector<std::pair<Tok
20362035
{
20372036
auto it = scopeList.begin();
20382037
std::advance(it, oldScopeCount);
2039-
for (; it != scopeList.end(); ++it)
2040-
newScopes.push_back(&(*it));
2038+
std::transform(it, scopeList.end(), std::back_inserter(newScopes), [](Scope& scope) {
2039+
return &scope;
2040+
});
20412041
}
20422042
std::vector<std::pair<Function*, Scope*>> newFunctions; // the function and the scope it is declared in
20432043
for (Scope& scope : scopeList) {

lib/templatesimplifier.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,12 +1253,10 @@ std::string TemplateSimplifier::deduceFunctionTemplateArguments(
12531253
// Can the deduction succeed later, when type information is available? Scope
12541254
// matching is not possible yet - the declaration may be in a base class - so
12551255
// consider all declarations with this name.
1256-
for (auto pos = range.first; pos != range.second; ++pos) {
1257-
if (deductionCache->supportedParameterCount(*pos->second) == instantiationArgs.size()) {
1258-
mPendingTypeDeductions = true;
1259-
return qualification;
1260-
}
1261-
}
1256+
if (std::any_of(range.first, range.second, [&](const std::pair<const std::string, const TokenAndName*>& entry) {
1257+
return deductionCache->supportedParameterCount(*entry.second) == instantiationArgs.size();
1258+
}))
1259+
mPendingTypeDeductions = true;
12621260
return qualification;
12631261
}
12641262

@@ -4014,8 +4012,9 @@ void TemplateSimplifier::replaceTemplateUsage(
40144012
// remembered new token ranges that start in the erased tokens are gone
40154013
if (!mNewTokenRanges.empty() && !removeTokens.empty()) {
40164014
std::unordered_set<const Token*> rangeStarts;
4017-
for (const auto& range : mNewTokenRanges)
4018-
rangeStarts.insert(range.first);
4015+
std::transform(mNewTokenRanges.cbegin(), mNewTokenRanges.cend(), std::inserter(rangeStarts, rangeStarts.end()), [](const std::pair<Token*, Token*>& range) {
4016+
return range.first;
4017+
});
40194018
std::unordered_set<const Token*> erasedRangeStarts;
40204019
for (const auto& removeToken : removeTokens) {
40214020
for (const Token* tok = removeToken.first->next(); tok && tok != removeToken.second; tok = tok->next()) {

0 commit comments

Comments
 (0)