std::erase, std::erase_if(std::basic_string)

来自cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
常量
非成员函数
erase(std::basic_string)erase_if(std::basic_string)
(C++20)(C++20)
I/O
比较
(C++20 前)(C++20 前)(C++20 前)(C++20 前)(C++20 前)(C++20)
数值转换
(C++11)(C++11)(C++11)
(C++11)(C++11) 
(C++11)(C++11)(C++11)
(C++11)
(C++11)
字面量
辅助类
推导指引 (C++17)
 
在标头 <string> 定义
(1)
template< class CharT, class Traits, class Alloc, class U >

typename std::basic_string<CharT, Traits, Alloc>::size_type

    erase( std::basic_string<CharT, Traits, Alloc>& c, const U& value );
(C++20 起)
(C++26 前)
template< class CharT, class Traits, class Alloc, class U = CharT >

constexpr typename std::basic_string<CharT, Traits, Alloc>::size_type

    erase( std::basic_string<CharT, Traits, Alloc>& c, const U& value );
(C++26 起)
template< class CharT, class Traits, class Alloc, class Pred >

typename std::basic_string<CharT, Traits, Alloc>::size_type

    erase_if( std::basic_string<CharT, Traits, Alloc>& c, Pred pred );
(2) (C++20 起)
1) 从容器 c 中擦除所有比较等于 value 的元素。等价于
auto it = std::remove(c.begin(), c.end(), value);
auto r = c.end() - it;
c.erase(it, c.end());
return r;
2) 从容器 c 中擦除所有满足 pred 的元素。等价于
auto it = std::remove_if(c.begin(), c.end(), pred);
auto r = c.end() - it;
c.erase(it, c.end());
return r;

目录

[