std::erase, std::erase_if(std::basic_string)
来自cppreference.com
< cpp | string | basic string
在标头 <string> 定义
|
||
(1) | ||
template< class CharT, class Traits, class Alloc, class U > typename std::basic_string<CharT, Traits, Alloc>::size_type |
(C++20 起) (C++26 前) |
|
template< class CharT, class Traits, class Alloc, class U = CharT > constexpr typename std::basic_string<CharT, Traits, Alloc>::size_type |
(C++26 起) | |
template< class CharT, class Traits, class Alloc, class Pred > typename std::basic_string<CharT, Traits, Alloc>::size_type |
(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;。
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;。
auto it = std::remove_if(c.begin(), c.end(), pred);
auto r = c.end() - it;
c.erase(it, c.end());
return r;。
目录 |