<s>
The	O
Standard	O
Template	B-Application
Library	O
(	O
STL	O
)	O
is	O
a	O
software	B-Library
library	I-Library
originally	O
designed	O
by	O
Alexander	O
Stepanov	O
for	O
the	O
C++	B-Language
programming	I-Language
language	I-Language
that	O
influenced	O
many	O
parts	O
of	O
the	O
C++	B-Language
Standard	I-Language
Library	I-Language
.	O
</s>
<s>
It	O
provides	O
four	O
components	O
called	O
algorithms	O
,	O
containers	B-Application
,	O
functions	B-Language
,	O
and	O
iterators	O
.	O
</s>
<s>
The	O
STL	O
provides	O
a	O
set	O
of	O
common	O
classes	B-Application
for	O
C++	B-Language
,	O
such	O
as	O
containers	B-Application
and	O
associative	B-Application
arrays	I-Application
,	O
that	O
can	O
be	O
used	O
with	O
any	O
built-in	O
type	O
and	O
with	O
any	O
user-defined	O
type	O
that	O
supports	O
some	O
elementary	O
operations	O
(	O
such	O
as	O
copying	O
and	O
assignment	O
)	O
.	O
</s>
<s>
STL	O
algorithms	O
are	O
independent	O
of	O
containers	B-Application
,	O
which	O
significantly	O
reduces	O
the	O
complexity	O
of	O
the	O
library	O
.	O
</s>
<s>
The	O
STL	O
achieves	O
its	O
results	O
through	O
the	O
use	O
of	O
templates	B-Application
.	O
</s>
<s>
This	O
approach	O
provides	O
compile-time	B-Language
polymorphism	I-Language
that	O
is	O
often	O
more	O
efficient	O
than	O
traditional	O
run-time	B-Application
polymorphism	I-Application
.	O
</s>
<s>
Modern	O
C++	B-Language
compilers	B-Language
are	O
tuned	O
to	O
minimize	O
abstraction	B-Application
penalties	O
arising	O
from	O
heavy	O
use	O
of	O
the	O
STL	O
.	O
</s>
<s>
The	O
STL	O
was	O
created	O
as	O
the	O
first	O
library	O
of	O
generic	B-Language
algorithms	I-Language
and	O
data	O
structures	O
for	O
C++	B-Language
,	O
with	O
four	O
ideas	O
in	O
mind	O
:	O
generic	B-Language
programming	I-Language
,	O
abstractness	B-Application
without	O
loss	O
of	O
efficiency	O
,	O
the	O
Von	B-Architecture
Neumann	I-Architecture
computation	I-Architecture
model	I-Architecture
,	O
and	O
value	B-Application
semantics	I-Application
.	O
</s>
<s>
The	O
STL	O
and	O
the	O
C++	B-Language
Standard	I-Language
Library	I-Language
are	O
two	O
distinct	O
entities	O
.	O
</s>
<s>
In	O
November	O
1993	O
Alexander	O
Stepanov	O
presented	O
a	O
library	O
based	O
on	O
generic	B-Language
programming	I-Language
to	O
the	O
ANSI/ISO	O
committee	O
for	O
C++	B-Language
standardization	O
.	O
</s>
<s>
The	O
requirements	O
for	O
the	O
most	O
significant	O
extension	O
(	O
associative	B-Application
containers	I-Application
)	O
had	O
to	O
be	O
shown	O
to	O
be	O
consistent	O
by	O
fully	O
implementing	O
them	O
,	O
a	O
task	O
Stepanov	O
delegated	O
to	O
David	O
Musser	O
.	O
</s>
<s>
Subsequently	O
,	O
the	O
Stepanov	O
and	O
Lee	O
document	O
17	O
was	O
incorporated	O
into	O
the	O
ANSI/ISO	O
C++	B-Language
draft	O
standard	O
(	O
1	O
,	O
parts	O
of	O
clauses	O
17	O
through	O
27	O
)	O
.	O
</s>
<s>
This	O
implementation	O
,	O
developed	O
by	O
Stepanov	O
,	O
Lee	O
,	O
and	O
Musser	O
during	O
the	O
standardization	O
process	O
,	O
became	O
the	O
basis	O
of	O
many	O
implementations	O
offered	O
by	O
compiler	B-Language
and	O
library	O
vendors	O
today	O
.	O
</s>
<s>
The	O
STL	O
contains	O
sequence	O
containers	B-Application
and	O
associative	B-Application
containers	I-Application
.	O
</s>
<s>
The	O
containers	B-Application
are	O
objects	O
that	O
store	O
data	O
.	O
</s>
<s>
The	O
standard	O
sequence	O
containers	B-Application
include	O
,	O
,	O
and	O
.	O
</s>
<s>
The	O
standard	O
associative	B-Application
containers	I-Application
are	O
,	O
,	O
,	O
,	O
,	O
,	O
and	O
.	O
</s>
<s>
There	O
are	O
also	O
container	B-Application
adaptors	O
,	O
,	O
and	O
,	O
that	O
are	O
containers	B-Application
with	O
specific	O
interface	O
,	O
using	O
other	O
containers	B-Application
as	O
implementation	O
.	O
</s>
<s>
|	O
The	O
pair	O
container	B-Application
is	O
a	O
simple	O
associative	B-Application
container	I-Application
consisting	O
of	O
a	O
2-tuple	O
of	O
data	O
elements	O
or	O
objects	O
,	O
called	O
'	O
first	O
 '	O
and	O
'	O
second	O
 '	O
,	O
in	O
that	O
fixed	O
order	O
.	O
</s>
<s>
The	O
array	O
of	O
objects	O
allocated	O
in	O
a	O
map	B-Language
or	O
hash_map	B-Language
(	O
described	O
below	O
)	O
are	O
of	O
type	O
'	O
pair	O
 '	O
by	O
default	O
,	O
where	O
all	O
the	O
'	O
first	O
 '	O
elements	O
act	O
as	O
the	O
unique	O
keys	O
,	O
each	O
associated	O
with	O
their	O
'	O
second	O
 '	O
value	O
objects	O
.	O
</s>
<s>
|	O
a	O
dynamic	B-Data_Structure
array	I-Data_Structure
,	O
like	O
C	B-Language
array	O
(	O
i.e.	O
,	O
capable	O
of	O
random	B-General_Concept
access	I-General_Concept
)	O
with	O
the	O
ability	O
to	O
resize	O
itself	O
automatically	O
when	O
inserting	O
or	O
erasing	O
an	O
object	O
.	O
</s>
<s>
Inserting	O
an	O
element	O
to	O
the	O
back	O
of	O
the	O
vector	O
at	O
the	O
end	O
takes	O
amortized	B-General_Concept
constant	I-General_Concept
time	I-General_Concept
.	O
</s>
<s>
|	O
a	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
;	O
elements	O
are	O
not	O
stored	O
in	O
contiguous	O
memory	O
.	O
</s>
<s>
|	O
a	O
singly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
;	O
elements	O
are	O
not	O
stored	O
in	O
contiguous	O
memory	O
.	O
</s>
<s>
It	O
has	O
slightly	O
more	O
efficient	O
insertion	O
and	O
deletion	O
,	O
and	O
uses	O
less	O
memory	O
than	O
a	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
,	O
but	O
can	O
only	O
be	O
iterated	O
forwards	O
.	O
</s>
<s>
It	O
is	O
implemented	O
in	O
the	O
C++	B-Language
standard	I-Language
library	I-Language
as	O
.	O
</s>
<s>
|a	O
vector	O
with	O
insertion/erase	O
at	O
the	O
beginning	O
or	O
end	O
in	O
amortized	B-General_Concept
constant	I-General_Concept
time	I-General_Concept
,	O
however	O
lacking	O
some	O
guarantees	O
on	O
iterator	O
validity	O
after	O
altering	O
the	O
deque	B-Application
.	O
</s>
<s>
|	O
Provides	O
FIFO	B-Operating_System
queue	B-Application
interface	O
in	O
terms	O
of	O
///	O
operations	O
.	O
</s>
<s>
Any	O
sequence	O
supporting	O
operations	O
,	O
,	O
,	O
and	O
can	O
be	O
used	O
to	O
instantiate	O
queue	B-Application
(	O
e.g.	O
</s>
<s>
|	O
Provides	O
priority	B-Application
queue	I-Application
interface	O
in	O
terms	O
of	O
operations	O
(	O
the	O
element	O
with	O
the	O
highest	O
priority	O
is	O
on	O
top	O
)	O
.	O
</s>
<s>
Any	O
random-access	B-General_Concept
sequence	O
supporting	O
operations	O
,	O
,	O
and	O
can	O
be	O
used	O
to	O
instantiate	O
priority_queue	O
(	O
e.g.	O
</s>
<s>
It	O
is	O
implemented	O
using	O
a	O
heap	B-Application
.	O
</s>
<s>
|	O
Provides	O
LIFO	B-Application
stack	B-Application
interface	O
in	O
terms	O
of	O
operations	O
(	O
the	O
last-inserted	O
element	O
is	O
on	O
top	O
)	O
.	O
</s>
<s>
Any	O
sequence	O
supporting	O
operations	O
,	O
,	O
and	O
can	O
be	O
used	O
to	O
instantiate	O
stack	B-Application
(	O
e.g.	O
</s>
<s>
Typically	O
implemented	O
using	O
a	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
|	O
same	O
as	O
a	O
set	O
,	O
but	O
allows	O
duplicate	O
elements	O
(	O
mathematical	O
multiset	B-Language
)	O
.	O
</s>
<s>
|	O
an	O
associative	B-Application
array	I-Application
;	O
allows	O
mapping	O
from	O
one	O
data	O
item	O
(	O
a	O
key	O
)	O
to	O
another	O
(	O
a	O
value	O
)	O
.	O
</s>
<s>
Typically	O
implemented	O
using	O
a	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
|	O
same	O
as	O
a	O
map	B-Language
,	O
but	O
allows	O
duplicate	O
keys	O
.	O
</s>
<s>
|	O
similar	O
to	O
a	O
set	O
,	O
multiset	B-Language
,	O
map	B-Language
,	O
or	O
multimap	B-Language
,	O
respectively	O
,	O
but	O
implemented	O
using	O
a	O
hash	B-Algorithm
table	I-Algorithm
;	O
keys	O
are	O
not	O
ordered	O
,	O
but	O
a	O
hash	B-Error_Name
function	I-Error_Name
must	O
exist	O
for	O
the	O
key	O
type	O
.	O
</s>
<s>
These	O
types	O
were	O
left	O
out	O
of	O
the	O
C++	B-Language
standard	O
;	O
similar	O
containers	B-Application
were	O
standardized	O
in	O
C++11	B-Language
,	O
but	O
with	O
different	O
names	O
(	O
and	O
)	O
.	O
</s>
<s>
Provides	O
random	B-General_Concept
access	I-General_Concept
.	O
</s>
<s>
|	O
Another	O
array	O
data	O
type	O
,	O
intended	O
for	O
numerical	O
use	O
(	O
especially	O
to	O
represent	O
vectors	O
and	O
matrices	B-Architecture
)	O
;	O
the	O
C++	B-Language
standard	O
allows	O
specific	O
optimizations	O
for	O
this	O
intended	O
purpose	O
.	O
</s>
<s>
According	O
to	O
Josuttis	O
,	O
was	O
badly	O
designed	O
,	O
by	O
people	O
"	O
who	O
left	O
the	O
[	O
C++	B-Language
standard ]	O
committee	O
a	O
long	O
time	O
before	O
the	O
standard	O
was	O
finished	O
"	O
,	O
and	O
expression	B-Application
template	I-Application
libraries	O
are	O
to	O
be	O
preferred	O
.	O
</s>
<s>
A	O
proposed	O
rewrite	O
of	O
the	O
part	O
of	O
the	O
standard	O
in	O
this	O
vein	O
was	O
rejected	O
,	O
instead	O
becoming	O
a	O
permission	O
to	O
implement	O
it	O
using	O
expression	B-Application
template	I-Application
.	O
</s>
<s>
A	O
fundamental	O
STL	O
concept	B-Application
is	O
a	O
range''	O
which	O
is	O
a	O
pair	O
of	O
iterators	O
that	O
designate	O
the	O
beginning	O
and	O
end	O
of	O
the	O
computation	O
,	O
and	O
most	O
of	O
the	O
library	O
's	O
algorithmic	O
templates	B-Application
that	O
operate	O
on	O
data	O
structures	O
have	O
interfaces	O
that	O
use	O
ranges	O
.	O
</s>
<s>
It	O
is	O
possible	O
to	O
have	O
bidirectional	O
iterators	O
act	O
like	O
random-access	B-General_Concept
iterators	O
,	O
so	O
moving	O
forward	O
ten	O
steps	O
could	O
be	O
done	O
by	O
simply	O
moving	O
forward	O
a	O
step	O
at	O
a	O
time	O
a	O
total	O
of	O
ten	O
times	O
.	O
</s>
<s>
However	O
,	O
having	O
distinct	O
random-access	B-General_Concept
iterators	O
offers	O
efficiency	O
advantages	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
vector	O
would	O
have	O
a	O
random-access	B-General_Concept
iterator	O
,	O
but	O
a	O
list	O
only	O
a	O
bidirectional	O
iterator	O
.	O
</s>
<s>
For	O
example	O
,	O
an	O
algorithm	B-Language
to	O
reverse	O
a	O
sequence	O
can	O
be	O
implemented	O
using	O
bidirectional	O
iterators	O
,	O
and	O
then	O
the	O
same	O
implementation	O
can	O
be	O
used	O
on	O
lists	O
,	O
vectors	O
and	O
deques	B-Application
.	O
</s>
<s>
User-created	O
containers	B-Application
only	O
have	O
to	O
provide	O
an	O
iterator	O
that	O
implements	O
one	O
of	O
the	O
five	O
standard	O
iterator	O
interfaces	O
,	O
and	O
all	O
the	O
algorithms	O
provided	O
in	O
the	O
STL	O
can	O
be	O
used	O
on	O
the	O
container	B-Application
.	O
</s>
<s>
For	O
example	O
,	O
performing	O
a	O
search	O
on	O
an	O
associative	B-Application
container	I-Application
such	O
as	O
a	O
map	B-Language
or	O
set	O
can	O
be	O
much	O
slower	O
using	O
iterators	O
than	O
by	O
calling	O
member	O
functions	B-Language
offered	O
by	O
the	O
container	B-Application
itself	O
.	O
</s>
<s>
This	O
is	O
because	O
an	O
associative	B-Application
container	I-Application
's	O
methods	O
can	O
take	O
advantage	O
of	O
knowledge	O
of	O
the	O
internal	O
structure	O
,	O
which	O
is	O
opaque	O
to	O
algorithms	O
using	O
iterators	O
.	O
</s>
<s>
A	O
large	O
number	O
of	O
algorithms	O
to	O
perform	O
activities	O
such	O
as	O
searching	O
and	O
sorting	O
are	O
provided	O
in	O
the	O
STL	O
,	O
each	O
implemented	O
to	O
require	O
a	O
certain	O
level	O
of	O
iterator	O
(	O
and	O
therefore	O
will	O
work	O
on	O
any	O
container	B-Application
that	O
provides	O
an	O
interface	O
by	O
iterators	O
)	O
.	O
</s>
<s>
Apart	O
from	O
these	O
,	O
algorithms	O
are	O
provided	O
for	O
making	O
heap	B-Application
from	O
a	O
range	O
of	O
elements	O
,	O
generating	O
lexicographically	O
ordered	O
permutations	O
of	O
a	O
range	O
of	O
elements	O
,	O
merge	O
sorted	O
ranges	O
and	O
perform	O
union	O
,	O
intersection	O
,	O
difference	O
of	O
sorted	O
ranges	O
.	O
</s>
<s>
The	O
STL	O
includes	O
classes	B-Application
that	O
overload	B-Language
the	O
function	O
call	O
operator	O
(	O
)	O
.	O
</s>
<s>
Instances	O
of	O
such	O
classes	B-Application
are	O
called	O
functors	B-Language
or	O
function	B-Language
objects	I-Language
.	O
</s>
<s>
Functors	B-Language
allow	O
the	O
behavior	O
of	O
the	O
associated	O
function	O
to	O
be	O
parameterized	O
(	O
e.g.	O
</s>
<s>
through	O
arguments	O
passed	O
to	O
the	O
functor	B-Language
's	O
constructor	O
)	O
and	O
can	O
be	O
used	O
to	O
keep	O
associated	O
per-functor	O
state	O
information	O
along	O
with	O
the	O
function	O
.	O
</s>
<s>
Since	O
both	O
functors	B-Language
and	O
function	O
pointers	O
can	O
be	O
invoked	O
using	O
the	O
syntax	O
of	O
a	O
function	O
call	O
,	O
they	O
are	O
interchangeable	O
as	O
arguments	O
to	O
templates	B-Application
when	O
the	O
corresponding	O
parameter	O
only	O
appears	O
in	O
function	O
call	O
contexts	O
.	O
</s>
<s>
A	O
particularly	O
common	O
type	O
of	O
functor	B-Language
is	O
the	O
predicate	B-Algorithm
.	O
</s>
<s>
For	O
example	O
,	O
algorithms	O
like	O
take	O
a	O
unary	O
predicate	B-Algorithm
that	O
operates	O
on	O
the	O
elements	O
of	O
a	O
sequence	O
.	O
</s>
<s>
Algorithms	O
like	O
sort	O
,	O
partial_sort	O
,	O
nth_element	O
and	O
all	O
sorted	O
containers	B-Application
use	O
a	O
binary	O
predicate	B-Algorithm
that	O
must	O
provide	O
a	O
strict	O
weak	O
ordering	O
,	O
that	O
is	O
,	O
it	O
must	O
behave	O
like	O
a	O
membership	O
test	O
on	O
a	O
transitive	O
,	O
non-reflexive	O
and	O
asymmetric	O
binary	O
relation	O
.	O
</s>
<s>
If	O
none	O
is	O
supplied	O
,	O
these	O
algorithms	O
and	O
containers	B-Application
use	O
by	O
default	O
,	O
which	O
in	O
turn	O
calls	O
the	O
less-than-operator	O
<	O
.	O
</s>
<s>
The	O
Quality	O
of	O
Implementation	O
(	O
QoI	O
)	O
of	O
the	O
C++	B-Language
compiler	B-Language
has	O
a	O
large	O
impact	O
on	O
usability	O
of	O
the	O
STL	O
(	O
and	O
templated	O
code	O
in	O
general	O
)	O
:	O
</s>
<s>
Error	O
messages	O
involving	O
templates	B-Application
tend	O
to	O
be	O
very	O
long	O
and	O
difficult	O
to	O
decipher	O
.	O
</s>
<s>
This	O
problem	O
has	O
been	O
considered	O
so	O
severe	O
that	O
a	O
number	O
of	O
tools	O
have	O
been	O
written	O
that	O
simplify	O
and	O
prettyprint	B-Application
STL-related	O
error	O
messages	O
to	O
make	O
them	O
more	O
comprehensible	O
.	O
</s>
<s>
Careless	O
use	O
of	O
templates	B-Application
can	O
lead	O
to	O
code	O
bloat	O
.	O
</s>
<s>
using	O
void*	O
containers	B-Application
internally	O
and	O
other	O
"	O
diet	O
template	B-Application
"	O
techniques	O
)	O
and	O
improving	O
compilers	B-Language
 '	O
optimization	O
techniques	O
.	O
</s>
<s>
However	O
,	O
this	O
symptom	O
is	O
similar	O
to	O
naively	O
manually	O
copying	O
a	O
set	O
of	O
functions	B-Language
to	O
work	O
with	O
a	O
different	O
type	O
,	O
in	O
that	O
both	O
can	O
be	O
avoided	O
with	O
care	O
and	O
good	O
technique	O
.	O
</s>
<s>
Template	B-Application
instantiation	O
can	O
increase	O
compilation	B-Language
time	O
and	O
memory	O
usage	O
,	O
in	O
exchange	O
for	O
typically	O
reducing	O
runtime	O
decision-making	O
(	O
e.g.	O
</s>
<s>
via	O
virtual	O
functions	B-Language
)	O
.	O
</s>
<s>
Until	O
the	O
compiler	B-Language
technology	O
improves	O
enough	O
,	O
this	O
problem	O
can	O
be	O
only	O
partially	O
eliminated	O
by	O
careful	O
coding	O
,	O
avoiding	O
certain	O
idioms	O
,	O
and	O
simply	O
not	O
using	O
templates	B-Application
where	O
they	O
are	O
not	O
appropriate	O
or	O
where	O
compile-time	O
performance	O
is	O
prioritized	O
.	O
</s>
<s>
Initialization	O
of	O
STL	O
containers	B-Application
with	O
constants	O
within	O
the	O
source	O
code	O
is	O
not	O
as	O
easy	O
as	O
data	O
structures	O
inherited	O
from	O
C	B-Language
(	O
addressed	O
in	O
C++11	B-Language
with	O
initializer	O
lists	O
)	O
.	O
</s>
<s>
STL	O
containers	B-Application
are	O
not	O
intended	O
to	O
be	O
used	O
as	O
base	O
classes	B-Application
(	O
their	O
destructors	O
are	O
deliberately	O
non-virtual	O
)	O
;	O
deriving	O
from	O
a	O
container	B-Application
is	O
a	O
common	O
mistake	O
.	O
</s>
<s>
The	O
concept	B-Application
of	O
iterators	O
as	O
implemented	O
by	O
the	O
STL	O
can	O
be	O
difficult	O
to	O
understand	O
at	O
first	O
:	O
for	O
example	O
,	O
if	O
a	O
value	O
pointed	O
to	O
by	O
the	O
iterator	O
is	O
deleted	O
,	O
the	O
iterator	O
itself	O
is	O
then	O
no	O
longer	O
valid	O
.	O
</s>
<s>
A	O
similar	O
problem	O
exists	O
in	O
other	O
languages	O
,	O
for	O
example	O
Java	B-Language
.	O
</s>
<s>
Certain	O
iteration	O
patterns	O
do	O
not	O
map	B-Language
to	O
the	O
STL	O
iterator	O
model	O
.	O
</s>
<s>
For	O
example	O
,	O
callback	O
enumeration	O
APIs	O
cannot	O
be	O
made	O
to	O
fit	O
the	O
STL	O
model	O
without	O
the	O
use	O
of	O
coroutines	B-Architecture
,	O
which	O
are	O
platform-dependent	O
or	O
unavailable	O
,	O
and	O
will	O
be	O
outside	O
the	O
C++	B-Language
standard	O
until	O
C++20	O
.	O
</s>
<s>
Compiler	B-Language
compliance	O
does	O
not	O
guarantee	O
that	O
Allocator	B-Application
objects	O
,	O
used	O
for	O
memory	O
management	O
for	O
containers	B-Application
,	O
will	O
work	O
with	O
state-dependent	O
behavior	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
portable	O
library	O
ca	O
n't	O
define	O
an	O
allocator	B-Application
type	O
that	O
will	O
pull	O
memory	O
from	O
different	O
pools	O
using	O
different	O
allocator	B-Application
objects	O
of	O
that	O
type	O
.	O
</s>
<s>
(	O
Meyers	O
,	O
p.50	O
)	O
(	O
addressed	O
in	O
C++11	B-Language
)	O
.	O
</s>
<s>
The	O
set	O
of	O
algorithms	O
is	O
not	O
complete	O
:	O
for	O
example	O
,	O
the	O
algorithm	B-Language
was	O
left	O
out	O
,	O
though	O
it	O
has	O
been	O
added	O
in	O
C++11	B-Language
.	I-Language
</s>
<s>
The	O
which	O
ships	O
with	O
Visual	O
C++	B-Language
is	O
a	O
licensed	O
derivative	O
of	O
Dinkum	O
's	O
STL	O
.	O
</s>
