std::experi...e(std::list)(3)

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

πŸ’– std::experi...e(std::list)(3) πŸ’–

okay bestie, welcome to the C++ Standard Libary page for std::experimental::erase(std::list) β€” yes, that is literally the manual name up there, typo and all, and we are moving on with main-character energy πŸ’…βœ¨


πŸŽ€ NAME πŸŽ€

std::experimental::erase(std::list) - std::experimental::erase(std::list)


✨ Synopsis ✨

Defined in header <experimental/list>

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

Erases all elements that compare equal to value from the container. Equivalent to

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

πŸ¦‹ Parameters πŸ¦‹

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

⭐ Complexity ⭐

Linear. No cap, that is the whole vibe for this one ⭐


🌸 Example 🌸

// Run this code

#include <experimental/list>
#include <iostream>

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

int main()
{
    std::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::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 is the whole note, bestie β€” no extra lore, no invented side quests 🫢


πŸ‘‘ 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::list<T,Allocator>)
  • erase_if (std::list) β€” (library fundamentals 2 TS) erases all elements satisfying a predicate from a std::list (function template)

that’s the whole page, bestie 🫢 source is http://cppreference.com, dated 2024.06.10, and it’s the std::experi...e(std::list)(3) manual page β€” periodt πŸ’…βœ¨

πŸ“¦ where this page comes from