A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../ranges/../string/basic_string/erase2.html below:

std::erase, std::erase_if(std::basic_string) - cppreference.com

(1) template< class CharT, class Traits, class Alloc, class U >

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

    erase( std::basic_string<CharT, Traits, Alloc>& c, const U& value );
(since C++20)
(until 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 );
(since C++26) template< class CharT, class Traits, class Alloc, class Pred >

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

    erase_if( std::basic_string<CharT, Traits, Alloc>& c, Pred pred );
(2) (since C++20)

1) Erases all elements that compare equal to value from the container c. Equivalent to auto it = std::remove(c.begin(), c.end(), value);
auto r = c.end() - it;
c.erase(it, c.end());
return r;
.

2)

Erases all elements that satisfy the predicate

pred

from the container

c

. Equivalent to

auto it = std::remove_if(c.begin(), c.end(), pred);
auto r = c.end() - it;
c.erase(it, c.end());
return r;

.

[edit] Parameters c - container from which to erase value - value to be removed pred - unary predicate which returns ​true if the element should be erased.

The expression pred(v) must be convertible to bool for every argument v of type (possibly const) CharT, regardless of value category, and must not modify v. Thus, a parameter type of CharT&is not allowed, nor is CharT unless for CharT a move is equivalent to a copy(since C++11). ​

[edit] Return value

The number of erased elements.

[edit] Complexity

Linear.

Notes [edit] Example

Possible output:

Initially, word = "startling"
After erase 'l', word = "starting"
After erase all 'a', 'r', and 't': "sing"
Erased symbols count: 4
After erase {'g'}: "sin"
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4