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:
parent
826e2bbf98
commit
860e6cf5cb
|
@ -24,7 +24,7 @@ struct Elt
|
|||
{
|
||||
bool IsZero() const
|
||||
{
|
||||
return std::all_of(data.begin(), data.end(), [](u8 b) { return b == 0; });
|
||||
return std::ranges::all_of(data, [](u8 b) { return b == 0; });
|
||||
}
|
||||
|
||||
void MulX()
|
||||
|
|
|
@ -729,7 +729,7 @@ static bool Unpack(const std::function<bool()>& cancelled, const std::string pat
|
|||
const bool is_path_traversal_attack =
|
||||
(childname.find("\\") != std::string_view::npos) ||
|
||||
(childname.find('/') != std::string_view::npos) ||
|
||||
std::all_of(childname.begin(), childname.end(), [](char c) { return c == '.'; });
|
||||
std::ranges::all_of(childname, [](char c) { return c == '.'; });
|
||||
if (is_path_traversal_attack)
|
||||
{
|
||||
ERROR_LOG_FMT(
|
||||
|
|
|
@ -113,7 +113,7 @@ static bool IsIllegalCharacter(char c)
|
|||
std::string EscapeFileName(const std::string& filename)
|
||||
{
|
||||
// Prevent paths from containing special names like ., .., ..., ...., and so on
|
||||
if (std::all_of(filename.begin(), filename.end(), [](char c) { return c == '.'; }))
|
||||
if (std::ranges::all_of(filename, [](char c) { return c == '.'; }))
|
||||
return ReplaceAll(filename, ".", "__2e__");
|
||||
|
||||
// Escape all double underscores since we will use double underscores for our escape sequences
|
||||
|
@ -170,8 +170,7 @@ std::string UnescapeFileName(const std::string& filename)
|
|||
|
||||
bool IsFileNameSafe(const std::string_view filename)
|
||||
{
|
||||
return !filename.empty() &&
|
||||
!std::all_of(filename.begin(), filename.end(), [](char c) { return c == '.'; }) &&
|
||||
return !filename.empty() && !std::ranges::all_of(filename, [](char c) { return c == '.'; }) &&
|
||||
std::none_of(filename.begin(), filename.end(), IsIllegalCharacter);
|
||||
}
|
||||
} // namespace Common
|
||||
|
|
|
@ -194,7 +194,7 @@ void DisplayMessage(std::string message, int time_in_ms)
|
|||
return;
|
||||
|
||||
// Actually displaying non-ASCII could cause things to go pear-shaped
|
||||
if (!std::all_of(message.begin(), message.end(), Common::IsPrintableCharacter))
|
||||
if (!std::ranges::all_of(message, Common::IsPrintableCharacter))
|
||||
return;
|
||||
|
||||
OSD::AddMessage(std::move(message), time_in_ms);
|
||||
|
|
|
@ -98,8 +98,8 @@ bool IOCtlVRequest::HasNumberOfValidVectors(const size_t in_count, const size_t
|
|||
return false;
|
||||
|
||||
auto IsValidVector = [](const auto& vector) { return vector.size == 0 || vector.address != 0; };
|
||||
return std::all_of(in_vectors.begin(), in_vectors.end(), IsValidVector) &&
|
||||
std::all_of(io_vectors.begin(), io_vectors.end(), IsValidVector);
|
||||
return std::ranges::all_of(in_vectors, IsValidVector) &&
|
||||
std::ranges::all_of(io_vectors, IsValidVector);
|
||||
}
|
||||
|
||||
void IOCtlRequest::Log(std::string_view device_name, Common::Log::LogType type,
|
||||
|
|
|
@ -298,7 +298,7 @@ std::string TMDReader::GetGameID() const
|
|||
std::memcpy(game_id, m_bytes.data() + offsetof(TMDHeader, title_id) + 4, 4);
|
||||
std::memcpy(game_id + 4, m_bytes.data() + offsetof(TMDHeader, group_id), 2);
|
||||
|
||||
if (std::all_of(std::begin(game_id), std::end(game_id), Common::IsPrintableCharacter))
|
||||
if (std::ranges::all_of(game_id, Common::IsPrintableCharacter))
|
||||
return std::string(game_id, sizeof(game_id));
|
||||
|
||||
return fmt::format("{:016x}", GetTitleId());
|
||||
|
|
|
@ -79,7 +79,7 @@ static bool IsValidPartOfTitleID(const std::string& string)
|
|||
{
|
||||
if (string.length() != 8)
|
||||
return false;
|
||||
return std::all_of(string.begin(), string.end(), Common::IsXDigit);
|
||||
return std::ranges::all_of(string, Common::IsXDigit);
|
||||
}
|
||||
|
||||
static std::vector<u64> GetTitlesInTitleOrImport(FS::FileSystem* fs, const std::string& titles_dir)
|
||||
|
|
|
@ -464,7 +464,7 @@ static bool HasAllRequiredContents(Kernel& ios, const ES::TMDReader& tmd)
|
|||
const u64 title_id = tmd.GetTitleId();
|
||||
const std::vector<ES::Content> contents = tmd.GetContents();
|
||||
const ES::SharedContentMap shared_content_map{ios.GetFSCore()};
|
||||
return std::all_of(contents.cbegin(), contents.cend(), [&](const ES::Content& content) {
|
||||
return std::ranges::all_of(contents, [&](const ES::Content& content) {
|
||||
if (content.IsOptional())
|
||||
return true;
|
||||
|
||||
|
|
|
@ -461,8 +461,7 @@ ResultCode HostFileSystem::Format(Uid uid)
|
|||
ResultCode HostFileSystem::CreateFileOrDirectory(Uid uid, Gid gid, const std::string& path,
|
||||
FileAttribute attr, Modes modes, bool is_file)
|
||||
{
|
||||
if (!IsValidNonRootPath(path) ||
|
||||
!std::all_of(path.begin(), path.end(), Common::IsPrintableCharacter))
|
||||
if (!IsValidNonRootPath(path) || !std::ranges::all_of(path, Common::IsPrintableCharacter))
|
||||
{
|
||||
return ResultCode::Invalid;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ static std::array<u8, 20> ConvertGitRevisionToBytes(const std::string& revision)
|
|||
{
|
||||
std::array<u8, 20> revision_bytes{};
|
||||
|
||||
if (revision.size() % 2 == 0 && std::all_of(revision.begin(), revision.end(), Common::IsXDigit))
|
||||
if (revision.size() % 2 == 0 && std::ranges::all_of(revision, Common::IsXDigit))
|
||||
{
|
||||
// The revision string normally contains a git commit hash,
|
||||
// which is 40 hexadecimal digits long. In DTM files, each pair of
|
||||
|
|
|
@ -2543,7 +2543,7 @@ bool NetPlayClient::DoAllPlayersHaveGame()
|
|||
{
|
||||
std::lock_guard lkp(m_crit.players);
|
||||
|
||||
return std::all_of(std::begin(m_players), std::end(m_players), [](auto entry) {
|
||||
return std::ranges::all_of(m_players, [](const auto& entry) {
|
||||
return entry.second.game_status == SyncIdentifierComparison::SameGame;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ static bool DecompressPacketIntoFolderInternal(sf::Packet& packet, const std::st
|
|||
if (name.find('\\') != std::string::npos)
|
||||
return false;
|
||||
#endif
|
||||
if (std::all_of(name.begin(), name.end(), [](char c) { return c == '.'; }))
|
||||
if (std::ranges::all_of(name, [](char c) { return c == '.'; }))
|
||||
return false;
|
||||
|
||||
bool is_folder;
|
||||
|
|
|
@ -1060,14 +1060,14 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
|
|||
{
|
||||
// we have all records for this frame
|
||||
|
||||
if (!std::all_of(timebases.begin(), timebases.end(), [&](std::pair<PlayerId, u64> pair) {
|
||||
if (!std::ranges::all_of(timebases, [&](std::pair<PlayerId, u64> pair) {
|
||||
return pair.second == timebases[0].second;
|
||||
}))
|
||||
{
|
||||
int pid_to_blame = 0;
|
||||
for (auto pair : timebases)
|
||||
{
|
||||
if (std::all_of(timebases.begin(), timebases.end(), [&](std::pair<PlayerId, u64> other) {
|
||||
if (std::ranges::all_of(timebases, [&](std::pair<PlayerId, u64> other) {
|
||||
return other.first == pair.first || other.second != pair.second;
|
||||
}))
|
||||
{
|
||||
|
@ -1467,14 +1467,12 @@ bool NetPlayServer::SetupNetSettings()
|
|||
|
||||
bool NetPlayServer::DoAllPlayersHaveIPLDump() const
|
||||
{
|
||||
return std::all_of(m_players.begin(), m_players.end(),
|
||||
[](const auto& p) { return p.second.has_ipl_dump; });
|
||||
return std::ranges::all_of(m_players, [](const auto& p) { return p.second.has_ipl_dump; });
|
||||
}
|
||||
|
||||
bool NetPlayServer::DoAllPlayersHaveHardwareFMA() const
|
||||
{
|
||||
return std::all_of(m_players.begin(), m_players.end(),
|
||||
[](const auto& p) { return p.second.has_hardware_fma; });
|
||||
return std::ranges::all_of(m_players, [](const auto& p) { return p.second.has_hardware_fma; });
|
||||
}
|
||||
|
||||
struct SaveSyncInfo
|
||||
|
|
|
@ -40,7 +40,7 @@ std::string NameForPartitionType(u32 partition_type, bool include_prefix)
|
|||
static_cast<char>((partition_type >> 16) & 0xFF),
|
||||
static_cast<char>((partition_type >> 8) & 0xFF),
|
||||
static_cast<char>(partition_type & 0xFF)};
|
||||
if (std::all_of(type_as_game_id.cbegin(), type_as_game_id.cend(), Common::IsAlnum))
|
||||
if (std::ranges::all_of(type_as_game_id, Common::IsAlnum))
|
||||
{
|
||||
return include_prefix ? "P-" + type_as_game_id : type_as_game_id;
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ FileDataLoaderHostFS::MakeAbsoluteFromRelative(std::string_view external_relativ
|
|||
result.pop_back();
|
||||
result.pop_back();
|
||||
}
|
||||
else if (std::all_of(element.begin(), element.end(), [](char c) { return c == '.'; }))
|
||||
else if (std::ranges::all_of(element, [](char c) { return c == '.'; }))
|
||||
{
|
||||
// This is a triple, quadruple, etc. dot.
|
||||
// Some file systems treat this as several 'up' path traversals, but Riivolution does not.
|
||||
|
|
|
@ -176,7 +176,7 @@ IOS::ES::TicketReader VolumeWAD::GetTicketWithFixedCommonKey() const
|
|||
return m_ticket;
|
||||
|
||||
const std::vector<u8> sig = m_ticket.GetSignatureData();
|
||||
if (!std::all_of(sig.cbegin(), sig.cend(), [](u8 a) { return a == 0; }))
|
||||
if (!std::ranges::all_of(sig, [](u8 a) { return a == 0; }))
|
||||
{
|
||||
// This does not look like a typical "invalid common key index" ticket, so let's assume
|
||||
// the index is correct. This saves some time when reading properly signed titles.
|
||||
|
|
|
@ -1126,7 +1126,7 @@ bool WIARVZFileReader<RVZ>::TryReuse(std::map<ReuseID, GroupEntry>* reusable_gro
|
|||
|
||||
static bool AllAre(const std::vector<u8>& data, u8 x)
|
||||
{
|
||||
return std::all_of(data.begin(), data.end(), [x](u8 y) { return x == y; });
|
||||
return std::ranges::all_of(data, [x](u8 y) { return x == y; });
|
||||
}
|
||||
|
||||
static bool AllAre(const u8* begin, const u8* end, u8 x)
|
||||
|
@ -1379,8 +1379,8 @@ WIARVZFileReader<RVZ>::ProcessAndCompress(CompressThreadState* state, CompressPa
|
|||
}
|
||||
}
|
||||
|
||||
if (!std::all_of(output_entries.begin(), output_entries.end(),
|
||||
[](const OutputParametersEntry& entry) { return entry.reused_group; }))
|
||||
if (!std::ranges::all_of(output_entries,
|
||||
[](const auto& entry) { return entry.reused_group.has_value(); }))
|
||||
{
|
||||
const u64 number_of_exception_lists =
|
||||
chunks_per_wii_group == 1 ? exception_lists_per_chunk : chunks;
|
||||
|
|
|
@ -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());
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -495,10 +495,8 @@ public:
|
|||
ControlState GetValue() const override
|
||||
{
|
||||
// True if we have no modifiers
|
||||
const bool modifiers_pressed = std::all_of(m_modifiers.begin(), m_modifiers.end(),
|
||||
[](const std::unique_ptr<ControlExpression>& input) {
|
||||
return input->GetValue() > CONDITION_THRESHOLD;
|
||||
});
|
||||
const bool modifiers_pressed = std::ranges::all_of(
|
||||
m_modifiers, [](const auto& input) { return input->GetValue() > CONDITION_THRESHOLD; });
|
||||
|
||||
const auto final_input_state = m_final_input->GetValueIgnoringSuppression();
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ IMUAccelerometer::IMUAccelerometer(std::string name_, std::string ui_name_)
|
|||
|
||||
bool IMUAccelerometer::AreInputsBound() const
|
||||
{
|
||||
return std::all_of(controls.begin(), controls.end(),
|
||||
[](const auto& control) { return control->control_ref->BoundCount() > 0; });
|
||||
return std::ranges::all_of(
|
||||
controls, [](const auto& control) { return control->control_ref->BoundCount() > 0; });
|
||||
}
|
||||
|
||||
std::optional<IMUAccelerometer::StateData> IMUAccelerometer::GetState() const
|
||||
|
|
|
@ -123,8 +123,8 @@ auto IMUGyroscope::GetRawState() const -> StateData
|
|||
|
||||
bool IMUGyroscope::AreInputsBound() const
|
||||
{
|
||||
return std::all_of(controls.begin(), controls.end(),
|
||||
[](const auto& control) { return control->control_ref->BoundCount() > 0; });
|
||||
return std::ranges::all_of(
|
||||
controls, [](const auto& control) { return control->control_ref->BoundCount() > 0; });
|
||||
}
|
||||
|
||||
bool IMUGyroscope::CanCalibrate() const
|
||||
|
|
|
@ -44,7 +44,7 @@ std::string GetExpressionForControl(const std::string& control_name,
|
|||
{
|
||||
// If our expression contains any non-alpha characters
|
||||
// we should quote it
|
||||
if (!std::all_of(expr.begin(), expr.end(), Common::IsAlpha))
|
||||
if (!std::ranges::all_of(expr, Common::IsAlpha))
|
||||
expr = fmt::format("`{}`", expr);
|
||||
}
|
||||
|
||||
|
|
|
@ -136,8 +136,7 @@ bool ProcessSpecificationV1(picojson::value& root, std::vector<Data>& input_text
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!std::all_of(region_offsets.begin(), region_offsets.end(),
|
||||
[](picojson::value val) { return val.is<double>(); }))
|
||||
if (!std::ranges::all_of(region_offsets, &picojson::value::is<double>))
|
||||
{
|
||||
ERROR_LOG_FMT(
|
||||
VIDEO,
|
||||
|
|
|
@ -63,8 +63,7 @@ bool ParseNumeric(const CustomAssetLibrary::AssetID& asset_id, const picojson::v
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!std::all_of(json_data.begin(), json_data.end(),
|
||||
[](const picojson::value& v) { return v.is<double>(); }))
|
||||
if (!std::ranges::all_of(json_data, &picojson::value::is<double>))
|
||||
{
|
||||
ERROR_LOG_FMT(VIDEO,
|
||||
"Asset id '{}' material has attribute '{}' where "
|
||||
|
|
|
@ -54,8 +54,7 @@ bool ParseNumeric(const CustomAssetLibrary::AssetID& asset_id, const picojson::v
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!std::all_of(json_data.begin(), json_data.end(),
|
||||
[](const picojson::value& v) { return v.is<double>(); }))
|
||||
if (!std::ranges::all_of(json_data, &picojson::value::is<double>))
|
||||
{
|
||||
ERROR_LOG_FMT(VIDEO,
|
||||
"Asset id '{}' shader has attribute '{}' where "
|
||||
|
|
Loading…
Reference in New Issue