Use Util::keep_if()
MODIFY
src/commands_build.cpp
src/commands_build.cpp
#include "metrics.h"
#include "vcpkg_Enums.h"
#include "Paragraphs.h"
+#include "vcpkg_Util.h"
namespace vcpkg::Commands::Build
{
@@ -149,12 +150,10 @@ namespace vcpkg::Commands::Build
if (result == BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES)
{
std::vector<InstallPlanAction> unmet_dependencies = Dependencies::create_install_plan(paths, { spec }, status_db);
- unmet_dependencies.erase(
- std::remove_if(unmet_dependencies.begin(), unmet_dependencies.end(), [&spec](const InstallPlanAction& p)
+ Util::keep_if(unmet_dependencies, [&spec](const InstallPlanAction& p)
{
- return (p.spec == spec) || (p.plan_type == InstallPlanType::ALREADY_INSTALLED);
- }),
- unmet_dependencies.end());
+ return (p.spec != spec) && (p.plan_type != InstallPlanType::ALREADY_INSTALLED);
+ });
Checks::check_exit(VCPKG_LINE_INFO, !unmet_dependencies.empty());
System::println(System::Color::error, "The build command requires all dependencies to be already installed.");

MODIFY
src/commands_hash.cpp
src/commands_hash.cpp
#include "pch.h"
#include "vcpkg_Commands.h"
#include "vcpkg_System.h"
+#include "vcpkg_Util.h"
namespace vcpkg::Commands::Hash
{
@@ -20,7 +21,7 @@ namespace vcpkg::Commands::Hash
Checks::check_exit(VCPKG_LINE_INFO, end != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line));
auto hash = output.substr(start, end - start);
- hash.erase(std::remove_if(hash.begin(), hash.end(), isspace), hash.end());
+ Util::keep_if(hash, [](char c) {return !isspace(c); });
System::println(hash);
}

MODIFY
src/commands_integrate.cpp
src/commands_integrate.cpp
#include "vcpkg_Checks.h"
#include "vcpkg_System.h"
#include "vcpkg_Files.h"
+#include "vcpkg_Util.h"
namespace vcpkg::Commands::Integrate
{
@@ -66,10 +67,10 @@ namespace vcpkg::Commands::Integrate
dir_id.erase(1, 1); // Erasing the ":"
// NuGet id cannot have invalid characters. We will only use alphanumeric and dot.
- dir_id.erase(std::remove_if(dir_id.begin(), dir_id.end(), [](char c)
+ Util::keep_if(dir_id, [](char c)
{
- return !isalnum(c) && (c != '.');
- }), dir_id.end());
+ return isalnum(c) || (c == '.');
+ });
const std::string nuget_id = "vcpkg." + dir_id;
return nuget_id;

MODIFY
src/vcpkg_Dependencies.cpp
src/vcpkg_Dependencies.cpp
@@ -143,10 +143,10 @@ namespace vcpkg::Dependencies
const std::unordered_set<PackageSpec> specs_as_set(specs.cbegin(), specs.cend());
std::vector<InstallPlanAction> toposort = Graphs::topological_sort(specs, InstallAdjacencyProvider{ paths, status_db, specs_as_set });
- toposort.erase(std::remove_if(toposort.begin(), toposort.end(), [](const InstallPlanAction& p)
+ Util::keep_if(toposort, [](const InstallPlanAction& p)
{
- return p.request_type == RequestType::AUTO_SELECTED && p.plan_type == InstallPlanType::ALREADY_INSTALLED;
- }), toposort.end());
+ return !(p.request_type == RequestType::AUTO_SELECTED && p.plan_type == InstallPlanType::ALREADY_INSTALLED);
+ });
return toposort;
}

MODIFY
src/vcpkg_Strings.cpp
src/vcpkg_Strings.cpp
#include "pch.h"
#include "vcpkg_Strings.h"
+#include "vcpkg_Util.h"
namespace vcpkg::Strings::details
{
@@ -98,10 +99,10 @@ namespace vcpkg::Strings
trim(&s);
}
- strings->erase(std::remove_if(strings->begin(), strings->end(), [](const std::string& s)-> bool
+ Util::keep_if(*strings, [](const std::string& s)-> bool
{
- return s == "";
- }), strings->end());
+ return s != "";
+ });
}
std::vector<std::string> split(const std::string& s, const std::string& delimiter)

MODIFY
src/vcpkglib.cpp
src/vcpkglib.cpp
#include "Paragraphs.h"
#include "metrics.h"
#include "vcpkg_Strings.h"
+#include "vcpkg_Util.h"
namespace vcpkg
{
@@ -201,12 +202,10 @@ namespace vcpkg
upgrade_to_slash_terminated_sorted_format(&installed_files_of_current_pgh, listfile_path);
// Remove the directories
- installed_files_of_current_pgh.erase(
- std::remove_if(installed_files_of_current_pgh.begin(), installed_files_of_current_pgh.end(), [](const std::string& file) -> bool
+ Util::keep_if(installed_files_of_current_pgh, [](const std::string& file) -> bool
{
- return file.back() == '/';
- }
- ), installed_files_of_current_pgh.end());
+ return file.back() != '/';
+ });
StatusParagraphAndAssociatedFiles pgh_and_files = { *pgh, SortedVector<std::string>(std::move(installed_files_of_current_pgh)) };
installed_files.push_back(std::move(pgh_and_files));

Use Util::keep_if()