Skip to content

Commit aedde45

Browse files
committed
Modernize erase-remove idiom to C++20 std::erase/std::erase_if
Replace traditional erase-remove idiom usage on standard containers with C++20 std::erase and std::erase_if across the cuttlefish package. Assisted-by: Jetski:Gemini Next
1 parent f7d32f3 commit aedde45

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

base/cvd/cuttlefish/host/commands/cvd/cli/parser/test_common.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ bool FindConfig(const std::vector<std::string>& vec,
3737
bool FindConfigIgnoreSpaces(const std::vector<std::string>& vec,
3838
const std::string& str) {
3939
std::string target = str;
40-
target.erase(std::remove(target.begin(), target.end(), ' '), target.end());
41-
target.erase(std::remove(target.begin(), target.end(), '\t'), target.end());
40+
std::erase(target, ' ');
41+
std::erase(target, '\t');
4242

4343
for (const auto& s : vec) {
4444
std::string current = s;
45-
current.erase(std::remove(current.begin(), current.end(), ' '),
46-
current.end());
47-
current.erase(std::remove(current.begin(), current.end(), '\t'),
48-
current.end());
45+
std::erase(current, ' ');
46+
std::erase(current, '\t');
4947
if (current == target) {
5048
return true;
5149
}

base/cvd/cuttlefish/host/commands/process_sandboxer/sandbox_manager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,8 @@ class SandboxManager::SocketClient {
305305
if (!env.ok()) {
306306
return env.status();
307307
}
308-
fds->erase(
309-
std::remove_if(fds->begin(), fds->end(),
310-
[this](auto& arg) { return arg.second == ignored_fd_; }),
311-
fds->end());
308+
std::erase_if(*fds,
309+
[this](auto& arg) { return arg.second == ignored_fd_; });
312310
return manager_.RunProcess(client_fd_.get(), std::move(*argv),
313311
std::move(*fds), *env);
314312
}

0 commit comments

Comments
 (0)