为什么 std::erase(std::erase_if) 不是 <algorithm> 中适用于任何容器的模板?

Why is std::erase(std::erase_if) not a template in <algorithm> that works on any container?

std::erase(_if) 是对 C++20 的一个很好的补充(我终于可以忘掉令人讨厌的擦除-删除习语),但有一点很奇怪: 从某种意义上说,它不是通用算法,它仅适用于 std:: 容器,例如它不能对升压向量进行操作。

    #include<string>

    #include<vector>

    #include<boost/container/vector.hpp>

    int main() {
        std::string str = " Hello World  !";
        std::erase(str, ' '); // :)
        boost::container::vector<int> vi{1,2};
        std::erase(vi, 2); // :(
    }

我最好的猜测是,该算法在概念被标准投票之前很久就处于实验阶段,因此对其进行返工需要大量工作,或者担心无法正确指定它的概念(即它将无法在某些具有古怪语义的用户定义类型上正常工作。

所以:我的问题是为什么这不是具有某些概念(或enable_if)的通用算法requirements/dispatching(例如map/set)?

原提案中已回答,N4009:

Q10. Instead of overloading erase_if() for each container, should you provide a single erase_if(Container&, Predicate) function template that's specified to do the right thing for each container?

A10. Such a general function template could be given user-defined containers. There aren't any "container traits", so it's impossible to determine whether a user-defined container is vector-like, list-like, map-like, or something else. User-defined containers could simply be rejected, but then the general function template wouldn't be doing anything differently than the set of specific overloads being proposed here. Note that an author of a user-defined container can overload erase_if() for their container in their namespace.

TL;DR: 因为没有办法写成这样 "Concept(or enable_if) requirements/dispatching".