std::experimental::erase_if (std::basic_string)
來自 cppreference.com
定義於標頭檔案 <experimental/string> |
||
template< class CharT, class Traits, class Alloc, class Pred > void erase_if( std::basic_string<CharT, Traits, Alloc>& c, Pred pred ); |
(庫基礎 TS v2) | |
從容器中擦除所有滿足謂詞 pred 的元素。等價於 c.erase(std::remove_if(c.begin(), c.end(), pred), c.end());。
目錄 |
[編輯] 引數
c | - | 要從中刪除元素的容器 |
pred | - | 決定哪些元素應該被擦除的謂詞 |
[編輯] 複雜度
線性。
[編輯] 示例
執行此程式碼
#include <experimental/string> #include <iomanip> #include <iostream> int main() { std::string data{"1337!p_C00L_<a-_HACKER_!@s_(!s#@_w^o%r*d#42"}; std::cout << "Original string: " << std::quoted(data) << '\n'; auto crack = [](auto O) { return '`' ^ ('`' & O); }; std::experimental::erase_if(data, crack); std::cout << "After erase_if: " << std::quoted(data) << '\n'; }
輸出
Original string: "1337!p_C00L_<a-_HACKER_!@s_{!s#@_w^o%r*d#42" After erase_if: "password"
[編輯] 參見
移除滿足特定標準的元素 (函式模板) | |
(庫基礎 2 TS) |
從 std::basic_string 中擦除所有等於特定值的元素 (函式模板) |