std::experi...asic_string)(3)

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

🌸 NAME 🌸

okay so bestie, this page is std::experi...asic_string)(3), folded in from the C++ Standard Libary manual (yes, "Libary," that's the header's spelling, no cap πŸ’…). NAME says std::experimental::erase(std::basic_string) - std::experimental::erase(std::basic_string) β€” yes, twice, and we love a repetitive queen. It's defined in header <experimental/string>. πŸŽ€

✨ Synopsis ✨

Defined in header <experimental/string>:

template< class CharT, class Traits, class A, class U
>                                                       (library
fundamentals TS v2)
void erase( std::basic_string<CharT, Traits, A>& c,
const U& value );

This one is tagged (library fundamentals TS v2), bestie. It erases all elements that compare equal to value from the container. Equivalent to:

c.erase(std::remove(c.begin(), c.end(), value), c.end());

πŸ’– Parameters πŸ’–

  • c β€” container from which to erase.
  • value β€” value to be removed.

πŸ”₯ Complexity πŸ”₯

Linear. Simple, clean, iconic. ✨

🧚 Example 🧚

// Run this code

#include <experimental/string>
#include <iostream>

int main()
{
    std::string data{"$$P$A$S$S$$W$O$R$$D$"};
    std::cout << data << '\n';
    auto crack{'$'};
    std::experimental::erase(data, crack);
    std::cout << data << '\n';
}

πŸ‘‘ Output: πŸ‘‘

$$P$A$S$S$$W$O$R$$D$
PASSWORD

πŸ¦‹ See also πŸ¦‹

  • remove β€” removes elements satisfying specific criteria.
  • remove_if β€” (function template).
  • erase_if (std::basic_string) β€” erases all elements satisfying a predicate from a std::basic_string (library fundamentals 2 TS) (function template).

cute sign-off: source/version is cppreference.com, 2024.06.10. stay slay, bestie πŸ’…πŸ«Ά

πŸ“¦ where this page comes from