From 8b9f92a0af0f467ffa0bde5f4e6239e57fbd4b5e Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Sun, 29 Sep 2024 11:19:33 -0700 Subject: Modernize `std::sort` with ranges and projections In PPCTables.cpp, the code is currently unused so I was unable to test it. In CustomPipeline.cpp, a pointer to member function cannot be used due to 16.4.5.2.1 of the C++ Standard regarding "addressable functions". https://eel.is/c++draft/namespace.std#6 In Fs.cpp and DirectoryBlob.cpp, these examples used projections in a previous iteration of this commit, but no longer do. Still, they remain in this commit because the PR they would actually belong to is already merged. --- Source/Core/DiscIO/DirectoryBlob.cpp | 16 +++++++--------- Source/Core/DiscIO/VolumeVerifier.cpp | 3 +-- Source/Core/DiscIO/WIABlob.cpp | 3 +-- 3 files changed, 9 insertions(+), 13 deletions(-) (limited to 'Source/Core/DiscIO') diff --git a/Source/Core/DiscIO/DirectoryBlob.cpp b/Source/Core/DiscIO/DirectoryBlob.cpp index 5d080afe1d..442c8ae851 100644 --- a/Source/Core/DiscIO/DirectoryBlob.cpp +++ b/Source/Core/DiscIO/DirectoryBlob.cpp @@ -1192,15 +1192,13 @@ void DirectoryBlobPartition::WriteDirectory(std::vector* fst_data, std::vector& sorted_entries = *parent_entries; // Sort for determinism - std::sort(sorted_entries.begin(), sorted_entries.end(), - [](const FSTBuilderNode& one, const FSTBuilderNode& two) { - std::string one_upper = one.m_filename; - std::string two_upper = two.m_filename; - Common::ToUpper(&one_upper); - Common::ToUpper(&two_upper); - return one_upper == two_upper ? one.m_filename < two.m_filename : - one_upper < two_upper; - }); + std::ranges::sort(sorted_entries, [](const FSTBuilderNode& one, const FSTBuilderNode& two) { + std::string one_upper = one.m_filename; + std::string two_upper = two.m_filename; + Common::ToUpper(&one_upper); + Common::ToUpper(&two_upper); + return one_upper == two_upper ? one.m_filename < two.m_filename : one_upper < two_upper; + }); for (FSTBuilderNode& entry : sorted_entries) { diff --git a/Source/Core/DiscIO/VolumeVerifier.cpp b/Source/Core/DiscIO/VolumeVerifier.cpp index 18ef37102e..dc67760ce2 100644 --- a/Source/Core/DiscIO/VolumeVerifier.cpp +++ b/Source/Core/DiscIO/VolumeVerifier.cpp @@ -1053,8 +1053,7 @@ void VolumeVerifier::SetUpHashing() m_scrubber.SetupScrub(m_volume); } - std::sort(m_groups.begin(), m_groups.end(), - [](const GroupToVerify& a, const GroupToVerify& b) { return a.offset < b.offset; }); + std::ranges::sort(m_groups, {}, &GroupToVerify::offset); if (m_hashes_to_calculate.crc32) m_crc32_context = Common::StartCRC32(); diff --git a/Source/Core/DiscIO/WIABlob.cpp b/Source/Core/DiscIO/WIABlob.cpp index c59802c947..3f91a606aa 100644 --- a/Source/Core/DiscIO/WIABlob.cpp +++ b/Source/Core/DiscIO/WIABlob.cpp @@ -941,8 +941,7 @@ ConversionResultCode WIARVZFileReader::SetUpDataEntriesForWriting( if (volume && volume->HasWiiHashes() && volume->HasWiiEncryption()) partitions = volume->GetPartitions(); - std::sort(partitions.begin(), partitions.end(), - [](const Partition& a, const Partition& b) { return a.offset < b.offset; }); + std::ranges::sort(partitions, {}, &Partition::offset); *total_groups = 0; -- cgit v1.2.3