Modernize std::all_of with ranges

In DITSpecification.cpp, MaterialAsset.cpp, and ShaderAsset.cpp, lambda predicates were replaced by pointers to member functions because ranges algorithms are able invoke those.

In NetPlayClient.cpp, the non-trivial `NetPlay::Player` elements were being passed by value in `NetPlayClient::DoAllPlayersHaveGame()`. This has been fixed.

In WIABlob.cpp, the second example's predicate was returning the `std::optional` by value instead of implicitly converting it to a bool. This has been fixed.
This commit is contained in:
mitaclaw
2024-09-29 11:43:52 -07:00
parent 826e2bbf98
commit 860e6cf5cb
27 changed files with 42 additions and 51 deletions

View File

@ -52,8 +52,8 @@ ConvertDialog::ConvertDialog(QList<std::shared_ptr<const UICommon::GameFile>> fi
m_format->addItem(QStringLiteral("GCZ"), static_cast<int>(DiscIO::BlobType::GCZ));
m_format->addItem(QStringLiteral("WIA"), static_cast<int>(DiscIO::BlobType::WIA));
m_format->addItem(QStringLiteral("RVZ"), static_cast<int>(DiscIO::BlobType::RVZ));
if (std::all_of(m_files.begin(), m_files.end(),
[](const auto& file) { return file->GetBlobType() == DiscIO::BlobType::PLAIN; }))
if (std::ranges::all_of(
m_files, [](const auto& file) { return file->GetBlobType() == DiscIO::BlobType::PLAIN; }))
{
m_format->setCurrentIndex(m_format->count() - 1);
}
@ -153,7 +153,7 @@ void ConvertDialog::OnFormatChanged()
// To support legacy versions of dolphin, we have to check the GCZ block size
// See DiscIO::IsGCZBlockSizeLegacyCompatible() for details
const auto block_size_ok = [this](int block_size) {
return std::all_of(m_files.begin(), m_files.end(), [block_size](const auto& file) {
return std::ranges::all_of(m_files, [block_size](const auto& file) {
return DiscIO::IsGCZBlockSizeLegacyCompatible(block_size, file->GetVolumeSize());
});
};

View File

@ -377,15 +377,15 @@ void GameList::ShowContextMenu(const QPoint&)
{
const auto selected_games = GetSelectedGames();
if (std::all_of(selected_games.begin(), selected_games.end(),
[](const auto& game) { return game->ShouldAllowConversion(); }))
if (std::ranges::all_of(selected_games,
[](const auto& game) { return game->ShouldAllowConversion(); }))
{
menu->addAction(tr("Convert Selected Files..."), this, &GameList::ConvertFile);
menu->addSeparator();
}
if (std::all_of(selected_games.begin(), selected_games.end(),
[](const auto& game) { return DiscIO::IsWii(game->GetPlatform()); }))
if (std::ranges::all_of(selected_games,
[](const auto& game) { return DiscIO::IsWii(game->GetPlatform()); }))
{
menu->addAction(tr("Export Wii Saves"), this, &GameList::ExportWiiSave);
menu->addSeparator();

View File

@ -30,7 +30,7 @@ static bool IsValidUSBIDString(const std::string& string)
{
if (string.empty() || string.length() > 4)
return false;
return std::all_of(string.begin(), string.end(), Common::IsXDigit);
return std::ranges::all_of(string, Common::IsXDigit);
}
USBDeviceAddToWhitelistDialog::USBDeviceAddToWhitelistDialog(QWidget* parent) : QDialog(parent)