Skip to content

cleanup: replace erase-remove idiom with std::erase_if or absl::erase_if - #46663

Merged
wbpcode merged 2 commits into
envoyproxy:mainfrom
Amila-Rukshan:improve-readability
Aug 14, 2026
Merged

cleanup: replace erase-remove idiom with std::erase_if or absl::erase_if#46663
wbpcode merged 2 commits into
envoyproxy:mainfrom
Amila-Rukshan:improve-readability

Conversation

@Amila-Rukshan

@Amila-Rukshan Amila-Rukshan commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Description

Replace the traditional erase-remove idiom with the more concise std::erase_if and absl::erase_if APIs where applicable.

This improves readability by expressing the intent to remove elements matching a predicate directly, while preserving the existing behavior.

Changes

Replace std::remove_if followed by erase with std::erase_if for standard containers.
Replace the same pattern with absl::erase_if for supported Abseil containers.

No functional behavior changes are intended.

…ve idiom

Signed-off-by: Amila Senadheera <amilaruk1995@gmail.com>
@Amila-Rukshan

Copy link
Copy Markdown
Contributor Author

/retest

@Amila-Rukshan Amila-Rukshan changed the title Use convenient std::erase_if or absl::erase_if instead of erase-remove idiom cleanup: replace erase-remove idiom with std::erase_if or absl::erase_if Aug 12, 2026
@wbpcode
wbpcode requested a lite review from Copilot August 13, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes element-removal code paths across Envoy by replacing the erase-remove idiom with std::erase_if (for standard containers) and absl::erase_if (for Abseil containers), improving readability while aiming to preserve behavior.

Changes:

  • Replaced container.erase(std::remove_if(...), end()) with std::erase_if(container, pred) for standard containers.
  • Replaced the equivalent pattern with absl::erase_if(container, pred) for Abseil containers.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/server/config_validation/xds_verifier.cc Uses std::erase_if to remove listener entries marked REMOVED in both SOTW and delta update paths.
test/server/config_validation/xds_fuzz.cc Uses std::erase_if to remove listeners by name in fuzz test helper.
source/extensions/filters/http/cache_v2/cache_sessions_impl.cc Uses std::erase_if to remove out-of-range body subscribers while performing existing side effects.
source/extensions/clusters/dynamic_forward_proxy/cluster.cc Uses std::erase_if to remove draining connection entries from the per-key connection info vector.
source/extensions/bootstrap/reverse_tunnel/downstream_socket_interface/reverse_connection_io_handle.cc Uses std::erase_if to remove stale connection wrappers from the wrappers vector.
source/common/upstream/upstream_impl.cc Uses std::erase_if to prune host vectors in dynamic host list update logic.
source/common/upstream/cluster_manager_impl.cc Uses std::erase_if to remove hosts from hosts_added_ that are also in hosts_removed_.
source/common/http/http_server_properties_cache_impl.cc Uses std::erase_if to drop expired alternate protocols while preserving existing update behavior.
source/common/http/header_map_impl.h Switches removal on absl::InlinedVector to absl::erase_if (with a now-outdated explanatory comment).
source/common/event/evwatch_observer_manager_impl.cc Uses std::erase_if to purge nulled observer entries from the observer list.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread source/common/http/header_map_impl.h Outdated

@botengyao botengyao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the improvement, lgtm module the nit.

/wait

Comment thread source/common/http/header_map_impl.h Outdated
Signed-off-by: Amila Senadheera <amilaruk1995@gmail.com>
@Amila-Rukshan

Copy link
Copy Markdown
Contributor Author

@botengyao, @wbpcode, I have addressed the nit.

@wbpcode
wbpcode merged commit 242be89 into envoyproxy:main Aug 14, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants