std::experi...orward_list)(3)

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

πŸ’… NAME πŸ’…

okay so bestie, welcome to the std::experi...orward_list)(3) page from the C++ Standard Library manual. The whole mood is literally this, twice:

std::experimental::erase(std::forward_list) β€” std::experimental::erase(std::forward_list)

Yes, it says the name twice. That's the original page's energy, not me glitching. πŸ’€


✨ Synopsis ✨

Defined in header <experimental/forward_list>.

template< class T, class A, class U >
void erase( std::forward_list<T, A>& c, const U& value );

This is the (library fundamentals TS v2) version, and it erases all elements that compare equal to value from the container. It's equivalent to:

c.remove_if([&](auto& elem) { return elem == value; });

πŸŽ€ Parameters πŸŽ€

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

🌈 Complexity 🌈

Linear. That's the official complexity, no cap. ✨


πŸ“ Example πŸ“

// Run this code

#include <experimental/forward_list>
#include <iostream>

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

int main()
{
    std::forward_list<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

🫢 Notes 🫢

Unlike std::forward_list::remove, this function template accepts heterogeneous types and does not force a conversion to the container's value type before invoking the == operator.

That's the whole note, bestie. Lowkey important, fr fr. πŸ¦‹


πŸ‘‘ See also πŸ‘‘

  • remove β€” removes elements satisfying specific criteria
  • remove_if β€” (function template)
  • remove β€” removes elements satisfying specific criteria
  • remove_if β€” (public member function of std::forward_list<T,Allocator>)
  • erase_if (std::forward_list) (library fundamentals 2 TS) β€” erases all elements satisfying a predicate from a std::forward_list (function template)

source/version/date check: http://cppreference.com β€’ 2024.06.10 β€’ std::experi...orward_list)(3). That's the footer, bestie β€” now go forth and erase with main character energy. πŸ’…πŸ’–

πŸ“¦ where this page comes from