std::experi...std::deque)(3)
π std::experimental::erase(std::deque) π
okay bestie, so this page lives in the C++ Standard Library manual (yes, that one) β let me put you on to what it actually does π
β¨ NAME β¨
std::experimental::erase(std::deque) β literally just std::experimental::erase(std::deque), that's the whole name, she's not complicated π
πΈ SYNOPSIS πΈ
First things first, she's defined in header <experimental/deque> β go include it or she won't show up, and that's on periodt.
template< class T, class A, class U > (library fundamentals TS v2)
void erase( std::deque<T, A>& c, const U& value );
So what does she do? She erases all elements that compare equal to value from the container. That's the vibe check and some elements are failing it π
She's exactly equivalent to this line right here, no cap:
c.erase(std::remove(c.begin(), c.end(), value), c.end());.
it's giving erase-remove idiom but make it a one-liner π¦
π PARAMETERS π
cβ the container from which to erase, aka the deque we're cleaning out π§Ήvalueβ the value to be removed, aka the one getting evicted π
β COMPLEXITY β
Linear. That's it. That's the whole section. Lowkey iconic for how brief it is π
π₯ EXAMPLE π₯
// Run this code
#include <experimental/deque>
#include <iostream>
auto show = [](const auto& container)
{
for (auto e : container)
std::cout << e;
std::cout << '\n';
};
int main()
{
std::deque<int> data{1, 1, 1, 4, 1, 1, 1, 2, 1, 1, 1};
show(data);
std::experimental::erase(data, 1);
show(data);
}
look at that little lambda, she's so cute, she just prints everything with no separator and a newline at the end π«Ά
π OUTPUT π
11141112111
42
ok so the 1s got absolutely obliterated and only the 4 and the 2 survived π they really said main character energy and made it out alive π
π SEE ALSO π
removeβ removes elements satisfying specific criteriaremove_ifβ (function template)erase_if (std::deque)(library fundamentals 2 TS) β erases all elements satisfying a predicate from astd::deque(function template)
ngl bestie, remember this whole thing is under the library fundamentals TS v2 umbrella, so treat her as experimental, okay? that's literally in the name π
and that's the tea π β this page came from http://cppreference.com, dated 2024.06.10, under the title std::experi...std::deque)(3). go forth and erase β¨ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms