# std::experimental::erase_if (std::basic_string)

< cpp‎ | experimental

定义于头文件 `<experimental/string>` |  |
template <..., class Pred> void erase_if(std::basic_string<...>& c, Pred pred); |  | (库基础 TS v2)

从容器擦除所有满足谓词 `pred` 的元素。等价于 c.erase(std::remove_if(c.begin(), c.end(), pred), c.end());

### 参数

c | - | 要从中擦除的容器
pred | - | 确定该擦除哪些元素的谓词

### 复杂度

线性。

### 示例

    #include <experimental/string>
    #include <iostream>

    int main()
    {
        std::string data { "1337!p_C00L_<a-_HACKER_!@s_{!s#@_w^o%r*d#42" };

        std::cout << "Original: \n\"" << data << "\"\n";

        auto crack = [](auto O) { return O < 0141 or 0172 < O; };

        std::experimental::erase_if(data, crack);

        std::cout << "After erase_if: \n\"" << data << "\"\n";
    }

输出：

    Original:
    "1337!p_C00L_<a-_HACKER_!@s_{!s#@_w^o%r*d#42"
    After erase_if:
    "password"

### 参阅

remove remove_if | 移除满足特定判别标准的元素 (函数模板)
erase(std::basic_string) (库基础 2 TS) | 从 std::basic_string 擦除所有等于特定值的元素 (函数模板)