refactor: use std ranges functions where applicable

This commit is contained in:
Jan
2024-03-24 20:49:15 +01:00
parent 132cccb971
commit 239001e6f2
42 changed files with 251 additions and 295 deletions

View File

@ -981,7 +981,7 @@ void DefinesStreamProxy::ProcessNestedMacros(ParserLine& line, unsigned& linePos
const Define* nestedMacro = nullptr;
while (FindNextMacro(input, pos, defineStart, nestedMacro))
{
if (std::find(callstack.cbegin(), callstack.cend(), nestedMacro) != callstack.cend())
if (std::ranges::find(std::as_const(callstack), nestedMacro) != callstack.cend())
{
// Do not expand recursively
continue;

View File

@ -283,18 +283,16 @@ std::unique_ptr<SimpleExpressionMatchers::matcher_t> SimpleExpressionMatchers::P
}
}
const auto hasAddOperation = std::any_of(enabledBinaryOperations.begin(),
enabledBinaryOperations.end(),
[](const SimpleExpressionBinaryOperationType* type)
{
return type == &SimpleExpressionBinaryOperationType::OPERATION_ADD;
});
const auto hasSubtractOperation = std::any_of(enabledBinaryOperations.begin(),
enabledBinaryOperations.end(),
[](const SimpleExpressionBinaryOperationType* type)
{
return type == &SimpleExpressionBinaryOperationType::OPERATION_SUBTRACT;
});
const auto hasAddOperation = std::ranges::any_of(enabledBinaryOperations,
[](const SimpleExpressionBinaryOperationType* type)
{
return type == &SimpleExpressionBinaryOperationType::OPERATION_ADD;
});
const auto hasSubtractOperation = std::ranges::any_of(enabledBinaryOperations,
[](const SimpleExpressionBinaryOperationType* type)
{
return type == &SimpleExpressionBinaryOperationType::OPERATION_SUBTRACT;
});
if (hasAddOperation && hasSubtractOperation)
{

View File

@ -8,7 +8,7 @@ SimpleMatcherAnyCharacterBesides::SimpleMatcherAnyCharacterBesides(std::vector<c
MatcherResult<SimpleParserValue> SimpleMatcherAnyCharacterBesides::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
{
const auto& token = lexer->GetToken(tokenOffset);
return token.m_type == SimpleParserValueType::CHARACTER && std::find(m_chars.begin(), m_chars.end(), token.CharacterValue()) == m_chars.end()
return token.m_type == SimpleParserValueType::CHARACTER && std::ranges::find(m_chars, token.CharacterValue()) == m_chars.end()
? MatcherResult<SimpleParserValue>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch();
}

View File

@ -17,14 +17,12 @@ MatcherResult<SimpleParserValue> SimpleMatcherKeywordIgnoreCase::CanMatch(ILexer
return MatcherResult<SimpleParserValue>::NoMatch();
const auto& identifierValue = token.IdentifierValue();
const auto isEqual = std::equal(identifierValue.begin(),
identifierValue.end(),
m_value.begin(),
m_value.end(),
[](const char a, const char b)
{
return tolower(a) == b;
});
const auto isEqual = std::ranges::equal(identifierValue,
m_value,
[](const char a, const char b)
{
return tolower(a) == b;
});
if (isEqual)
return MatcherResult<SimpleParserValue>::Match(1);