]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Simplify std::erase functions for sequence containers
authorJonathan Wakely <jwakely@redhat.com>
Fri, 19 Sep 2025 15:03:11 +0000 (16:03 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 26 Sep 2025 10:05:54 +0000 (11:05 +0100)
commitb83c2e52a21c1882a149e89e5ab152c09a73fb30
tree309e60929f15f3723c579d2010776c79d9d0f28f
parentaaeca77a79a9a897c97f00f83f2471e7a8bd6685
libstdc++: Simplify std::erase functions for sequence containers

This removes the use of std::ref that meant that __remove_if used an
indirection through the reference, which might be a pessimization. Users
can always use std::ref to pass expensive predicates into erase_if, but
we shouldn't do it unconditionally. We can std::move the predicate so
that if it's not cheap to copy and the user didn't use std::ref, then we
try to use a cheaper move instead of a copy.

There's no reason that std::erase shouldn't just be implemented by
forwarding to std::erase_if. I probably should have done that in
r12-4083-gacf3a21cbc26b3 when std::erase started to call __remove_if
directly.

libstdc++-v3/ChangeLog:

* include/std/deque (erase_if): Move predicate instead of
wrapping with std::ref.
(erase): Forward to erase_if.
* include/std/inplace_vector (erase_if, erase): Likewise.
* include/std/string (erase_if, erase): Likewise.
* include/std/vector (erase_if, erase): Likewise.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
libstdc++-v3/include/std/deque
libstdc++-v3/include/std/inplace_vector
libstdc++-v3/include/std/string
libstdc++-v3/include/std/vector