std::experi...sic_string)(3)
okay so bestie, welcome to the C++ Standard Libary manual β yes thatβs the spelling on the page, donβt @ me π β and this entry is std::experi...sic_string)(3). Itβs giving βexperimental string eraseβ and itβs lowkey iconic. π¦
π NAME π
std::experimental::erase_if(std::basic_string) - std::experimental::erase_if(std::basic_string)
Thatβs the name and the short description, periodt. π
β¨ Synopsis β¨
Defined in header <experimental/string>
template< class CharT, class Traits, class Alloc,
class Pred >
void erase_if( std::basic_string<CharT, Traits,
Alloc>& c, Pred pred );
This one is tagged (library fundamentals TS v2), iykyk. π«Ά
It erases all elements that satisfy the predicate pred from the container. Equivalent to c.erase(std::remove_if(c.begin(), c.end(), pred), c.end());.
πΈ Parameters πΈ
cβ container from which to erase. Itβs the main character losing elements.predβ predicate that determines which elements should be erased. Itβs the vibe check for each element.
π¦ Complexity π¦
Linear. No cap. β
π Example π
Run this code, bestie π
#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';
}
π Output π
Original string: "1337!p_C00L_<a-_HACKER_!@s_{!s#@_w^o%r*d#42"
After erase_if: "password"
π See also π
removeβ removes elements satisfying specific criteriaremove_ifβ (function template)erase (std::basic_string)(library fundamentals 2 TS) β erases all elements equal to a specific value from astd::basic_string(function template)
π Category π
Noindexed pages
source/version/date sign-off: http://cppreference.com, 2024.06.10, and page std::experi...sic_string)(3) β mwah, bestie, stay slaying those erases πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms