<s>
The	O
erase	B-Language
–	I-Language
remove	I-Language
idiom	I-Language
is	O
a	O
common	O
C++	B-Language
technique	O
to	O
eliminate	O
elements	O
that	O
fulfill	O
a	O
certain	O
criterion	O
from	O
a	O
C++	B-Language
Standard	I-Language
Library	I-Language
container	B-Application
.	O
</s>
<s>
A	O
common	O
programming	O
task	O
is	O
to	O
remove	O
all	O
elements	O
that	O
have	O
a	O
certain	O
value	O
or	O
fulfill	O
a	O
certain	O
criterion	O
from	O
a	O
collection	B-Application
.	O
</s>
<s>
In	O
C++	B-Language
,	O
this	O
can	O
be	O
achieved	O
using	O
a	O
hand-written	O
loop	O
.	O
</s>
<s>
It	O
is	O
,	O
however	O
,	O
preferable	O
to	O
use	O
an	O
algorithm	O
from	O
the	O
C++	B-Language
Standard	I-Language
Library	I-Language
for	O
such	O
tasks	O
.	O
</s>
<s>
The	O
member	O
function	O
erase	O
can	O
be	O
used	O
to	O
delete	O
an	O
element	O
from	O
a	O
collection	B-Application
,	O
but	O
for	O
containers	B-Application
which	O
are	O
based	O
on	O
an	O
array	O
,	O
such	O
as	O
vector	O
,	O
all	O
elements	O
after	O
the	O
deleted	O
element	O
have	O
to	O
be	O
moved	O
forward	O
to	O
avoid	O
"	O
gaps	O
"	O
in	O
the	O
collection	B-Application
.	O
</s>
<s>
Calling	O
erase	O
multiple	O
times	O
on	O
the	O
same	O
container	B-Application
generates	O
much	O
overhead	O
from	O
moving	O
the	O
elements	O
.	O
</s>
<s>
Because	O
these	O
algorithms	O
operate	O
on	O
a	O
range	O
of	O
elements	O
denoted	O
by	O
two	O
forward	O
iterators	O
,	O
they	O
have	O
no	O
knowledge	O
of	O
the	O
underlying	O
container	B-Application
or	O
collection	B-Application
.	O
</s>
<s>
These	O
algorithms	O
do	O
not	O
remove	O
elements	O
from	O
the	O
container	B-Application
,	O
but	O
move	O
all	O
elements	O
that	O
do	O
not	O
fit	O
the	O
removal	O
criteria	O
to	O
the	O
front	O
of	O
the	O
range	O
,	O
keeping	O
the	O
relative	O
order	O
of	O
the	O
elements	O
.	O
</s>
<s>
As	O
no	O
elements	O
are	O
actually	O
removed	O
and	O
the	O
container	B-Application
retains	O
the	O
same	O
size	O
,	O
the	O
tail	O
of	O
the	O
array	O
has	O
a	O
length	O
equal	O
to	O
the	O
number	O
of	O
"	O
removed	O
"	O
items	O
;	O
these	O
items	O
remain	O
in	O
memory	O
but	O
in	O
an	O
unspecified	O
state	O
.	O
</s>
<s>
As	O
of	O
C++20	O
,	O
the	O
free	O
functions	O
std::erase	O
and	O
std::erase_if	O
are	O
provided	O
for	O
STL	O
containers	B-Application
.	O
</s>
<s>
These	O
convenience	O
functions	O
can	O
be	O
used	O
to	O
perform	O
correct	O
erasure	O
of	O
elements	O
without	O
requiring	O
the	O
programmer	O
to	O
explicitly	O
use	O
the	O
erase-remove	B-Language
idiom	I-Language
.	O
</s>
<s>
The	O
erase	B-Language
–	I-Language
remove	I-Language
idiom	I-Language
cannot	O
be	O
used	O
for	O
containers	B-Application
that	O
return	O
const_iterator	O
(	O
e.g.	O
</s>
<s>
Thus	O
,	O
erase	O
–	O
remove	O
can	O
only	O
be	O
used	O
with	O
containers	B-Application
holding	O
elements	O
with	O
full	O
value	O
semantics	O
without	O
incurring	O
resource	O
leaks	O
.	O
</s>
