libstdc++: Call predicate with non-const values in std::erase_if [PR107850]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 24 Nov 2022 21:09:03 +0000 (21:09 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 25 Nov 2022 15:06:25 +0000 (15:06 +0000)
commitf54ceb2062c7fef294f85ae093914fa6c7ca35b8
tree8e935211c279fc7accbe99a5d6fdcc23d59f065d
parent48e4a9d93885b3d82cfcbf1e804fe9c3eaabf157
libstdc++: Call predicate with non-const values in std::erase_if [PR107850]

As specified in the standard, the predicate for std::erase_if has to be
invocable as non-const with a non-const lvalues argument. Restore
support for predicates that only accept non-const arguments.

It's not strictly nevessary to change it for the set and unordered_set
overloads, because they only give const access to the elements anyway.
I've done it for them too just to keep them all consistent.

libstdc++-v3/ChangeLog:

PR libstdc++/107850
* include/bits/erase_if.h (__erase_nodes_if): Use non-const
reference to the container.
* include/experimental/map (erase_if): Likewise.
* include/experimental/set (erase_if): Likewise.
* include/experimental/unordered_map (erase_if): Likewise.
* include/experimental/unordered_set (erase_if): Likewise.
* include/std/map (erase_if): Likewise.
* include/std/set (erase_if): Likewise.
* include/std/unordered_map (erase_if): Likewise.
* include/std/unordered_set (erase_if): Likewise.
* testsuite/23_containers/map/erasure.cc: Check with
const-incorrect predicate.
* testsuite/23_containers/set/erasure.cc: Likewise.
* testsuite/23_containers/unordered_map/erasure.cc: Likewise.
* testsuite/23_containers/unordered_set/erasure.cc: Likewise.
* testsuite/experimental/map/erasure.cc: Likewise.
* testsuite/experimental/set/erasure.cc: Likewise.
* testsuite/experimental/unordered_map/erasure.cc: Likewise.
* testsuite/experimental/unordered_set/erasure.cc: Likewise.
17 files changed:
libstdc++-v3/include/bits/erase_if.h
libstdc++-v3/include/experimental/map
libstdc++-v3/include/experimental/set
libstdc++-v3/include/experimental/unordered_map
libstdc++-v3/include/experimental/unordered_set
libstdc++-v3/include/std/map
libstdc++-v3/include/std/set
libstdc++-v3/include/std/unordered_map
libstdc++-v3/include/std/unordered_set
libstdc++-v3/testsuite/23_containers/map/erasure.cc
libstdc++-v3/testsuite/23_containers/set/erasure.cc
libstdc++-v3/testsuite/23_containers/unordered_map/erasure.cc
libstdc++-v3/testsuite/23_containers/unordered_set/erasure.cc
libstdc++-v3/testsuite/experimental/map/erasure.cc
libstdc++-v3/testsuite/experimental/set/erasure.cc
libstdc++-v3/testsuite/experimental/unordered_map/erasure.cc
libstdc++-v3/testsuite/experimental/unordered_set/erasure.cc