std::experi...sic_string)(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

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 criteria
  • remove_if β€” (function template)
  • erase (std::basic_string) (library fundamentals 2 TS) β€” erases all elements equal to a specific value from a std::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