std::experi...std::vector)(3)

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

✨ NAME ✨

okay bestie, real talk: this page is from the C++ Standard Libary manual β€” yes, Libary, that's how it's spelled, don't come for me β€” and the page handle is std::experi...std::vector)(3). The function is literally called std::experimental::erase(std::vector), and the one-line description is also std::experimental::erase(std::vector). Repetitive? Maybe. Iconic? Absolutely. πŸ’…

πŸ¦‹ Synopsis πŸ¦‹

Defined in header <experimental/vector>.

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

This one erases all elements that compare equal to value from the container. Equivalent to c.erase(std::remove(c.begin(), c.end(), value), c.end());. (Yes, the original has that lil period at the end of the code, I'm not gonna gaslight you about it. πŸ™ˆ)

🌸 Parameters 🌸

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

πŸ”₯ Complexity πŸ”₯

Linear. β€” that's it, that's the whole vibe check. πŸ’€

πŸŽ€ Example πŸŽ€

Run this code, bestie:

// Run this code

#include <experimental/vector>
#include <iostream>

auto show = [](const auto& container)
{
    for (auto e : container)
        std::cout << e;
    std::cout << '\n';
};

int main()
{
    std::vector<int> data{1, 1, 1, 4, 1, 1, 1, 2, 1, 1, 1};
    show(data);
    std::experimental::erase(data, 1);
    show(data);
}

🌈 Output: 🌈

11141112111
42

πŸ‘‘ See also πŸ‘‘

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

mwah πŸ’‹ β€” source/version: http://cppreference.com, date: 2024.06.10. periodt. 🫢

πŸ“¦ where this page comes from