Date
2025-03-05.00:00:00
Message id
14670

Content

C++20 added std::vector::erase[_if]. Per [vector.erasure], these are equivalent to a call to std::remove[_if] followed by an appropriate erase.

This is unfortunate, because `std::remove_if` is specified (by [alg.remove]) as invoking its predicate as `pred(*i)`, while `std::ranges::remove_if` uses the more flexible `invoke(pred, invoke(proj, *i))`. Disregarding the projection, the latter allows the use of member function pointers as predicates, while the former does not.

I assume the committee intentionally did not change the non-ranges version to use `invoke` because it caused a backwards-compatibility risk. (If I am mistaken and this was an oversight, perhaps this and other non-ranges algorithms that take predicates should be updated to use invoke() to invoke them.)

If that's true, though, it's perplexing why a new-to-c++20 function like `std::vector::erase_if` should suffer the same drawback.