Modernize std::sort with ranges

This commit is contained in:
mitaclaw 2024-09-29 11:19:05 -07:00
parent bcaf665d14
commit ebf7cebc32
5 changed files with 13 additions and 14 deletions

View File

@ -97,7 +97,7 @@ std::vector<std::string> DoFileSearch(const std::vector<std::string>& directorie
// Remove duplicates (occurring because caller gave e.g. duplicate or overlapping directories -
// not because std::filesystem returns duplicates). Also note that this pathname-based uniqueness
// isn't as thorough as std::filesystem::equivalent.
std::sort(result.begin(), result.end());
std::ranges::sort(result);
result.erase(std::unique(result.begin(), result.end()), result.end());
// Dolphin expects to be able to use "/" (DIR_SEP) everywhere.

View File

@ -624,16 +624,15 @@ void DirectoryBlobReader::SetWiiRegionData(const std::vector<u8>& wii_region_dat
void DirectoryBlobReader::SetPartitions(std::vector<PartitionWithType>&& partitions)
{
std::sort(partitions.begin(), partitions.end(),
[](const PartitionWithType& lhs, const PartitionWithType& rhs) {
if (lhs.type == rhs.type)
return lhs.partition.GetRootDirectory() < rhs.partition.GetRootDirectory();
std::ranges::sort(partitions, [](const PartitionWithType& lhs, const PartitionWithType& rhs) {
if (lhs.type == rhs.type)
return lhs.partition.GetRootDirectory() < rhs.partition.GetRootDirectory();
// Ascending sort by partition type, except Update (1) comes before before Game (0)
return (lhs.type > PartitionType::Update || rhs.type > PartitionType::Update) ?
lhs.type < rhs.type :
lhs.type > rhs.type;
});
// Ascending sort by partition type, except Update (1) comes before before Game (0)
return (lhs.type > PartitionType::Update || rhs.type > PartitionType::Update) ?
lhs.type < rhs.type :
lhs.type > rhs.type;
});
u32 subtable_1_size = 0;
while (subtable_1_size < partitions.size() && subtable_1_size < 3 &&

View File

@ -481,7 +481,7 @@ void WatchWidget::DeleteSelectedWatches()
}
// Sort greatest to smallest, so we don't stomp on existing indices
std::sort(row_indices.begin(), row_indices.end(), std::greater{});
std::ranges::sort(row_indices, std::ranges::greater{});
for (const int row : row_indices)
{
DeleteWatch(guard, row);

View File

@ -101,7 +101,7 @@ BuildExpression(const std::vector<ciface::Core::DeviceContainer::InputDetection>
}
else
{
std::sort(alternation.begin(), alternation.end());
std::ranges::sort(alternation);
alternations.push_back(fmt::to_string(fmt::join(alternation, "&")));
}
};
@ -128,7 +128,7 @@ BuildExpression(const std::vector<ciface::Core::DeviceContainer::InputDetection>
handle_release();
// Remove duplicates
std::sort(alternations.begin(), alternations.end());
std::ranges::sort(alternations);
alternations.erase(std::unique(alternations.begin(), alternations.end()), alternations.end());
return fmt::to_string(fmt::join(alternations, "|"));

View File

@ -151,7 +151,7 @@ ScissorResult::ScissorResult(const BPMemory& bpmemory, std::pair<float, float> v
}
auto cmp = [&](const ScissorRect& lhs, const ScissorRect& rhs) { return IsWorse(lhs, rhs); };
std::sort(m_result.begin(), m_result.end(), cmp);
std::ranges::sort(m_result, cmp);
}
ScissorRect ScissorResult::Best() const