Merge pull request #13090 from mitaclaw/ranges-modernization-1-trivial

Ranges Algorithms Modernization - Trivial
This commit is contained in:
JosJuice 2024-10-15 17:08:55 +02:00 committed by GitHub
commit 07605bf67c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
52 changed files with 106 additions and 118 deletions

View File

@ -252,8 +252,8 @@ Signature Sign(const u8* key, const u8* hash)
bn_mul(s.data.data(), minv, kk, ec_N, 30); bn_mul(s.data.data(), minv, kk, ec_N, 30);
Signature signature; Signature signature;
std::copy(r.data.cbegin(), r.data.cend(), signature.begin()); std::ranges::copy(r.data, signature.begin());
std::copy(s.data.cbegin(), s.data.cend(), signature.begin() + 30); std::ranges::copy(s.data, signature.begin() + 30);
return signature; return signature;
} }

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 - // 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 // not because std::filesystem returns duplicates). Also note that this pathname-based uniqueness
// isn't as thorough as std::filesystem::equivalent. // 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()); result.erase(std::unique(result.begin(), result.end()), result.end());
// Dolphin expects to be able to use "/" (DIR_SEP) everywhere. // Dolphin expects to be able to use "/" (DIR_SEP) everywhere.
@ -107,7 +107,7 @@ std::vector<std::string> DoFileSearch(const std::vector<std::string>& directorie
if constexpr (os_separator != DIR_SEP_CHR) if constexpr (os_separator != DIR_SEP_CHR)
{ {
for (auto& path : result) for (auto& path : result)
std::replace(path.begin(), path.end(), '\\', DIR_SEP_CHR); std::ranges::replace(path, '\\', DIR_SEP_CHR);
} }
return result; return result;

View File

@ -446,7 +446,7 @@ FSTEntry ScanDirectoryTree(std::string directory, bool recursive)
// about with directory separators (for host paths - emulated paths may require it) and instead // about with directory separators (for host paths - emulated paths may require it) and instead
// use fs::path to interact with them. // use fs::path to interact with them.
auto wpath = path.wstring(); auto wpath = path.wstring();
std::replace(wpath.begin(), wpath.end(), L'\\', L'/'); std::ranges::replace(wpath, L'\\', L'/');
return WStringToUTF8(wpath); return WStringToUTF8(wpath);
#else #else
return PathToString(path); return PathToString(path);

View File

@ -36,10 +36,10 @@ MACAddress GenerateMacAddress(const MACConsumer type)
switch (type) switch (type)
{ {
case MACConsumer::BBA: case MACConsumer::BBA:
std::copy(oui_bba.begin(), oui_bba.end(), mac.begin()); std::ranges::copy(oui_bba, mac.begin());
break; break;
case MACConsumer::IOS: case MACConsumer::IOS:
std::copy(oui_ios.begin(), oui_ios.end(), mac.begin()); std::ranges::copy(oui_ios, mac.begin());
break; break;
} }

View File

@ -234,8 +234,8 @@ std::string_view StripQuotes(std::string_view s)
// Turns "\n\rhello" into " hello". // Turns "\n\rhello" into " hello".
void ReplaceBreaksWithSpaces(std::string& str) void ReplaceBreaksWithSpaces(std::string& str)
{ {
std::replace(str.begin(), str.end(), '\r', ' '); std::ranges::replace(str, '\r', ' ');
std::replace(str.begin(), str.end(), '\n', ' '); std::ranges::replace(str, '\n', ' ');
} }
void TruncateToCString(std::string* s) void TruncateToCString(std::string* s)
@ -403,8 +403,7 @@ void StringPopBackIf(std::string* s, char c)
size_t StringUTF8CodePointCount(std::string_view str) size_t StringUTF8CodePointCount(std::string_view str)
{ {
return str.size() - return str.size() - std::ranges::count_if(str, [](char c) -> bool { return (c & 0xC0) == 0x80; });
std::count_if(str.begin(), str.end(), [](char c) -> bool { return (c & 0xC0) == 0x80; });
} }
#ifdef _WIN32 #ifdef _WIN32
@ -656,12 +655,12 @@ std::string GetEscapedHtml(std::string html)
void ToLower(std::string* str) void ToLower(std::string* str)
{ {
std::transform(str->begin(), str->end(), str->begin(), [](char c) { return Common::ToLower(c); }); std::ranges::transform(*str, str->begin(), static_cast<char (&)(char)>(Common::ToLower));
} }
void ToUpper(std::string* str) void ToUpper(std::string* str)
{ {
std::transform(str->begin(), str->end(), str->begin(), [](char c) { return Common::ToUpper(c); }); std::ranges::transform(*str, str->begin(), static_cast<char (&)(char)>(Common::ToUpper));
} }
bool CaseInsensitiveEquals(std::string_view a, std::string_view b) bool CaseInsensitiveEquals(std::string_view a, std::string_view b)

View File

@ -265,7 +265,7 @@ struct SetGameMetadata
std::string executable_path = executable.path; std::string executable_path = executable.path;
constexpr char BACKSLASH = '\\'; constexpr char BACKSLASH = '\\';
constexpr char FORWARDSLASH = '/'; constexpr char FORWARDSLASH = '/';
std::replace(executable_path.begin(), executable_path.end(), BACKSLASH, FORWARDSLASH); std::ranges::replace(executable_path, BACKSLASH, FORWARDSLASH);
config->SetRunningGameMetadata(SConfig::MakeGameID(PathToFileName(executable_path))); config->SetRunningGameMetadata(SConfig::MakeGameID(PathToFileName(executable_path)));
Host_TitleChanged(); Host_TitleChanged();

View File

@ -143,20 +143,20 @@ bool SDSP::Initialize(const DSPInitOptions& opts)
std::memset(&r, 0, sizeof(r)); std::memset(&r, 0, sizeof(r));
std::fill(std::begin(reg_stack_ptrs), std::end(reg_stack_ptrs), 0); std::ranges::fill(reg_stack_ptrs, 0);
for (auto& stack : reg_stacks) for (auto& stack : reg_stacks)
std::fill(std::begin(stack), std::end(stack), 0); std::ranges::fill(stack, 0);
// Fill IRAM with HALT opcodes. // Fill IRAM with HALT opcodes.
std::fill(iram, iram + DSP_IRAM_SIZE, 0x0021); std::ranges::fill_n(iram, DSP_IRAM_SIZE, 0x0021);
// Just zero out DRAM. // Just zero out DRAM.
std::fill(dram, dram + DSP_DRAM_SIZE, 0); std::ranges::fill_n(dram, DSP_DRAM_SIZE, 0);
// Copied from a real console after the custom UCode has been loaded. // Copied from a real console after the custom UCode has been loaded.
// These are the indexing wrapping registers. // These are the indexing wrapping registers.
std::fill(std::begin(r.wr), std::end(r.wr), 0xffff); std::ranges::fill(r.wr, 0xffff);
r.sr |= SR_INT_ENABLE; r.sr |= SR_INT_ENABLE;
r.sr |= SR_EXT_INT_ENABLE; r.sr |= SR_EXT_INT_ENABLE;
@ -172,7 +172,7 @@ bool SDSP::Initialize(const DSPInitOptions& opts)
void SDSP::Reset() void SDSP::Reset()
{ {
pc = DSP_RESET_VECTOR; pc = DSP_RESET_VECTOR;
std::fill(std::begin(r.wr), std::end(r.wr), 0xffff); std::ranges::fill(r.wr, 0xffff);
} }
void SDSP::Shutdown() void SDSP::Shutdown()

View File

@ -40,7 +40,7 @@ DSPEmitter::DSPEmitter(DSPCore& dsp)
m_stub_entry_point = CompileStub(); m_stub_entry_point = CompileStub();
// Clear all of the block references // Clear all of the block references
std::fill(m_blocks.begin(), m_blocks.end(), (DSPCompiledCode)m_stub_entry_point); std::ranges::fill(m_blocks, (DSPCompiledCode)m_stub_entry_point);
} }
DSPEmitter::~DSPEmitter() DSPEmitter::~DSPEmitter()

View File

@ -307,8 +307,7 @@ void BranchWatch::UpdateHitsSnapshot()
void BranchWatch::ClearSelectionInspection() void BranchWatch::ClearSelectionInspection()
{ {
std::for_each(m_selection.begin(), m_selection.end(), std::ranges::for_each(m_selection, [](Selection::value_type& value) { value.inspection = {}; });
[](Selection::value_type& value) { value.inspection = {}; });
} }
void BranchWatch::SetSelectedInspected(std::size_t idx, SelectionInspection inspection) void BranchWatch::SetSelectedInspected(std::size_t idx, SelectionInspection inspection)

View File

@ -266,7 +266,7 @@ Common::Debug::Threads PPCDebugInterface::GetThreads(const Core::CPUThreadGuard&
const u32 prev_addr = active_thread->Data().thread_link.prev; const u32 prev_addr = active_thread->Data().thread_link.prev;
insert_threads(prev_addr, [](const auto& thread) { return thread.Data().thread_link.prev; }); insert_threads(prev_addr, [](const auto& thread) { return thread.Data().thread_link.prev; });
std::reverse(threads.begin(), threads.end()); std::ranges::reverse(threads);
const u32 next_addr = active_thread->Data().thread_link.next; const u32 next_addr = active_thread->Data().thread_link.next;
threads.emplace_back(std::move(active_thread)); threads.emplace_back(std::move(active_thread));

View File

@ -500,7 +500,7 @@ void FifoPlayer::WriteMemory(const MemoryUpdate& memUpdate)
else else
mem = &memory.GetRAM()[memUpdate.address & memory.GetRamMask()]; mem = &memory.GetRAM()[memUpdate.address & memory.GetRamMask()];
std::copy(memUpdate.data.begin(), memUpdate.data.end(), mem); std::ranges::copy(memUpdate.data, mem);
} }
void FifoPlayer::WriteFifo(const u8* data, u32 start, u32 end) void FifoPlayer::WriteFifo(const u8* data, u32 start, u32 end)

View File

@ -240,8 +240,8 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
m_Ram.resize(memory.GetRamSize()); m_Ram.resize(memory.GetRamSize());
m_ExRam.resize(memory.GetExRamSize()); m_ExRam.resize(memory.GetExRamSize());
std::fill(m_Ram.begin(), m_Ram.end(), 0); std::ranges::fill(m_Ram, 0);
std::fill(m_ExRam.begin(), m_ExRam.end(), 0); std::ranges::fill(m_ExRam, 0);
m_File->SetIsWii(m_system.IsWii()); m_File->SetIsWii(m_system.IsWii());

View File

@ -93,7 +93,7 @@ int CSIDevice_GBAEmu::RunBuffer(u8* buffer, int request_length)
std::vector<u8> response = m_core->GetJoybusResponse(); std::vector<u8> response = m_core->GetJoybusResponse();
if (response.empty()) if (response.empty())
return -1; return -1;
std::copy(response.begin(), response.end(), buffer); std::ranges::copy(response, buffer);
#ifdef _DEBUG #ifdef _DEBUG
const Common::Log::LogLevel log_level = const Common::Log::LogLevel log_level =

View File

@ -422,7 +422,7 @@ public:
if (data) if (data)
{ {
std::vector<u8> file_data_enc(Common::AlignUp(data->size(), BLOCK_SZ)); std::vector<u8> file_data_enc(Common::AlignUp(data->size(), BLOCK_SZ));
std::copy(data->cbegin(), data->cend(), file_data_enc.begin()); std::ranges::copy(*data, file_data_enc.begin());
m_iosc.Encrypt(IOS::HLE::IOSC::HANDLE_SD_KEY, file_hdr.iv.data(), file_data_enc.data(), m_iosc.Encrypt(IOS::HLE::IOSC::HANDLE_SD_KEY, file_hdr.iv.data(), file_data_enc.data(),
file_data_enc.size(), file_data_enc.data(), IOS::PID_ES); file_data_enc.size(), file_data_enc.data(), IOS::PID_ES);
if (!m_file.WriteBytes(file_data_enc.data(), file_data_enc.size())) if (!m_file.WriteBytes(file_data_enc.data(), file_data_enc.size()))

View File

@ -70,7 +70,7 @@ CameraLogic::GetCameraPoints(const Common::Matrix44& transform, Common::Vec2 fie
std::array<CameraPoint, CameraLogic::NUM_POINTS> camera_points; std::array<CameraPoint, CameraLogic::NUM_POINTS> camera_points;
std::transform(leds.begin(), leds.end(), camera_points.begin(), [&](const Vec3& v) { std::ranges::transform(leds, camera_points.begin(), [&](const Vec3& v) {
const auto point = camera_view * Vec4(v, 1.0); const auto point = camera_view * Vec4(v, 1.0);
// Check if LED is behind camera. // Check if LED is behind camera.

View File

@ -452,7 +452,7 @@ bool Wiimote::ProcessReadDataRequest()
reply.address = Common::swap16(m_read_request.address); reply.address = Common::swap16(m_read_request.address);
// Pre-fill with zeros in case of read-error or read < 16-bytes: // Pre-fill with zeros in case of read-error or read < 16-bytes:
std::fill(std::begin(reply.data), std::end(reply.data), 0x00); std::ranges::fill(reply.data, 0x00);
ErrorCode error_code = ErrorCode::Success; ErrorCode error_code = ErrorCode::Success;

View File

@ -44,7 +44,7 @@ struct MPI : mbedtls_mpi
if (mbedtls_mpi_write_binary(this, out_data->data(), out_data->size())) if (mbedtls_mpi_write_binary(this, out_data->data(), out_data->size()))
return false; return false;
std::reverse(out_data->begin(), out_data->end()); std::ranges::reverse(*out_data);
return true; return true;
} }

View File

@ -33,14 +33,14 @@ std::optional<IPCReply> ShaDevice::Open(const OpenRequest& request)
static void ConvertContext(const ShaDevice::ShaContext& src, mbedtls_sha1_context* dest) static void ConvertContext(const ShaDevice::ShaContext& src, mbedtls_sha1_context* dest)
{ {
std::copy(std::begin(src.length), std::end(src.length), std::begin(dest->total)); std::ranges::copy(src.length, std::begin(dest->total));
std::copy(std::begin(src.states), std::end(src.states), std::begin(dest->state)); std::ranges::copy(src.states, std::begin(dest->state));
} }
static void ConvertContext(const mbedtls_sha1_context& src, ShaDevice::ShaContext* dest) static void ConvertContext(const mbedtls_sha1_context& src, ShaDevice::ShaContext* dest)
{ {
std::copy(std::begin(src.total), std::end(src.total), std::begin(dest->length)); std::ranges::copy(src.total, std::begin(dest->length));
std::copy(std::begin(src.state), std::end(src.state), std::begin(dest->states)); std::ranges::copy(src.state, std::begin(dest->states));
} }
HLE::ReturnCode ShaDevice::ProcessShaCommand(ShaIoctlv command, const IOCtlVRequest& request) HLE::ReturnCode ShaDevice::ProcessShaCommand(ShaIoctlv command, const IOCtlVRequest& request)

View File

@ -530,7 +530,7 @@ HLE::ReturnCode TicketReader::Unpersonalise(HLE::IOSC& iosc)
sizeof(Ticket::title_key), key.data(), PID_ES); sizeof(Ticket::title_key), key.data(), PID_ES);
// Finally, IOS copies the decrypted title key back to the ticket buffer. // Finally, IOS copies the decrypted title key back to the ticket buffer.
if (ret == IPC_SUCCESS) if (ret == IPC_SUCCESS)
std::copy(key.cbegin(), key.cend(), ticket_begin + offsetof(Ticket, title_key)); std::ranges::copy(key, ticket_begin + offsetof(Ticket, title_key));
return ret; return ret;
} }

View File

@ -219,8 +219,7 @@ ESCore::GetStoredContentsFromTMD(const ES::TMDReader& tmd,
u32 ESCore::GetSharedContentsCount() const u32 ESCore::GetSharedContentsCount() const
{ {
const auto entries = m_ios.GetFS()->ReadDirectory(PID_KERNEL, PID_KERNEL, "/shared1"); const auto entries = m_ios.GetFS()->ReadDirectory(PID_KERNEL, PID_KERNEL, "/shared1");
return static_cast<u32>( return static_cast<u32>(std::ranges::count_if(*entries, [this](const std::string& entry) {
std::count_if(entries->begin(), entries->end(), [this](const std::string& entry) {
return !m_ios.GetFS()->ReadDirectory(PID_KERNEL, PID_KERNEL, "/shared1/" + entry) && return !m_ios.GetFS()->ReadDirectory(PID_KERNEL, PID_KERNEL, "/shared1/" + entry) &&
entry.size() == 12 && entry.compare(8, 4, ".app") == 0; entry.size() == 12 && entry.compare(8, 4, ".app") == 0;
})); }));

View File

@ -817,7 +817,7 @@ ReturnCode ESCore::ExportContentData(Context& context, u32 content_fd, u8* data,
if (encrypt_ret != IPC_SUCCESS) if (encrypt_ret != IPC_SUCCESS)
return encrypt_ret; return encrypt_ret;
std::copy(output.cbegin(), output.cend(), data); std::ranges::copy(output, data);
return IPC_SUCCESS; return IPC_SUCCESS;
} }

View File

@ -147,7 +147,7 @@ ReturnCode ESCore::GetTicketFromView(const u8* ticket_view, u8* ticket, u32* tic
return ES_EACCES; return ES_EACCES;
} }
std::copy(ticket_bytes.begin(), ticket_bytes.end(), ticket); std::ranges::copy(ticket_bytes, ticket);
return IPC_SUCCESS; return IPC_SUCCESS;
} }

View File

@ -143,7 +143,7 @@ enum class FileLookupMode
static SystemTimers::TimeBaseTick EstimateFileLookupTicks(const std::string& path, static SystemTimers::TimeBaseTick EstimateFileLookupTicks(const std::string& path,
FileLookupMode mode) FileLookupMode mode)
{ {
const size_t number_of_path_components = std::count(path.cbegin(), path.cend(), '/'); const size_t number_of_path_components = std::ranges::count(path, '/');
if (number_of_path_components == 0) if (number_of_path_components == 0)
return 0_tbticks; return 0_tbticks;

View File

@ -467,7 +467,7 @@ ResultCode HostFileSystem::CreateFileOrDirectory(Uid uid, Gid gid, const std::st
return ResultCode::Invalid; return ResultCode::Invalid;
} }
if (!is_file && std::count(path.begin(), path.end(), '/') > int(MaxPathDepth)) if (!is_file && std::ranges::count(path, '/') > int(MaxPathDepth))
return ResultCode::TooManyPathComponents; return ResultCode::TooManyPathComponents;
const auto split_path = SplitPathAndBasename(path); const auto split_path = SplitPathAndBasename(path);

View File

@ -551,7 +551,7 @@ void IOSC::Sign(u8* sig_out, u8* ap_cert_out, u64 title_id, const u8* data, u32
// Sign the data. // Sign the data.
const auto data_digest = Common::SHA1::CalculateDigest(data, data_size); const auto data_digest = Common::SHA1::CalculateDigest(data, data_size);
const auto signature = Common::ec::Sign(ap_priv.data(), data_digest.data()); const auto signature = Common::ec::Sign(ap_priv.data(), data_digest.data());
std::copy(signature.cbegin(), signature.cend(), sig_out); std::ranges::copy(signature, sig_out);
} }
void IOSC::LoadDefaultEntries() void IOSC::LoadDefaultEntries()

View File

@ -51,8 +51,8 @@ BluetoothEmuDevice::BluetoothEmuDevice(EmulationKernel& ios, const std::string&
const bdaddr_t tmp_bd = {0x11, 0x02, 0x19, 0x79, 0, i}; const bdaddr_t tmp_bd = {0x11, 0x02, 0x19, 0x79, 0, i};
// Previous records can be safely overwritten, since they are backed up // Previous records can be safely overwritten, since they are backed up
std::copy(tmp_bd.begin(), tmp_bd.end(), std::rbegin(bt_dinf.active[i].bdaddr)); std::ranges::copy(tmp_bd, std::rbegin(bt_dinf.active[i].bdaddr));
std::copy(tmp_bd.begin(), tmp_bd.end(), std::rbegin(bt_dinf.registered[i].bdaddr)); std::ranges::copy(tmp_bd, std::rbegin(bt_dinf.registered[i].bdaddr));
const auto& wm_name = const auto& wm_name =
(i == WIIMOTE_BALANCE_BOARD) ? "Nintendo RVL-WBC-01" : "Nintendo RVL-CNT-01"; (i == WIIMOTE_BALANCE_BOARD) ? "Nintendo RVL-WBC-01" : "Nintendo RVL-CNT-01";

View File

@ -482,9 +482,9 @@ bool BluetoothRealDevice::SendHCIStoreLinkKeyCommand()
auto iterator = packet.begin() + sizeof(hci_cmd_hdr_t) + sizeof(hci_write_stored_link_key_cp); auto iterator = packet.begin() + sizeof(hci_cmd_hdr_t) + sizeof(hci_write_stored_link_key_cp);
for (const auto& entry : m_link_keys) for (const auto& entry : m_link_keys)
{ {
std::copy(entry.first.begin(), entry.first.end(), iterator); std::ranges::copy(entry.first, iterator);
iterator += entry.first.size(); iterator += entry.first.size();
std::copy(entry.second.begin(), entry.second.end(), iterator); std::ranges::copy(entry.second, iterator);
iterator += entry.second.size(); iterator += entry.second.size();
} }
@ -598,7 +598,7 @@ void BluetoothRealDevice::LoadLinkKeys()
} }
auto& mac = address.value(); auto& mac = address.value();
std::reverse(mac.begin(), mac.end()); std::ranges::reverse(mac);
const std::string& key_string = pair.substr(index + 1); const std::string& key_string = pair.substr(index + 1);
linkkey_t key{}; linkkey_t key{};
@ -621,7 +621,7 @@ void BluetoothRealDevice::SaveLinkKeys()
{ {
bdaddr_t address; bdaddr_t address;
// Reverse the address so that it is stored in the correct order in the config file // Reverse the address so that it is stored in the correct order in the config file
std::reverse_copy(entry.first.begin(), entry.first.end(), address.begin()); std::ranges::reverse_copy(entry.first, address.begin());
oss << Common::MacAddressToString(address); oss << Common::MacAddressToString(address);
oss << '='; oss << '=';
oss << std::hex; oss << std::hex;
@ -737,7 +737,7 @@ void BluetoothRealDevice::HandleBulkOrIntrTransfer(libusb_transfer* tr)
hci_link_key_notification_ep notification; hci_link_key_notification_ep notification;
std::memcpy(&notification, tr->buffer + sizeof(hci_event_hdr_t), sizeof(notification)); std::memcpy(&notification, tr->buffer + sizeof(hci_event_hdr_t), sizeof(notification));
linkkey_t key; linkkey_t key;
std::copy(std::begin(notification.key), std::end(notification.key), std::begin(key)); std::ranges::copy(notification.key, std::begin(key));
m_link_keys[notification.bdaddr] = key; m_link_keys[notification.bdaddr] = key;
} }
else if (event == HCI_EVENT_COMMAND_COMPL) else if (event == HCI_EVENT_COMMAND_COMPL)

View File

@ -87,7 +87,7 @@ void V4GetUSStringMessage::OnTransferComplete(s32 return_value) const
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
std::string message = memory.GetString(data_address); std::string message = memory.GetString(data_address);
std::replace_if(message.begin(), message.end(), std::not_fn(Common::IsPrintableCharacter), '?'); std::ranges::replace_if(message, std::not_fn(Common::IsPrintableCharacter), '?');
memory.CopyToEmu(data_address, message.c_str(), message.size()); memory.CopyToEmu(data_address, message.c_str(), message.size());
TransferCommand::OnTransferComplete(return_value); TransferCommand::OnTransferComplete(return_value);
} }

View File

@ -1100,7 +1100,7 @@ void MovieManager::LoadInput(const std::string& movie_path)
"read-only mode off. Otherwise you'll probably get a desync.", "read-only mode off. Otherwise you'll probably get a desync.",
byte_offset, byte_offset); byte_offset, byte_offset);
std::copy(movInput.begin(), movInput.end(), m_temp_input.begin()); std::ranges::copy(movInput, m_temp_input.begin());
} }
else else
{ {

View File

@ -100,9 +100,9 @@ void Cache::Reset()
valid.fill(0); valid.fill(0);
plru.fill(0); plru.fill(0);
modified.fill(0); modified.fill(0);
std::fill(lookup_table.begin(), lookup_table.end(), 0xFF); std::ranges::fill(lookup_table, 0xFF);
std::fill(lookup_table_ex.begin(), lookup_table_ex.end(), 0xFF); std::ranges::fill(lookup_table_ex, 0xFF);
std::fill(lookup_table_vmem.begin(), lookup_table_vmem.end(), 0xFF); std::ranges::fill(lookup_table_vmem, 0xFF);
} }
void InstructionCache::Reset(JitInterface& jit_interface) void InstructionCache::Reset(JitInterface& jit_interface)

View File

@ -128,10 +128,10 @@ void PowerPCManager::DoState(PointerWrap& p)
void PowerPCManager::ResetRegisters() void PowerPCManager::ResetRegisters()
{ {
std::fill(std::begin(m_ppc_state.ps), std::end(m_ppc_state.ps), PairedSingle{}); std::ranges::fill(m_ppc_state.ps, PairedSingle{});
std::fill(std::begin(m_ppc_state.sr), std::end(m_ppc_state.sr), 0U); std::ranges::fill(m_ppc_state.sr, 0U);
std::fill(std::begin(m_ppc_state.gpr), std::end(m_ppc_state.gpr), 0U); std::ranges::fill(m_ppc_state.gpr, 0U);
std::fill(std::begin(m_ppc_state.spr), std::end(m_ppc_state.spr), 0U); std::ranges::fill(m_ppc_state.spr, 0U);
// Gamecube: // Gamecube:
// 0x00080200 = lonestar 2.0 // 0x00080200 = lonestar 2.0

View File

@ -192,7 +192,7 @@ bool SysConf::Save() const
// Make sure the buffer size is 0x4000 bytes now and write the footer. // Make sure the buffer size is 0x4000 bytes now and write the footer.
buffer.resize(SYSCONF_SIZE); buffer.resize(SYSCONF_SIZE);
constexpr std::array<u8, 4> footer = {{'S', 'C', 'e', 'd'}}; constexpr std::array<u8, 4> footer = {{'S', 'C', 'e', 'd'}};
std::copy(footer.cbegin(), footer.cend(), buffer.end() - footer.size()); std::ranges::copy(footer, buffer.end() - footer.size());
// Write the new data. // Write the new data.
const std::string temp_file = "/tmp/SYSCONF"; const std::string temp_file = "/tmp/SYSCONF";

View File

@ -623,8 +623,7 @@ void DirectoryBlobReader::SetWiiRegionData(const std::vector<u8>& wii_region_dat
void DirectoryBlobReader::SetPartitions(std::vector<PartitionWithType>&& partitions) void DirectoryBlobReader::SetPartitions(std::vector<PartitionWithType>&& partitions)
{ {
std::sort(partitions.begin(), partitions.end(), std::ranges::sort(partitions, [](const PartitionWithType& lhs, const PartitionWithType& rhs) {
[](const PartitionWithType& lhs, const PartitionWithType& rhs) {
if (lhs.type == rhs.type) if (lhs.type == rhs.type)
return lhs.partition.GetRootDirectory() < rhs.partition.GetRootDirectory(); return lhs.partition.GetRootDirectory() < rhs.partition.GetRootDirectory();

View File

@ -721,8 +721,7 @@ bool VolumeVerifier::ShouldHaveChannelPartition() const
}; };
static_assert(std::ranges::is_sorted(channel_discs)); static_assert(std::ranges::is_sorted(channel_discs));
return std::binary_search(channel_discs.cbegin(), channel_discs.cend(), return std::ranges::binary_search(channel_discs, m_volume.GetGameID());
std::string_view(m_volume.GetGameID()));
} }
bool VolumeVerifier::ShouldHaveInstallPartition() const bool VolumeVerifier::ShouldHaveInstallPartition() const
@ -754,8 +753,7 @@ bool VolumeVerifier::ShouldBeDualLayer() const
}; };
static_assert(std::ranges::is_sorted(dual_layer_discs)); static_assert(std::ranges::is_sorted(dual_layer_discs));
return std::binary_search(dual_layer_discs.cbegin(), dual_layer_discs.cend(), return std::ranges::binary_search(dual_layer_discs, m_volume.GetGameID());
std::string_view(m_volume.GetGameID()));
} }
void VolumeVerifier::CheckVolumeSize() void VolumeVerifier::CheckVolumeSize()

View File

@ -914,7 +914,7 @@ CalibrationWidget::CalibrationWidget(ControllerEmu::ReshapableInput& input,
m_informative_timer = new QTimer(this); m_informative_timer = new QTimer(this);
connect(m_informative_timer, &QTimer::timeout, this, [this] { connect(m_informative_timer, &QTimer::timeout, this, [this] {
// If the user has started moving we'll assume they know what they are doing. // If the user has started moving we'll assume they know what they are doing.
if (*std::max_element(m_calibration_data.begin(), m_calibration_data.end()) > 0.5) if (*std::ranges::max_element(m_calibration_data) > 0.5)
return; return;
ModalMessageBox::information( ModalMessageBox::information(

View File

@ -846,7 +846,7 @@ void AssemblerWidget::CloseTab(int index, AsmEditor* editor)
int AssemblerWidget::AllocateTabNum() int AssemblerWidget::AllocateTabNum()
{ {
auto min_it = std::min_element(m_free_editor_nums.begin(), m_free_editor_nums.end()); auto min_it = std::ranges::min_element(m_free_editor_nums);
if (min_it == m_free_editor_nums.end()) if (min_it == m_free_editor_nums.end())
{ {
return m_unnamed_editor_count++; return m_unnamed_editor_count++;

View File

@ -481,7 +481,7 @@ void WatchWidget::DeleteSelectedWatches()
} }
// Sort greatest to smallest, so we don't stomp on existing indices // 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) for (const int row : row_indices)
{ {
DeleteWatch(guard, row); DeleteWatch(guard, row);

View File

@ -192,8 +192,7 @@ void FIFOAnalyzer::UpdateTree()
// We shouldn't end on a Command (it should end with an EFB copy) // We shouldn't end on a Command (it should end with an EFB copy)
ASSERT(part_start == frame_info.parts.size()); ASSERT(part_start == frame_info.parts.size());
// The counts we computed should match the frame's counts // The counts we computed should match the frame's counts
ASSERT(std::equal(frame_info.part_type_counts.begin(), frame_info.part_type_counts.end(), ASSERT(std::ranges::equal(frame_info.part_type_counts, part_counts));
part_counts.begin()));
} }
} }

View File

@ -130,8 +130,7 @@ void InterfacePane::CreateUI()
Common::DoFileSearch({File::GetUserPath(D_THEMES_IDX), File::GetSysDirectory() + THEMES_DIR}); Common::DoFileSearch({File::GetUserPath(D_THEMES_IDX), File::GetSysDirectory() + THEMES_DIR});
std::vector<std::string> theme_names; std::vector<std::string> theme_names;
theme_names.reserve(theme_paths.size()); theme_names.reserve(theme_paths.size());
std::transform(theme_paths.cbegin(), theme_paths.cend(), std::back_inserter(theme_names), std::ranges::transform(theme_paths, std::back_inserter(theme_names), PathToFileName);
PathToFileName);
// Theme Combobox // Theme Combobox
m_combobox_theme = new ConfigStringChoice(theme_names, Config::MAIN_THEME_NAME); m_combobox_theme = new ConfigStringChoice(theme_names, Config::MAIN_THEME_NAME);

View File

@ -143,10 +143,10 @@ void ToolBar::MakeActions()
} }
std::vector<int> widths; std::vector<int> widths;
std::transform(items.begin(), items.end(), std::back_inserter(widths), std::ranges::transform(items, std::back_inserter(widths),
[](QWidget* item) { return item->sizeHint().width(); }); [](QWidget* item) { return item->sizeHint().width(); });
const int min_width = *std::max_element(widths.begin(), widths.end()) * 0.85; const int min_width = *std::ranges::max_element(widths) * 0.85;
for (QWidget* widget : items) for (QWidget* widget : items)
widget->setMinimumWidth(min_width); widget->setMinimumWidth(min_width);
} }

View File

@ -53,8 +53,7 @@ struct TwoPointCalibration
} }
else else
{ {
return std::equal(std::begin(max.data), std::end(max.data), std::begin(zero.data), return std::ranges::equal(max.data, zero.data, std::ranges::not_equal_to{});
std::not_equal_to<>());
} }
} }

View File

@ -176,15 +176,14 @@ Joystick::Joystick(const LPDIRECTINPUTDEVICE8 device) : m_device(device)
std::list<DIDEVICEOBJECTINSTANCE> objects; std::list<DIDEVICEOBJECTINSTANCE> objects;
if (SUCCEEDED(m_device->EnumObjects(DIEnumDeviceObjectsCallback, (LPVOID)&objects, DIDFT_AXIS))) if (SUCCEEDED(m_device->EnumObjects(DIEnumDeviceObjectsCallback, (LPVOID)&objects, DIDFT_AXIS)))
{ {
const int num_ff_axes = const int num_ff_axes = std::ranges::count_if(
std::count_if(std::begin(objects), std::end(objects), objects, [](const auto& pdidoi) { return (pdidoi.dwFlags & DIDOI_FFACTUATOR) != 0; });
[](const auto& pdidoi) { return (pdidoi.dwFlags & DIDOI_FFACTUATOR) != 0; });
InitForceFeedback(m_device, num_ff_axes); InitForceFeedback(m_device, num_ff_axes);
} }
// Set hats to center: // Set hats to center:
// "The center position is normally reported as -1" -MSDN // "The center position is normally reported as -1" -MSDN
std::fill(std::begin(m_state_in.rgdwPOV), std::end(m_state_in.rgdwPOV), -1); std::ranges::fill(m_state_in.rgdwPOV, -1);
} }
Joystick::~Joystick() Joystick::~Joystick()

View File

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

View File

@ -111,8 +111,7 @@ ProfileCycler::GetMatchingProfilesFromSetting(const std::string& setting,
} }
std::vector<std::string> result; std::vector<std::string> result;
std::set_intersection(profiles.begin(), profiles.end(), profiles_from_setting.begin(), std::ranges::set_intersection(profiles, profiles_from_setting, std::back_inserter(result));
profiles_from_setting.end(), std::back_inserter(result));
return result; return result;
} }

View File

@ -613,11 +613,10 @@ bool GameFile::CheckIfTwoDiscGame(const std::string& game_id) const
"S6T", "S6T",
"SDQ", "SDQ",
}; };
static_assert(std::is_sorted(two_disc_game_id_prefixes.begin(), two_disc_game_id_prefixes.end())); static_assert(std::ranges::is_sorted(two_disc_game_id_prefixes));
std::string_view game_id_prefix(game_id.data(), GAME_ID_PREFIX_SIZE); std::string_view game_id_prefix(game_id.data(), GAME_ID_PREFIX_SIZE);
return std::binary_search(two_disc_game_id_prefixes.begin(), two_disc_game_id_prefixes.end(), return std::ranges::binary_search(two_disc_game_id_prefixes, game_id_prefix);
game_id_prefix);
} }
std::string GameFile::GetNetPlayName(const Core::TitleDatabase& title_database) const std::string GameFile::GetNetPlayName(const Core::TitleDatabase& title_database) const

View File

@ -225,7 +225,7 @@ void SetLocale(std::string locale_name)
if (locale_name == "en") if (locale_name == "en")
locale_name = "en_GB"; locale_name = "en_GB";
std::replace(locale_name.begin(), locale_name.end(), OTHER_SEPARATOR, PREFERRED_SEPARATOR); std::ranges::replace(locale_name, OTHER_SEPARATOR, PREFERRED_SEPARATOR);
// Use the specified locale if supported. // Use the specified locale if supported.
if (set_locale(locale_name)) if (set_locale(locale_name))

View File

@ -4,6 +4,7 @@
#include "VideoBackends/OGL/OGLConfig.h" #include "VideoBackends/OGL/OGLConfig.h"
#include <cstdio> #include <cstdio>
#include <ranges>
#include <string> #include <string>
#include <string_view> #include <string_view>
@ -585,7 +586,7 @@ bool PopulateConfig(GLContext* m_main_gl_context)
glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, colorInternalFormat, GL_SAMPLES, glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, colorInternalFormat, GL_SAMPLES,
num_color_sample_counts, num_color_sample_counts,
reinterpret_cast<GLint*>(color_aa_modes.data())); reinterpret_cast<GLint*>(color_aa_modes.data()));
ASSERT_MSG(VIDEO, std::is_sorted(color_aa_modes.rbegin(), color_aa_modes.rend()), ASSERT_MSG(VIDEO, std::ranges::is_sorted(color_aa_modes | std::views::reverse),
"GPU driver didn't return sorted color AA modes: [{}]", "GPU driver didn't return sorted color AA modes: [{}]",
fmt::join(color_aa_modes, ", ")); fmt::join(color_aa_modes, ", "));
} }
@ -614,7 +615,7 @@ bool PopulateConfig(GLContext* m_main_gl_context)
glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, depthInternalFormat, GL_SAMPLES, glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, depthInternalFormat, GL_SAMPLES,
num_depth_sample_counts, num_depth_sample_counts,
reinterpret_cast<GLint*>(depth_aa_modes.data())); reinterpret_cast<GLint*>(depth_aa_modes.data()));
ASSERT_MSG(VIDEO, std::is_sorted(depth_aa_modes.rbegin(), depth_aa_modes.rend()), ASSERT_MSG(VIDEO, std::ranges::is_sorted(depth_aa_modes | std::views::reverse),
"GPU driver didn't return sorted depth AA modes: [{}]", "GPU driver didn't return sorted depth AA modes: [{}]",
fmt::join(depth_aa_modes, ", ")); fmt::join(depth_aa_modes, ", "));
} }
@ -630,9 +631,9 @@ bool PopulateConfig(GLContext* m_main_gl_context)
g_Config.backend_info.AAModes.clear(); g_Config.backend_info.AAModes.clear();
g_Config.backend_info.AAModes.reserve(std::min(color_aa_modes.size(), depth_aa_modes.size())); g_Config.backend_info.AAModes.reserve(std::min(color_aa_modes.size(), depth_aa_modes.size()));
// We only want AA modes that are supported for both the color and depth textures. Probably // We only want AA modes that are supported for both the color and depth textures. Probably
// the support is the same, though. rbegin/rend are used to swap the order ahead of time. // the support is the same, though. views::reverse is used to swap the order ahead of time.
std::set_intersection(color_aa_modes.rbegin(), color_aa_modes.rend(), depth_aa_modes.rbegin(), std::ranges::set_intersection(color_aa_modes | std::views::reverse,
depth_aa_modes.rend(), depth_aa_modes | std::views::reverse,
std::back_inserter(g_Config.backend_info.AAModes)); std::back_inserter(g_Config.backend_info.AAModes));
} }
else else
@ -660,7 +661,7 @@ bool PopulateConfig(GLContext* m_main_gl_context)
} }
g_Config.backend_info.AAModes.push_back(1); g_Config.backend_info.AAModes.push_back(1);
// The UI wants ascending order // The UI wants ascending order
std::reverse(g_Config.backend_info.AAModes.begin(), g_Config.backend_info.AAModes.end()); std::ranges::reverse(g_Config.backend_info.AAModes);
} }
} }
else else

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); }; 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 ScissorRect ScissorResult::Best() const

View File

@ -764,9 +764,9 @@ bool FramebufferManager::CreateReadbackFramebuffer()
} }
m_efb_color_cache.tiles.resize(total_tiles); m_efb_color_cache.tiles.resize(total_tiles);
std::fill(m_efb_color_cache.tiles.begin(), m_efb_color_cache.tiles.end(), EFBCacheTile{false, 0}); std::ranges::fill(m_efb_color_cache.tiles, EFBCacheTile{false, 0});
m_efb_depth_cache.tiles.resize(total_tiles); m_efb_depth_cache.tiles.resize(total_tiles);
std::fill(m_efb_depth_cache.tiles.begin(), m_efb_depth_cache.tiles.end(), EFBCacheTile{false, 0}); std::ranges::fill(m_efb_depth_cache.tiles, EFBCacheTile{false, 0});
return true; return true;
} }

View File

@ -965,8 +965,7 @@ void VertexManagerBase::OnDraw()
// Check if this draw is scheduled to kick a command buffer. // Check if this draw is scheduled to kick a command buffer.
// The draw counters will always be sorted so a binary search is possible here. // The draw counters will always be sorted so a binary search is possible here.
if (std::binary_search(m_scheduled_command_buffer_kicks.begin(), if (std::ranges::binary_search(m_scheduled_command_buffer_kicks, m_draw_counter))
m_scheduled_command_buffer_kicks.end(), m_draw_counter))
{ {
// Kick a command buffer on the background thread. // Kick a command buffer on the background thread.
g_gfx->Flush(); g_gfx->Flush();

View File

@ -47,7 +47,7 @@ TEST(SettingsHandlerTest, EncryptSingleSetting)
handler.AddSetting("key", "val"); handler.AddSetting("key", "val");
Common::SettingsHandler::Buffer buffer = handler.GetBytes(); Common::SettingsHandler::Buffer buffer = handler.GetBytes();
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), BUFFER_A.begin(), BUFFER_A.end())); EXPECT_TRUE(std::ranges::equal(buffer, BUFFER_A));
} }
TEST(SettingsHandlerTest, DecryptSingleSetting) TEST(SettingsHandlerTest, DecryptSingleSetting)
@ -64,7 +64,7 @@ TEST(SettingsHandlerTest, EncryptMultipleSettings)
handler.AddSetting("foo", "bar"); handler.AddSetting("foo", "bar");
Common::SettingsHandler::Buffer buffer = handler.GetBytes(); Common::SettingsHandler::Buffer buffer = handler.GetBytes();
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), BUFFER_B.begin(), BUFFER_B.end())); EXPECT_TRUE(std::ranges::equal(buffer, BUFFER_B));
} }
TEST(SettingsHandlerTest, DecryptMultipleSettings) TEST(SettingsHandlerTest, DecryptMultipleSettings)
@ -88,7 +88,7 @@ TEST(SettingsHandlerTest, EncryptAddsLFOnNullChar)
handler.AddSetting("\xFA", "a"); handler.AddSetting("\xFA", "a");
Common::SettingsHandler::Buffer buffer = handler.GetBytes(); Common::SettingsHandler::Buffer buffer = handler.GetBytes();
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), BUFFER_C.begin(), BUFFER_C.end())); EXPECT_TRUE(std::ranges::equal(buffer, BUFFER_C));
} }
TEST(SettingsHandlerTest, EncryptAddsLFOnNullCharTwice) TEST(SettingsHandlerTest, EncryptAddsLFOnNullCharTwice)
@ -97,7 +97,7 @@ TEST(SettingsHandlerTest, EncryptAddsLFOnNullCharTwice)
handler.AddSetting("\xFA\xE9", "a"); handler.AddSetting("\xFA\xE9", "a");
Common::SettingsHandler::Buffer buffer = handler.GetBytes(); Common::SettingsHandler::Buffer buffer = handler.GetBytes();
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), BUFFER_D.begin(), BUFFER_D.end())); EXPECT_TRUE(std::ranges::equal(buffer, BUFFER_D));
} }
TEST(SettingsHandlerTest, DecryptSingleAddedLF) TEST(SettingsHandlerTest, DecryptSingleAddedLF)

View File

@ -121,7 +121,7 @@ TEST_F(FileSystemTest, CreateFile)
const Result<std::vector<std::string>> tmp_files = m_fs->ReadDirectory(Uid{0}, Gid{0}, "/tmp"); const Result<std::vector<std::string>> tmp_files = m_fs->ReadDirectory(Uid{0}, Gid{0}, "/tmp");
ASSERT_TRUE(tmp_files.Succeeded()); ASSERT_TRUE(tmp_files.Succeeded());
EXPECT_EQ(std::count(tmp_files->begin(), tmp_files->end(), "f"), 1u); EXPECT_EQ(std::ranges::count(*tmp_files, "f"), 1u);
// Test invalid paths // Test invalid paths
// Unprintable characters // Unprintable characters