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
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
42 changed files with 251 additions and 295 deletions

View File

@ -25,7 +25,7 @@ void GameIW3::AddZone(Zone* zone)
void GameIW3::RemoveZone(Zone* zone) void GameIW3::RemoveZone(Zone* zone)
{ {
const auto foundEntry = std::find(m_zones.begin(), m_zones.end(), zone); const auto foundEntry = std::ranges::find(m_zones, zone);
if (foundEntry != m_zones.end()) if (foundEntry != m_zones.end())
m_zones.erase(foundEntry); m_zones.erase(foundEntry);

View File

@ -25,7 +25,7 @@ void GameIW4::AddZone(Zone* zone)
void GameIW4::RemoveZone(Zone* zone) void GameIW4::RemoveZone(Zone* zone)
{ {
const auto foundEntry = std::find(m_zones.begin(), m_zones.end(), zone); const auto foundEntry = std::ranges::find(m_zones, zone);
if (foundEntry != m_zones.end()) if (foundEntry != m_zones.end())
m_zones.erase(foundEntry); m_zones.erase(foundEntry);

View File

@ -25,7 +25,7 @@ void GameIW5::AddZone(Zone* zone)
void GameIW5::RemoveZone(Zone* zone) void GameIW5::RemoveZone(Zone* zone)
{ {
const auto foundEntry = std::find(m_zones.begin(), m_zones.end(), zone); const auto foundEntry = std::ranges::find(m_zones, zone);
if (foundEntry != m_zones.end()) if (foundEntry != m_zones.end())
m_zones.erase(foundEntry); m_zones.erase(foundEntry);

View File

@ -25,7 +25,7 @@ void GameT5::AddZone(Zone* zone)
void GameT5::RemoveZone(Zone* zone) void GameT5::RemoveZone(Zone* zone)
{ {
const auto foundEntry = std::find(m_zones.begin(), m_zones.end(), zone); const auto foundEntry = std::ranges::find(m_zones, zone);
if (foundEntry != m_zones.end()) if (foundEntry != m_zones.end())
m_zones.erase(foundEntry); m_zones.erase(foundEntry);

View File

@ -25,7 +25,7 @@ void GameT6::AddZone(Zone* zone)
void GameT6::RemoveZone(Zone* zone) void GameT6::RemoveZone(Zone* zone)
{ {
const auto foundEntry = std::find(m_zones.begin(), m_zones.end(), zone); const auto foundEntry = std::ranges::find(m_zones, zone);
if (foundEntry != m_zones.end()) if (foundEntry != m_zones.end())
m_zones.erase(foundEntry); m_zones.erase(foundEntry);

View File

@ -37,12 +37,11 @@ namespace state_map
for (auto& resultVar : entry.m_result_vars) for (auto& resultVar : entry.m_result_vars)
{ {
const auto correspondingVar = std::find_if(layout.m_var_layout.m_vars.begin(), const auto correspondingVar = std::ranges::find_if(layout.m_var_layout.m_vars,
layout.m_var_layout.m_vars.end(), [&resultVar](const StateMapLayoutVar& var)
[&resultVar](const StateMapLayoutVar& var) {
{ return var.m_name == resultVar;
return var.m_name == resultVar; });
});
// Has to have a corresponding var // Has to have a corresponding var
assert(correspondingVar != layout.m_var_layout.m_vars.end()); assert(correspondingVar != layout.m_var_layout.m_vars.end());

View File

@ -467,19 +467,18 @@ class LinkerImpl final : public Linker
bool BuildReferencedTargets(const std::string& projectName, const std::string& targetName, const ZoneDefinition& zoneDefinition) bool BuildReferencedTargets(const std::string& projectName, const std::string& targetName, const ZoneDefinition& zoneDefinition)
{ {
return std::all_of(zoneDefinition.m_targets_to_build.begin(), return std::ranges::all_of(zoneDefinition.m_targets_to_build,
zoneDefinition.m_targets_to_build.end(), [this, &projectName, &targetName](const std::string& buildTargetName)
[this, &projectName, &targetName](const std::string& buildTargetName) {
{ if (buildTargetName == targetName)
if (buildTargetName == targetName) {
{ std::cerr << "Cannot build target with same name: \"" << targetName << "\"\n";
std::cerr << "Cannot build target with same name: \"" << targetName << "\"\n"; return false;
return false; }
}
std::cout << "Building referenced target \"" << buildTargetName << "\"\n"; std::cout << "Building referenced target \"" << buildTargetName << "\"\n";
return BuildProject(projectName, buildTargetName); return BuildProject(projectName, buildTargetName);
}); });
} }
bool BuildProject(const std::string& projectName, const std::string& targetName) bool BuildProject(const std::string& projectName, const std::string& targetName)

View File

@ -60,20 +60,18 @@ uint32_t CommonStructuredDataEnum::CalculateChecksum(const uint32_t initialValue
void CommonStructuredDataEnum::SortEntriesByOffset() void CommonStructuredDataEnum::SortEntriesByOffset()
{ {
std::sort(m_entries.begin(), std::ranges::sort(m_entries,
m_entries.end(), [](const CommonStructuredDataEnumEntry& e1, const CommonStructuredDataEnumEntry& e2)
[](const CommonStructuredDataEnumEntry& e1, const CommonStructuredDataEnumEntry& e2) {
{ return e1.m_value < e2.m_value;
return e1.m_value < e2.m_value; });
});
} }
void CommonStructuredDataEnum::SortEntriesByName() void CommonStructuredDataEnum::SortEntriesByName()
{ {
std::sort(m_entries.begin(), std::ranges::sort(m_entries,
m_entries.end(), [](const CommonStructuredDataEnumEntry& e1, const CommonStructuredDataEnumEntry& e2)
[](const CommonStructuredDataEnumEntry& e1, const CommonStructuredDataEnumEntry& e2) {
{ return e1.m_name < e2.m_name;
return e1.m_name < e2.m_name; });
});
} }

View File

@ -118,20 +118,18 @@ uint32_t CommonStructuredDataStruct::CalculateChecksum(const CommonStructuredDat
void CommonStructuredDataStruct::SortPropertiesByOffset() void CommonStructuredDataStruct::SortPropertiesByOffset()
{ {
std::sort(m_properties.begin(), std::ranges::sort(m_properties,
m_properties.end(), [](const CommonStructuredDataStructProperty& e1, const CommonStructuredDataStructProperty& e2)
[](const CommonStructuredDataStructProperty& e1, const CommonStructuredDataStructProperty& e2) {
{ return e1.m_offset_in_bits < e2.m_offset_in_bits;
return e1.m_offset_in_bits < e2.m_offset_in_bits; });
});
} }
void CommonStructuredDataStruct::SortPropertiesByName() void CommonStructuredDataStruct::SortPropertiesByName()
{ {
std::sort(m_properties.begin(), std::ranges::sort(m_properties,
m_properties.end(), [](const CommonStructuredDataStructProperty& e1, const CommonStructuredDataStructProperty& e2)
[](const CommonStructuredDataStructProperty& e1, const CommonStructuredDataStructProperty& e2) {
{ return e1.m_name < e2.m_name;
return e1.m_name < e2.m_name; });
});
} }

View File

@ -844,13 +844,12 @@ namespace IW4
if (techsetDefinition->GetTechniqueByIndex(i, techniqueName)) if (techsetDefinition->GetTechniqueByIndex(i, techniqueName))
{ {
const auto stateBitsForTechnique = GetStateBitsForTechnique(techniqueName); const auto stateBitsForTechnique = GetStateBitsForTechnique(techniqueName);
const auto foundStateBits = const auto foundStateBits = std::ranges::find_if(m_state_bits,
std::find_if(m_state_bits.begin(), [stateBitsForTechnique](const GfxStateBits& s1)
m_state_bits.end(), {
[stateBitsForTechnique](const GfxStateBits& s1) return s1.loadBits[0] == stateBitsForTechnique.loadBits[0]
{ && s1.loadBits[1] == stateBitsForTechnique.loadBits[1];
return s1.loadBits[0] == stateBitsForTechnique.loadBits[0] && s1.loadBits[1] == stateBitsForTechnique.loadBits[1]; });
});
if (foundStateBits != m_state_bits.end()) if (foundStateBits != m_state_bits.end())
{ {

View File

@ -403,22 +403,21 @@ namespace IW4
return false; return false;
// Sort args by their update frequency // Sort args by their update frequency
std::sort(pass.m_arguments.begin(), std::ranges::sort(pass.m_arguments,
pass.m_arguments.end(), [](const PassShaderArgument& arg1, const PassShaderArgument& arg2)
[](const PassShaderArgument& arg1, const PassShaderArgument& arg2) {
{ if (arg1.m_update_frequency != arg2.m_update_frequency)
if (arg1.m_update_frequency != arg2.m_update_frequency) return arg1.m_update_frequency < arg2.m_update_frequency;
return arg1.m_update_frequency < arg2.m_update_frequency;
if (arg1.m_arg.type != arg2.m_arg.type) if (arg1.m_arg.type != arg2.m_arg.type)
return arg1.m_arg.type < arg2.m_arg.type; return arg1.m_arg.type < arg2.m_arg.type;
if (arg1.m_arg.type == MTL_ARG_MATERIAL_VERTEX_CONST || arg1.m_arg.type == MTL_ARG_MATERIAL_PIXEL_CONST if (arg1.m_arg.type == MTL_ARG_MATERIAL_VERTEX_CONST || arg1.m_arg.type == MTL_ARG_MATERIAL_PIXEL_CONST
|| arg1.m_arg.type == MTL_ARG_MATERIAL_PIXEL_SAMPLER) || arg1.m_arg.type == MTL_ARG_MATERIAL_PIXEL_SAMPLER)
return arg1.m_arg.u.codeSampler < arg2.m_arg.u.codeSampler; return arg1.m_arg.u.codeSampler < arg2.m_arg.u.codeSampler;
return arg1.m_arg.dest < arg2.m_arg.dest; return arg1.m_arg.dest < arg2.m_arg.dest;
}); });
AllocateVertexDecl(); AllocateVertexDecl();
@ -600,12 +599,11 @@ namespace IW4
size_t& registerOffset, size_t& registerOffset,
std::string& errorMessage) const std::string& errorMessage) const
{ {
const auto matchingShaderConstant = std::find_if(shaderInfo.m_constants.begin(), const auto matchingShaderConstant = std::ranges::find_if(shaderInfo.m_constants,
shaderInfo.m_constants.end(), [argument](const d3d9::ShaderConstant& constant)
[argument](const d3d9::ShaderConstant& constant) {
{ return constant.m_name == argument.m_argument_name;
return constant.m_name == argument.m_argument_name; });
});
if (matchingShaderConstant == shaderInfo.m_constants.end()) if (matchingShaderConstant == shaderInfo.m_constants.end())
{ {
@ -1013,14 +1011,14 @@ namespace IW4
return false; return false;
} }
const auto foundDestination = std::find(std::begin(materialStreamDestinationNames), std::end(materialStreamDestinationNames), destination); const auto foundDestination = std::ranges::find(materialStreamDestinationNames, destination);
if (foundDestination == std::end(materialStreamDestinationNames)) if (foundDestination == std::end(materialStreamDestinationNames))
{ {
errorMessage = "Unknown stream destination"; errorMessage = "Unknown stream destination";
return false; return false;
} }
const auto foundSource = std::find(std::begin(materialStreamSourceNames), std::end(materialStreamSourceNames), source); const auto foundSource = std::ranges::find(materialStreamSourceNames, source);
if (foundSource == std::end(materialStreamSourceNames)) if (foundSource == std::end(materialStreamSourceNames))
{ {
errorMessage = "Unknown stream source"; errorMessage = "Unknown stream source";
@ -1187,7 +1185,7 @@ namespace IW4
assert(arg.m_arg.type == MTL_ARG_CODE_PIXEL_SAMPLER); assert(arg.m_arg.type == MTL_ARG_CODE_PIXEL_SAMPLER);
if (arg.m_arg.type == MTL_ARG_CODE_PIXEL_SAMPLER) if (arg.m_arg.type == MTL_ARG_CODE_PIXEL_SAMPLER)
{ {
const auto customSampler = std::find(std::begin(g_customSamplerSrc), std::end(g_customSamplerSrc), arg.m_arg.u.codeSampler); const auto customSampler = std::ranges::find(g_customSamplerSrc, arg.m_arg.u.codeSampler);
assert(customSampler != std::end(g_customSamplerSrc)); assert(customSampler != std::end(g_customSamplerSrc));
if (customSampler != std::end(g_customSamplerSrc)) if (customSampler != std::end(g_customSamplerSrc))
{ {

View File

@ -64,16 +64,14 @@ bool AssetLoaderVertexDecl::LoadFromRaw(
return false; return false;
} }
const auto foundSourceAbbreviation = const auto foundSourceAbbreviation = std::ranges::find(materialStreamSourceAbbreviation, sourceAbbreviation);
std::find(std::begin(materialStreamSourceAbbreviation), std::end(materialStreamSourceAbbreviation), sourceAbbreviation);
if (foundSourceAbbreviation == std::end(materialStreamSourceAbbreviation)) if (foundSourceAbbreviation == std::end(materialStreamSourceAbbreviation))
{ {
std::cout << "Unknown vertex decl source abbreviation: " << sourceAbbreviation << "\n"; std::cout << "Unknown vertex decl source abbreviation: " << sourceAbbreviation << "\n";
return false; return false;
} }
const auto foundDestinationAbbreviation = const auto foundDestinationAbbreviation = std::ranges::find(materialStreamDestinationAbbreviation, destinationAbbreviation);
std::find(std::begin(materialStreamDestinationAbbreviation), std::end(materialStreamDestinationAbbreviation), destinationAbbreviation);
if (foundDestinationAbbreviation == std::end(materialStreamDestinationAbbreviation)) if (foundDestinationAbbreviation == std::end(materialStreamDestinationAbbreviation))
{ {
std::cout << "Unknown vertex decl destination abbreviation: " << destinationAbbreviation << "\n"; std::cout << "Unknown vertex decl destination abbreviation: " << destinationAbbreviation << "\n";

View File

@ -48,12 +48,11 @@ void AssetLoaderFontIcon::PreprocessRow(std::vector<std::string>& row)
bool AssetLoaderFontIcon::RowIsEmpty(const std::vector<std::string>& row) bool AssetLoaderFontIcon::RowIsEmpty(const std::vector<std::string>& row)
{ {
return std::all_of(row.begin(), return std::ranges::all_of(row,
row.end(), [](const std::string& cell)
[](const std::string& cell) {
{ return cell.empty();
return cell.empty(); });
});
} }
bool AssetLoaderFontIcon::ParseInt(int& value, const std::string& str) bool AssetLoaderFontIcon::ParseInt(int& value, const std::string& str)

View File

@ -27,7 +27,7 @@ namespace
{ {
std::string soundFilePath(sndAlias->assetFileName); std::string soundFilePath(sndAlias->assetFileName);
std::replace(soundFilePath.begin(), soundFilePath.end(), '\\', '/'); std::ranges::replace(soundFilePath, '\\', '/');
for (const auto& droppedPrefix : PREFIXES_TO_DROP) for (const auto& droppedPrefix : PREFIXES_TO_DROP)
{ {
if (soundFilePath.rfind(droppedPrefix, 0) != std::string::npos) if (soundFilePath.rfind(droppedPrefix, 0) != std::string::npos)

View File

@ -56,12 +56,11 @@ class IPak::Impl : public ObjContainerReferenceable
m_index_entries.push_back(indexEntry); m_index_entries.push_back(indexEntry);
} }
std::sort(m_index_entries.begin(), std::ranges::sort(m_index_entries,
m_index_entries.end(), [](const IPakIndexEntry& entry1, const IPakIndexEntry& entry2)
[](const IPakIndexEntry& entry1, const IPakIndexEntry& entry2) {
{ return entry1.key.combinedKey < entry2.key.combinedKey;
return entry1.key.combinedKey < entry2.key.combinedKey; });
});
return true; return true;
} }

View File

@ -71,12 +71,11 @@ public:
m_stream_mutex.lock(); m_stream_mutex.lock();
ChunkBuffer* reservedChunkBuffer; ChunkBuffer* reservedChunkBuffer;
const auto freeChunkBuffer = std::find_if(m_chunk_buffers.begin(), const auto freeChunkBuffer = std::ranges::find_if(m_chunk_buffers,
m_chunk_buffers.end(), [](ChunkBuffer* chunkBuffer)
[](ChunkBuffer* chunkBuffer) {
{ return chunkBuffer->m_using_stream == nullptr;
return chunkBuffer->m_using_stream == nullptr; });
});
if (freeChunkBuffer == m_chunk_buffers.end()) if (freeChunkBuffer == m_chunk_buffers.end())
{ {
@ -111,12 +110,11 @@ public:
{ {
m_stream_mutex.lock(); m_stream_mutex.lock();
const auto openStreamEntry = std::find_if(m_open_streams.begin(), const auto openStreamEntry = std::ranges::find_if(m_open_streams,
m_open_streams.end(), [stream](const ManagedStream& managedStream)
[stream](const ManagedStream& managedStream) {
{ return managedStream.m_stream == stream;
return managedStream.m_stream == stream; });
});
if (openStreamEntry != m_open_streams.end()) if (openStreamEntry != m_open_streams.end())
{ {
@ -127,7 +125,7 @@ public:
// Only keep previously allocated chunk buffer if we did not get over the limit of idle chunk buffers // Only keep previously allocated chunk buffer if we did not get over the limit of idle chunk buffers
if (m_chunk_buffers.size() > CHUNK_BUFFER_COUNT_IDLE_LIMIT) if (m_chunk_buffers.size() > CHUNK_BUFFER_COUNT_IDLE_LIMIT)
{ {
const auto chunkBufferEntry = std::find(m_chunk_buffers.begin(), m_chunk_buffers.end(), chunkBuffer); const auto chunkBufferEntry = std::ranges::find(m_chunk_buffers, chunkBuffer);
if (chunkBufferEntry != m_chunk_buffers.end()) if (chunkBufferEntry != m_chunk_buffers.end())
{ {

View File

@ -248,7 +248,7 @@ public:
} }
auto iwdFilename = fileName; auto iwdFilename = fileName;
std::replace(iwdFilename.begin(), iwdFilename.end(), '\\', '/'); std::ranges::replace(iwdFilename, '\\', '/');
const auto iwdEntry = m_entry_map.find(iwdFilename); const auto iwdEntry = m_entry_map.find(iwdFilename);

View File

@ -46,12 +46,11 @@ public:
void AddSound(const std::string& soundFilePath, unsigned int soundId, bool looping, bool streamed) override void AddSound(const std::string& soundFilePath, unsigned int soundId, bool looping, bool streamed) override
{ {
auto itr = std::find_if(this->m_sounds.begin(), auto itr = std::ranges::find_if(this->m_sounds,
this->m_sounds.end(), [soundId](SoundBankEntryInfo& entry)
[soundId](SoundBankEntryInfo& entry) {
{ return entry.m_sound_id == soundId;
return entry.m_sound_id == soundId; });
});
if (itr == this->m_sounds.end()) if (itr == this->m_sounds.end())
{ {

View File

@ -179,12 +179,11 @@ namespace state_map
const auto tokenValue = const auto tokenValue =
valueToken.m_type == SimpleParserValueType::IDENTIFIER ? valueToken.IdentifierValue() : std::to_string(valueToken.IntegerValue()); valueToken.m_type == SimpleParserValueType::IDENTIFIER ? valueToken.IdentifierValue() : std::to_string(valueToken.IntegerValue());
const auto referencedValue = std::find_if(var.m_values.begin(), const auto referencedValue = std::ranges::find_if(var.m_values,
var.m_values.end(), [&tokenValue](const StateMapLayoutVarValue& value)
[&tokenValue](const StateMapLayoutVarValue& value) {
{ return value.m_name == tokenValue;
return value.m_name == tokenValue; });
});
if (referencedValue == var.m_values.end()) if (referencedValue == var.m_values.end())
throw ParsingException(valueToken.GetPos(), "Not part of the valid values for this var"); throw ParsingException(valueToken.GetPos(), "Not part of the valid values for this var");

View File

@ -40,19 +40,18 @@ void StateMapHandler::ApplyStateMap(const uint32_t* baseStateBits, uint32_t* out
for (auto entryIndex = 0u; entryIndex < m_state_map.m_state_map_entries.size(); entryIndex++) for (auto entryIndex = 0u; entryIndex < m_state_map.m_state_map_entries.size(); entryIndex++)
{ {
const auto& entry = m_state_map.m_state_map_entries[entryIndex]; const auto& entry = m_state_map.m_state_map_entries[entryIndex];
const auto matchingRule = std::find_if(entry.m_rules.begin(), const auto matchingRule = std::ranges::find_if(entry.m_rules,
entry.m_rules.end(), [&vars](const std::unique_ptr<StateMapRule>& rule)
[&vars](const std::unique_ptr<StateMapRule>& rule) {
{ const auto matchingCondition =
const auto matchingCondition = std::find_if(rule->m_conditions.begin(), std::ranges::find_if(rule->m_conditions,
rule->m_conditions.end(), [&vars](std::unique_ptr<ISimpleExpression>& condition)
[&vars](std::unique_ptr<ISimpleExpression>& condition) {
{ return condition->EvaluateNonStatic(&vars).IsTruthy();
return condition->EvaluateNonStatic(&vars).IsTruthy(); });
});
return matchingCondition != rule->m_conditions.end(); return matchingCondition != rule->m_conditions.end();
}); });
if (matchingRule != entry.m_rules.end()) if (matchingRule != entry.m_rules.end())
ApplyRule(m_state_map_layout.m_entry_layout.m_entries[entryIndex], **matchingRule, outStateBits); ApplyRule(m_state_map_layout.m_entry_layout.m_entries[entryIndex], **matchingRule, outStateBits);
@ -68,12 +67,11 @@ StateMapVars StateMapHandler::BuildVars(const uint32_t* baseStateBits) const
for (const auto& var : m_state_map_layout.m_var_layout.m_vars) for (const auto& var : m_state_map_layout.m_var_layout.m_vars)
{ {
const auto baseStateBitField = baseStateBits[var.m_state_bits_index]; const auto baseStateBitField = baseStateBits[var.m_state_bits_index];
const auto matchingValue = std::find_if(var.m_values.begin(), const auto matchingValue = std::ranges::find_if(var.m_values,
var.m_values.end(), [&baseStateBitField](const StateMapLayoutVarValue& value)
[&baseStateBitField](const StateMapLayoutVarValue& value) {
{ return (baseStateBitField & value.m_state_bits_mask) == value.m_state_bits_mask;
return (baseStateBitField & value.m_state_bits_mask) == value.m_state_bits_mask; });
});
if (matchingValue != var.m_values.end()) if (matchingValue != var.m_values.end())
result.AddValue(var.m_name, matchingValue->m_name); result.AddValue(var.m_name, matchingValue->m_name);

View File

@ -126,13 +126,12 @@ namespace IW4
{ {
const auto expectedRegisterSet = const auto expectedRegisterSet =
arg.type == MTL_ARG_CODE_PIXEL_SAMPLER || arg.type == MTL_ARG_MATERIAL_PIXEL_SAMPLER ? d3d9::RegisterSet::SAMPLER : d3d9::RegisterSet::FLOAT_4; arg.type == MTL_ARG_CODE_PIXEL_SAMPLER || arg.type == MTL_ARG_MATERIAL_PIXEL_SAMPLER ? d3d9::RegisterSet::SAMPLER : d3d9::RegisterSet::FLOAT_4;
const auto targetShaderArg = std::find_if(shaderInfo.m_constants.begin(), const auto targetShaderArg = std::ranges::find_if(shaderInfo.m_constants,
shaderInfo.m_constants.end(), [arg, expectedRegisterSet](const d3d9::ShaderConstant& constant)
[arg, expectedRegisterSet](const d3d9::ShaderConstant& constant) {
{ return constant.m_register_set == expectedRegisterSet && constant.m_register_index <= arg.dest
return constant.m_register_set == expectedRegisterSet && constant.m_register_index <= arg.dest && constant.m_register_index + constant.m_register_count > arg.dest;
&& constant.m_register_index + constant.m_register_count > arg.dest; });
});
assert(targetShaderArg != shaderInfo.m_constants.end()); assert(targetShaderArg != shaderInfo.m_constants.end());
if (targetShaderArg == shaderInfo.m_constants.end()) if (targetShaderArg == shaderInfo.m_constants.end())

View File

@ -139,7 +139,7 @@ class AssetDumperSndBank::Internal
{ {
fs::path assetPath(m_context.m_base_path); fs::path assetPath(m_context.m_base_path);
std::replace(outputFileName.begin(), outputFileName.end(), '\\', '/'); std::ranges::replace(outputFileName, '\\', '/');
for (const auto& droppedPrefix : PREFIXES_TO_DROP) for (const auto& droppedPrefix : PREFIXES_TO_DROP)
{ {
if (outputFileName.rfind(droppedPrefix, 0) != std::string::npos) if (outputFileName.rfind(droppedPrefix, 0) != std::string::npos)

View File

@ -115,22 +115,20 @@ bool AbstractMenuDumper::DoesTokenNeedQuotationMarks(const std::string& token)
if (token.empty()) if (token.empty())
return true; return true;
const auto hasAlNumCharacter = std::any_of(token.begin(), const auto hasAlNumCharacter = std::ranges::any_of(token,
token.end(), [](const char& c)
[](const char& c) {
{ return isalnum(c);
return isalnum(c); });
});
if (!hasAlNumCharacter) if (!hasAlNumCharacter)
return false; return false;
const auto hasNonIdentifierCharacter = std::any_of(token.begin(), const auto hasNonIdentifierCharacter = std::ranges::any_of(token,
token.end(), [](const char& c)
[](const char& c) {
{ return !isalnum(c) && c != '_';
return !isalnum(c) && c != '_'; });
});
return hasNonIdentifierCharacter; return hasNonIdentifierCharacter;
} }

View File

@ -291,12 +291,11 @@ public:
m_index_entries.reserve(m_images.size()); m_index_entries.reserve(m_images.size());
const auto result = std::all_of(m_images.begin(), const auto result = std::ranges::all_of(m_images,
m_images.end(), [this](const std::string& imageName)
[this](const std::string& imageName) {
{ return WriteImageData(imageName);
return WriteImageData(imageName); });
});
FlushBlock(); FlushBlock();
m_data_section_size = static_cast<size_t>(m_current_offset - m_data_section_offset); m_data_section_size = static_cast<size_t>(m_current_offset - m_data_section_offset);
@ -311,7 +310,7 @@ public:
void SortIndexSectionEntries() void SortIndexSectionEntries()
{ {
std::sort(m_index_entries.begin(), m_index_entries.end(), CompareIndices); std::ranges::sort(m_index_entries, CompareIndices);
} }
void WriteIndexSection() void WriteIndexSection()

View File

@ -981,7 +981,7 @@ void DefinesStreamProxy::ProcessNestedMacros(ParserLine& line, unsigned& linePos
const Define* nestedMacro = nullptr; const Define* nestedMacro = nullptr;
while (FindNextMacro(input, pos, defineStart, nestedMacro)) 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 // Do not expand recursively
continue; continue;

View File

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

View File

@ -8,7 +8,7 @@ SimpleMatcherAnyCharacterBesides::SimpleMatcherAnyCharacterBesides(std::vector<c
MatcherResult<SimpleParserValue> SimpleMatcherAnyCharacterBesides::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset) MatcherResult<SimpleParserValue> SimpleMatcherAnyCharacterBesides::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
{ {
const auto& token = lexer->GetToken(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>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch(); : MatcherResult<SimpleParserValue>::NoMatch();
} }

View File

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

View File

@ -21,12 +21,11 @@ bool MemberComputations::ShouldIgnore() const
bool MemberComputations::ContainsNonEmbeddedReference() const bool MemberComputations::ContainsNonEmbeddedReference() const
{ {
const auto& declarationModifiers = m_info->m_member->m_type_declaration->m_declaration_modifiers; const auto& declarationModifiers = m_info->m_member->m_type_declaration->m_declaration_modifiers;
return std::any_of(declarationModifiers.begin(), return std::ranges::any_of(declarationModifiers,
declarationModifiers.end(), [](const std::unique_ptr<DeclarationModifier>& modifier)
[](const std::unique_ptr<DeclarationModifier>& modifier) {
{ return modifier->GetType() == DeclarationModifierType::POINTER;
return modifier->GetType() == DeclarationModifierType::POINTER; });
});
} }
bool MemberComputations::ContainsSinglePointerReference() const bool MemberComputations::ContainsSinglePointerReference() const
@ -136,12 +135,11 @@ bool MemberComputations::IsPointerToArray() const
if (lastModifier->GetType() != DeclarationModifierType::ARRAY) if (lastModifier->GetType() != DeclarationModifierType::ARRAY)
return false; return false;
return std::any_of(declarationModifiers.begin(), return std::ranges::any_of(declarationModifiers,
declarationModifiers.end(), [](const std::unique_ptr<DeclarationModifier>& modifier)
[](const std::unique_ptr<DeclarationModifier>& modifier) {
{ return modifier->GetType() == DeclarationModifierType::POINTER;
return modifier->GetType() == DeclarationModifierType::POINTER; });
});
} }
std::vector<int> MemberComputations::GetPointerToArraySizes() const std::vector<int> MemberComputations::GetPointerToArraySizes() const
@ -207,13 +205,12 @@ bool MemberComputations::HasDynamicArraySize() const
{ {
const auto& declarationModifiers = m_info->m_member->m_type_declaration->m_declaration_modifiers; const auto& declarationModifiers = m_info->m_member->m_type_declaration->m_declaration_modifiers;
return std::any_of(declarationModifiers.begin(), return std::ranges::any_of(declarationModifiers,
declarationModifiers.end(), [](const std::unique_ptr<DeclarationModifier>& declarationModifier)
[](const std::unique_ptr<DeclarationModifier>& declarationModifier) {
{ return declarationModifier->GetType() == DeclarationModifierType::ARRAY
return declarationModifier->GetType() == DeclarationModifierType::ARRAY && dynamic_cast<ArrayDeclarationModifier*>(declarationModifier.get())->m_dynamic_size_evaluation;
&& dynamic_cast<ArrayDeclarationModifier*>(declarationModifier.get())->m_dynamic_size_evaluation; });
});
} }
bool MemberComputations::IsDynamicMember() const bool MemberComputations::IsDynamicMember() const

View File

@ -123,7 +123,7 @@ std::vector<DeclarationModifierComputations> DeclarationModifierComputations::Ge
for (auto i = 0; i < arraySize; i++) for (auto i = 0; i < arraySize; i++)
{ {
std::vector<int> childModifierIndices(m_modifier_indices.size() + 1); std::vector<int> childModifierIndices(m_modifier_indices.size() + 1);
std::copy(m_modifier_indices.begin(), m_modifier_indices.end(), childModifierIndices.begin()); std::ranges::copy(m_modifier_indices, childModifierIndices.begin());
childModifierIndices[childModifierIndices.size() - 1] = i; childModifierIndices[childModifierIndices.size() - 1] = i;
arrayEntries.push_back(DeclarationModifierComputations(m_information, std::move(childModifierIndices))); arrayEntries.push_back(DeclarationModifierComputations(m_information, std::move(childModifierIndices)));
} }
@ -140,12 +140,11 @@ bool DeclarationModifierComputations::IsSinglePointer() const
{ {
const auto following = GetFollowingDeclarationModifiers(); const auto following = GetFollowingDeclarationModifiers();
return !std::any_of(following.begin(), return !std::ranges::any_of(following,
following.end(), [](const DeclarationModifier* modifier)
[](const DeclarationModifier* modifier) {
{ return modifier->GetType() == DeclarationModifierType::POINTER;
return modifier->GetType() == DeclarationModifierType::POINTER; });
});
} }
return false; return false;
@ -160,12 +159,11 @@ bool DeclarationModifierComputations::IsArrayPointer() const
{ {
const auto following = GetFollowingDeclarationModifiers(); const auto following = GetFollowingDeclarationModifiers();
return !std::any_of(following.begin(), return !std::ranges::any_of(following,
following.end(), [](const DeclarationModifier* modifier)
[](const DeclarationModifier* modifier) {
{ return modifier->GetType() == DeclarationModifierType::POINTER;
return modifier->GetType() == DeclarationModifierType::POINTER; });
});
} }
return false; return false;
@ -247,12 +245,11 @@ unsigned DeclarationModifierComputations::GetAlignment() const
{ {
const auto following = GetFollowingDeclarationModifiers(); const auto following = GetFollowingDeclarationModifiers();
return std::any_of(following.begin(), return std::ranges::any_of(following,
following.end(), [](const DeclarationModifier* modifier)
[](const DeclarationModifier* modifier) {
{ return modifier->GetType() == DeclarationModifierType::POINTER;
return modifier->GetType() == DeclarationModifierType::POINTER; })
})
? m_information->m_member->GetAlignment() ? m_information->m_member->GetAlignment()
: m_information->m_member->m_type_declaration->m_type->GetAlignment(); : m_information->m_member->m_type_declaration->m_type->GetAlignment();
} }

View File

@ -91,10 +91,9 @@ bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository)
if (!result) if (!result)
return false; return false;
return std::all_of(m_post_processors.begin(), return std::ranges::all_of(m_post_processors,
m_post_processors.end(), [repository](const std::unique_ptr<IPostProcessor>& postProcessor)
[repository](const std::unique_ptr<IPostProcessor>& postProcessor) {
{ return postProcessor->PostProcess(repository);
return postProcessor->PostProcess(repository); });
});
} }

View File

@ -45,12 +45,11 @@ void SequenceAssetRef::ProcessMatch(CommandsParserState* state, SequenceResult<C
if (!hasPointerRef) if (!hasPointerRef)
{ {
const auto& modifiers = typeDecl->m_declaration_modifiers; const auto& modifiers = typeDecl->m_declaration_modifiers;
hasPointerRef = std::any_of(modifiers.begin(), hasPointerRef = std::ranges::any_of(modifiers,
modifiers.end(), [](const std::unique_ptr<DeclarationModifier>& modifier)
[](const std::unique_ptr<DeclarationModifier>& modifier) {
{ return modifier->GetType() == DeclarationModifierType::POINTER;
return modifier->GetType() == DeclarationModifierType::POINTER; });
});
} }
if (typeDecl->m_type->GetType() == DataDefinitionType::TYPEDEF) if (typeDecl->m_type->GetType() == DataDefinitionType::TYPEDEF)

View File

@ -39,12 +39,11 @@ void SequenceString::ProcessMatch(CommandsParserState* state, SequenceResult<Com
if (!hasPointerRef) if (!hasPointerRef)
{ {
const auto& modifiers = typeDecl->m_declaration_modifiers; const auto& modifiers = typeDecl->m_declaration_modifiers;
hasPointerRef = std::any_of(modifiers.begin(), hasPointerRef = std::ranges::any_of(modifiers,
modifiers.end(), [](const std::unique_ptr<DeclarationModifier>& modifier)
[](const std::unique_ptr<DeclarationModifier>& modifier) {
{ return modifier->GetType() == DeclarationModifierType::POINTER;
return modifier->GetType() == DeclarationModifierType::POINTER; });
});
} }
if (typeDecl->m_type->GetType() == DataDefinitionType::TYPEDEF) if (typeDecl->m_type->GetType() == DataDefinitionType::TYPEDEF)

View File

@ -91,10 +91,9 @@ bool HeaderFileReader::ReadHeaderFile(IDataRepository* repository)
if (!result) if (!result)
return false; return false;
return std::all_of(m_post_processors.begin(), return std::ranges::all_of(m_post_processors,
m_post_processors.end(), [repository](const std::unique_ptr<IPostProcessor>& postProcessor)
[repository](const std::unique_ptr<IPostProcessor>& postProcessor) {
{ return postProcessor->PostProcess(repository);
return postProcessor->PostProcess(repository); });
});
} }

View File

@ -29,10 +29,9 @@ bool CreateMemberInformationPostProcessor::PostProcess(IDataRepository* reposito
{ {
const auto& allStructureInformation = repository->GetAllStructureInformation(); const auto& allStructureInformation = repository->GetAllStructureInformation();
return std::all_of(allStructureInformation.begin(), return std::ranges::all_of(allStructureInformation,
allStructureInformation.end(), [this, repository](StructureInformation* structure)
[this, repository](StructureInformation* structure) {
{ return CreateMemberInformationForStructure(repository, structure);
return CreateMemberInformationForStructure(repository, structure); });
});
} }

View File

@ -40,13 +40,12 @@ bool UnionsPostProcessor::PostProcess(IDataRepository* repository)
{ {
const auto& allInfos = repository->GetAllStructureInformation(); const auto& allInfos = repository->GetAllStructureInformation();
return std::all_of(allInfos.begin(), return std::ranges::all_of(allInfos,
allInfos.end(), [](StructureInformation* info)
[](StructureInformation* info) {
{ if (info->m_definition->GetType() != DataDefinitionType::UNION)
if (info->m_definition->GetType() != DataDefinitionType::UNION) return true;
return true;
return ProcessUnion(info); return ProcessUnion(info);
}); });
} }

View File

@ -63,11 +63,10 @@ bool UsagesPostProcessor::PostProcess(IDataRepository* repository)
{ {
const auto& allInfos = repository->GetAllStructureInformation(); const auto& allInfos = repository->GetAllStructureInformation();
return std::all_of(allInfos.begin(), return std::ranges::all_of(allInfos,
allInfos.end(), [](StructureInformation* info)
[](StructureInformation* info) {
{ const StructureComputations computations(info);
const StructureComputations computations(info); return !computations.IsAsset() || ProcessAsset(info);
return !computations.IsAsset() || ProcessAsset(info); });
});
} }

View File

@ -97,12 +97,11 @@ void PrettyPrinter::PrintVariable(Variable* variable) const
else else
{ {
if (declarationModifiers[0]->GetType() == DeclarationModifierType::POINTER if (declarationModifiers[0]->GetType() == DeclarationModifierType::POINTER
&& std::any_of(declarationModifiers.begin(), && std::ranges::any_of(declarationModifiers,
declarationModifiers.end(), [](const std::unique_ptr<DeclarationModifier>& modifier)
[](const std::unique_ptr<DeclarationModifier>& modifier) {
{ return modifier->GetType() == DeclarationModifierType::ARRAY;
return modifier->GetType() == DeclarationModifierType::ARRAY; }))
}))
{ {
PrintVariablePointerToArray(variable); PrintVariablePointerToArray(variable);
} }
@ -262,12 +261,11 @@ void PrettyPrinter::PrintTypedefs() const
else else
{ {
if (declarationModifiers[0]->GetType() == DeclarationModifierType::POINTER if (declarationModifiers[0]->GetType() == DeclarationModifierType::POINTER
&& std::any_of(declarationModifiers.begin(), && std::ranges::any_of(declarationModifiers,
declarationModifiers.end(), [](const std::unique_ptr<DeclarationModifier>& modifier)
[](const std::unique_ptr<DeclarationModifier>& modifier) {
{ return modifier->GetType() == DeclarationModifierType::ARRAY;
return modifier->GetType() == DeclarationModifierType::ARRAY; }))
}))
{ {
PrintTypedefPointerToArray(typedefDefinition); PrintTypedefPointerToArray(typedefDefinition);
} }

View File

@ -82,7 +82,7 @@ std::vector<scr_string_t> AssetMarker::GetUsedScriptStrings() const
for (auto scrString : m_used_script_strings) for (auto scrString : m_used_script_strings)
usedScriptStrings.push_back(scrString); usedScriptStrings.push_back(scrString);
std::sort(usedScriptStrings.begin(), usedScriptStrings.end()); std::ranges::sort(usedScriptStrings);
} }
return usedScriptStrings; return usedScriptStrings;

View File

@ -30,12 +30,11 @@ void ZoneLoader::AddXBlock(std::unique_ptr<XBlock> block)
{ {
m_blocks.push_back(block.get()); m_blocks.push_back(block.get());
std::sort(m_blocks.begin(), std::ranges::sort(m_blocks,
m_blocks.end(), [](XBlock* b1, XBlock* b2) -> bool
[](XBlock* b1, XBlock* b2) -> bool {
{ return b1->m_index < b2->m_index;
return b1->m_index < b2->m_index; });
});
m_zone->GetMemory()->AddBlock(std::move(block)); m_zone->GetMemory()->AddBlock(std::move(block));
} }

View File

@ -61,10 +61,9 @@ bool MockParserLineStream::IsOpen() const
bool MockParserLineStream::Eof() const bool MockParserLineStream::Eof() const
{ {
return !std::any_of(m_include_positions.begin(), return !std::ranges::any_of(m_include_positions,
m_include_positions.end(), [](const IncludePos& pos)
[](const IncludePos& pos) {
{ return pos.m_pos < pos.m_lines.size();
return pos.m_pos < pos.m_lines.size(); });
});
} }

View File

@ -973,7 +973,7 @@ namespace test::parsing::matcher
[](HeaderMatcherFactory::token_list_t& tokens) [](HeaderMatcherFactory::token_list_t& tokens)
{ {
auto str = tokens[0].get().IdentifierValue(); auto str = tokens[0].get().IdentifierValue();
std::transform(str.begin(), str.end(), str.begin(), toupper); std::ranges::transform(str, str.begin(), toupper);
return HeaderParserValue::Identifier(tokens[0].get().GetPos(), new std::string(std::move(str))); return HeaderParserValue::Identifier(tokens[0].get().GetPos(), new std::string(std::move(str)));
}), }),
create.Char('{'), create.Char('{'),