<s>
In	O
computing	O
,	O
sequence	B-Language
containers	I-Language
refer	O
to	O
a	O
group	O
of	O
container	B-Application
class	O
templates	B-Application
in	O
the	O
standard	B-Language
library	I-Language
of	O
the	O
C++	B-Language
programming	I-Language
language	I-Language
that	O
implement	O
storage	O
of	O
data	O
elements	O
.	O
</s>
<s>
Being	O
templates	B-Application
,	O
they	O
can	O
be	O
used	O
to	O
store	O
arbitrary	O
elements	O
,	O
such	O
as	O
integers	O
or	O
custom	O
classes	O
.	O
</s>
<s>
One	O
common	O
property	O
of	O
all	O
sequential	O
containers	B-Application
is	O
that	O
the	O
elements	O
can	O
be	O
accessed	O
sequentially	O
.	O
</s>
<s>
Like	O
all	O
other	O
standard	B-Language
library	I-Language
components	O
,	O
they	O
reside	O
in	O
namespace	O
std	O
.	O
</s>
<s>
The	O
following	O
containers	B-Application
are	O
defined	O
in	O
the	O
current	O
revision	O
of	O
the	O
C++	B-Language
standard	O
:	O
array	B-Data_Structure
,	O
vector	O
,	O
list	O
,	O
forward_list	O
,	O
deque	B-Application
.	O
</s>
<s>
Each	O
of	O
these	O
containers	B-Application
implements	O
different	O
algorithms	O
for	O
data	O
storage	O
,	O
which	O
means	O
that	O
they	O
have	O
different	O
speed	O
guarantees	O
for	O
different	O
operations	O
:	O
</s>
<s>
array	B-Data_Structure
implements	O
a	O
compile-time	O
non-resizable	O
array	B-Data_Structure
.	O
</s>
<s>
vector	O
implements	O
an	O
array	B-Data_Structure
with	O
fast	O
random	B-General_Concept
access	I-General_Concept
and	O
an	O
ability	O
to	O
automatically	O
resize	O
when	O
appending	O
elements	O
.	O
</s>
<s>
deque	B-Application
implements	O
a	O
double-ended	B-Application
queue	I-Application
with	O
comparatively	O
fast	O
random	B-General_Concept
access	I-General_Concept
.	O
</s>
<s>
list	O
implements	O
a	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
.	O
</s>
<s>
Since	O
each	O
of	O
the	O
containers	B-Application
needs	O
to	O
be	O
able	O
to	O
copy	O
its	O
elements	O
in	O
order	O
to	O
function	O
properly	O
,	O
the	O
type	O
of	O
the	O
elements	O
must	O
fulfill	O
CopyConstructible	O
and	O
Assignable	O
requirements	O
.	O
</s>
<s>
For	O
a	O
given	O
container	B-Application
,	O
all	O
elements	O
must	O
belong	O
to	O
the	O
same	O
type	O
.	O
</s>
<s>
For	O
instance	O
,	O
one	O
cannot	O
store	O
data	O
in	O
the	O
form	O
of	O
both	O
char	O
and	O
int	O
within	O
the	O
same	O
container	B-Application
instance	O
.	O
</s>
<s>
Originally	O
,	O
only	O
vector	O
,	O
list	O
and	O
deque	B-Application
were	O
defined	O
.	O
</s>
<s>
Until	O
the	O
standardization	O
of	O
the	O
C++	B-Language
language	I-Language
in	O
1998	O
,	O
they	O
were	O
part	O
of	O
the	O
Standard	B-Application
Template	I-Application
Library	I-Application
(	O
STL	O
)	O
,	O
published	O
by	O
SGI	O
.	O
</s>
<s>
Alexander	O
Stepanov	O
,	O
the	O
primary	O
designer	O
of	O
the	O
STL	O
,	O
bemoans	O
the	O
choice	O
of	O
the	O
name	O
vector	O
,	O
saying	O
that	O
it	O
comes	O
from	O
the	O
older	O
programming	O
languages	O
Scheme	B-Language
and	O
Lisp	B-Language
but	O
is	O
inconsistent	O
with	O
the	O
mathematical	O
meaning	O
of	O
the	O
term	O
.	O
</s>
<s>
The	O
array	B-Data_Structure
container	B-Application
at	O
first	O
appeared	O
in	O
several	O
books	O
under	O
various	O
names	O
.	O
</s>
<s>
Later	O
it	O
was	O
incorporated	O
into	O
a	O
Boost	B-Language
library	I-Language
,	O
and	O
was	O
proposed	O
for	O
inclusion	O
in	O
the	O
standard	O
C++	B-Language
library	O
.	O
</s>
<s>
The	O
motivation	O
for	O
inclusion	O
of	O
array	B-Data_Structure
was	O
that	O
it	O
solves	O
two	O
problems	O
of	O
the	O
C-style	O
array	B-Data_Structure
:	O
the	O
lack	O
of	O
an	O
STL-like	O
interface	O
,	O
and	O
an	O
inability	O
to	O
be	O
copied	O
like	O
any	O
other	O
object	O
.	O
</s>
<s>
It	O
firstly	O
appeared	O
in	O
C++	B-Language
TR1	I-Language
and	O
later	O
was	O
incorporated	O
into	O
C++11	B-Language
.	I-Language
</s>
<s>
The	O
forward_list	O
container	B-Application
was	O
added	O
to	O
C++11	B-Language
as	O
a	O
space-efficient	O
alternative	O
to	O
list	O
when	O
reverse	O
iteration	O
is	O
not	O
needed	O
.	O
</s>
<s>
array	B-Data_Structure
,	O
vector	O
and	O
deque	B-Application
all	O
support	O
fast	O
random	B-General_Concept
access	I-General_Concept
to	O
the	O
elements	O
.	O
</s>
<s>
array	B-Data_Structure
does	O
not	O
support	O
element	O
insertion	O
or	O
removal	O
.	O
</s>
<s>
Also	O
,	O
if	O
the	O
allocated	O
storage	O
in	O
the	O
vector	O
is	O
too	O
small	O
to	O
insert	O
elements	O
,	O
a	O
new	O
array	B-Data_Structure
is	O
allocated	O
,	O
all	O
elements	O
are	O
copied	O
or	O
moved	O
to	O
the	O
new	O
array	B-Data_Structure
,	O
and	O
the	O
old	O
array	B-Data_Structure
is	O
freed	O
.	O
</s>
<s>
deque	B-Application
,	O
list	O
and	O
forward_list	O
all	O
support	O
fast	O
insertion	O
or	O
removal	O
of	O
elements	O
anywhere	O
in	O
the	O
container	B-Application
.	O
</s>
<s>
list	O
and	O
forward_list	O
preserves	O
validity	O
of	O
iterators	O
on	O
such	O
operation	O
,	O
whereas	O
deque	B-Application
invalidates	O
all	O
of	O
them	O
.	O
</s>
<s>
Like	O
all	O
dynamic	B-Data_Structure
array	I-Data_Structure
implementations	O
,	O
vectors	O
have	O
low	O
memory	O
usage	O
and	O
good	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
and	O
data	B-General_Concept
cache	I-General_Concept
utilization	O
.	O
</s>
<s>
Unlike	O
other	O
STL	O
containers	B-Application
,	O
such	O
as	O
deques	B-Application
and	O
lists	O
,	O
vectors	O
allow	O
the	O
user	O
to	O
denote	O
an	O
initial	O
capacity	O
for	O
the	O
container	B-Application
.	O
</s>
<s>
Vectors	O
allow	O
random	B-General_Concept
access	I-General_Concept
;	O
that	O
is	O
,	O
an	O
element	O
of	O
a	O
vector	O
may	O
be	O
referenced	O
in	O
the	O
same	O
manner	O
as	O
elements	O
of	O
arrays	O
(	O
by	O
array	B-Data_Structure
indices	O
)	O
.	O
</s>
<s>
Linked-lists	O
and	O
sets	O
,	O
on	O
the	O
other	O
hand	O
,	O
do	O
not	O
support	O
random	B-General_Concept
access	I-General_Concept
or	O
pointer	O
arithmetic	O
.	O
</s>
<s>
The	O
vector	B-Data_Structure
data	I-Data_Structure
structure	I-Data_Structure
is	O
able	O
to	O
quickly	O
and	O
easily	O
allocate	O
the	O
necessary	O
memory	O
needed	O
for	O
specific	O
data	O
storage	O
,	O
and	O
it	O
is	O
able	O
to	O
do	O
so	O
in	O
amortized	B-General_Concept
constant	I-General_Concept
time	I-General_Concept
.	O
</s>
<s>
A	O
typical	O
vector	O
implementation	O
consists	O
,	O
internally	O
,	O
of	O
a	O
pointer	O
to	O
a	O
dynamically	B-Application
allocated	I-Application
array	B-Data_Structure
,	O
and	O
possibly	O
data	O
members	O
holding	O
the	O
capacity	O
and	O
size	O
of	O
the	O
vector	O
.	O
</s>
<s>
The	O
size	O
of	O
the	O
vector	O
refers	O
to	O
the	O
actual	O
number	O
of	O
elements	O
,	O
while	O
the	O
capacity	O
refers	O
to	O
the	O
size	O
of	O
the	O
internal	O
array	B-Data_Structure
.	O
</s>
<s>
Because	O
the	O
addresses	B-General_Concept
of	O
the	O
elements	O
change	O
during	O
this	O
process	O
,	O
any	O
references	O
or	O
iterators	O
to	O
elements	O
in	O
the	O
vector	O
become	O
invalidated	O
.	O
</s>
<s>
Using	O
an	O
invalidated	O
reference	O
causes	O
undefined	B-Language
behaviour	I-Language
.	O
</s>
<s>
The	O
vector	O
maintains	O
a	O
certain	O
order	O
of	O
its	O
elements	O
,	O
so	O
that	O
when	O
a	O
new	O
element	O
is	O
inserted	O
at	O
the	O
beginning	O
or	O
in	O
the	O
middle	O
of	O
the	O
vector	O
,	O
subsequent	O
elements	O
are	O
moved	O
backwards	O
in	O
terms	O
of	O
their	O
assignment	O
operator	O
or	O
copy	B-Language
constructor	I-Language
.	O
</s>
<s>
C++	B-Language
vectors	O
do	O
not	O
support	O
in-place	O
reallocation	O
of	O
memory	O
,	O
by	O
design	O
;	O
i.e.	O
,	O
upon	O
reallocation	O
of	O
a	O
vector	O
,	O
the	O
memory	O
it	O
held	O
will	O
always	O
be	O
copied	O
to	O
a	O
new	O
block	O
of	O
memory	O
using	O
its	O
elements	O
 '	O
copy	B-Language
constructor	I-Language
,	O
and	O
then	O
released	O
.	O
</s>
<s>
This	O
is	O
inefficient	O
for	O
cases	O
where	O
the	O
vector	O
holds	O
plain	B-Language
old	I-Language
data	I-Language
and	O
additional	O
contiguous	O
space	O
beyond	O
the	O
held	O
block	O
of	O
memory	O
is	O
available	O
for	O
allocation	O
.	O
</s>
<s>
The	O
Standard	B-Language
Library	I-Language
defines	O
a	O
specialization	O
of	O
the	O
vector	O
template	B-Application
for	O
bool	O
.	O
</s>
<s>
vectorxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
does	O
not	O
meet	O
the	O
requirements	O
for	O
a	O
C++	B-Language
Standard	I-Language
Library	I-Language
container	B-Application
.	O
</s>
<s>
For	O
instance	O
,	O
a	O
containerxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1::reference	O
,	O
which	O
is	O
a	O
proxy	O
class	O
convertible	O
to	O
bool	O
.	O
</s>
<s>
There	O
is	O
a	O
general	O
consensus	O
among	O
the	O
C++	B-Language
Standard	O
Committee	O
and	O
the	O
Library	O
Working	O
Group	O
that	O
vectorxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
should	O
be	O
deprecated	O
and	O
subsequently	O
removed	O
from	O
the	O
standard	B-Language
library	I-Language
,	O
while	O
the	O
functionality	O
will	O
be	O
reintroduced	O
under	O
a	O
different	O
name	O
.	O
</s>
<s>
The	O
list	O
data	O
structure	O
implements	O
a	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
.	O
</s>
<s>
Lists	O
do	O
not	O
have	O
random-access	B-General_Concept
ability	O
like	O
vectors	O
(	O
operation	O
)	O
.	O
</s>
<s>
Each	O
node	O
takes	O
up	O
sizeof(type )	O
+	O
2	O
*	O
sizeof( type*	O
)	O
.	O
</s>
<s>
deque	B-Application
is	O
a	O
container	B-Application
class	O
template	B-Application
that	O
implements	O
a	O
double-ended	B-Application
queue	I-Application
.	O
</s>
<s>
It	O
provides	O
similar	O
computational	O
complexity	O
to	O
vector	O
for	O
most	O
operations	O
,	O
with	O
the	O
notable	O
exception	O
that	O
it	O
provides	O
amortized	B-General_Concept
constant-time	I-General_Concept
insertion	O
and	O
removal	O
from	O
both	O
ends	O
of	O
the	O
element	O
sequence	O
.	O
</s>
<s>
Unlike	O
vector	O
,	O
deque	B-Application
uses	O
discontiguous	O
blocks	O
of	O
memory	O
,	O
and	O
provides	O
no	O
means	O
to	O
control	O
the	O
capacity	O
of	O
the	O
container	B-Application
and	O
the	O
moment	O
of	O
reallocation	O
of	O
memory	O
.	O
</s>
<s>
Like	O
vector	O
,	O
deque	B-Application
offers	O
support	O
for	O
random-access	B-General_Concept
iterators	O
,	O
and	O
insertion	O
and	O
removal	O
of	O
elements	O
invalidates	O
all	O
iterators	O
to	O
the	O
deque	B-Application
.	O
</s>
<s>
array	B-Data_Structure
implements	O
a	O
non-resizable	O
array	B-Data_Structure
.	O
</s>
<s>
The	O
size	O
is	O
determined	O
at	O
compile-time	O
by	O
a	O
template	B-Application
parameter	O
.	O
</s>
<s>
By	O
design	O
,	O
the	O
container	B-Application
does	O
not	O
support	O
allocators	B-Application
because	O
it	O
's	O
basically	O
a	O
C-style	O
array	B-Data_Structure
wrapper	O
.	O
</s>
<s>
The	O
containers	B-Application
are	O
defined	O
in	O
headers	O
named	O
after	O
the	O
names	O
of	O
the	O
containers	B-Application
,	O
e.g.	O
</s>
<s>
All	O
containers	B-Application
satisfy	O
the	O
requirements	O
of	O
the	O
concept	B-Application
,	O
which	O
means	O
they	O
have	O
begin( )	O
,	O
end( )	O
,	O
size( )	O
,	O
max_size( )	O
,	O
empty( )	O
,	O
and	O
swap( )	O
methods	O
.	O
</s>
<s>
Functions	O
array( C++11	O
)	O
vector	O
deque	B-Application
list	O
forward_list( C++11	O
)	O
Description	O
Basics	O
rowspan	O
=3	O
(	O
constructor	O
)	O
(	O
constructor	O
)	O
(	O
constructor	O
)	O
(	O
constructor	O
)	O
Constructs	O
the	O
container	B-Application
from	O
variety	O
of	O
sources	O
(	O
destructor	O
)	O
(	O
destructor	O
)	O
(	O
destructor	O
)	O
(	O
destructor	O
)	O
Destructs	O
the	O
container	B-Application
and	O
the	O
contained	O
elements	O
operator	O
=	O
operator	O
=	O
operator	O
=	O
operator	O
=	O
Assigns	O
values	O
to	O
the	O
container	B-Application
rowspan	O
=	O
2	O
assign	O
assign	O
assign	O
assign	O
Assigns	O
values	O
to	O
the	O
container	B-Application
Allocators	B-Application
get_allocator	O
get_allocator	O
get_allocator	O
get_allocator	O
Returns	O
the	O
allocator	B-Application
used	O
to	O
allocate	O
memory	O
for	O
the	O
elements	O
Elementaccess	O
at	O
at	O
at	O
rowspan	O
=	O
2	O
rowspan	O
=	O
2	O
Accesses	O
specified	O
element	O
with	O
bounds	O
checking	O
.	O
</s>
<s>
front	O
front	O
front	O
front	O
front	O
Accesses	O
the	O
first	O
element	O
back	O
back	O
back	O
back	O
rowspan	O
=	O
2	O
Accesses	O
the	O
last	O
element	O
data	O
data	O
Accesses	O
the	O
underlying	O
array	B-Data_Structure
Iterators	O
begincbegin	O
begincbegin	O
begincbegin	O
begincbegin	O
begincbegin	O
Returns	O
an	O
iterator	O
to	O
the	O
beginning	O
of	O
the	O
container	B-Application
endcend	O
endcend	O
endcend	O
endcend	O
endcend	O
Returns	O
an	O
iterator	O
to	O
the	O
end	O
of	O
the	O
container	B-Application
rbegincrbegin	O
rbegincrbegin	O
rbegincrbegin	O
rbegincrbegin	O
rowspan	O
=	O
2	O
Returns	O
a	O
reverse	O
iterator	O
to	O
the	O
reverse	O
beginning	O
of	O
the	O
container	B-Application
rendcrend	O
rendcrend	O
rendcrend	O
rendcrend	O
Returns	O
a	O
reverse	O
iterator	O
to	O
the	O
reverse	O
end	O
of	O
the	O
container	B-Application
Capacity	O
empty	O
empty	O
empty	O
empty	O
empty	O
Checks	O
whether	O
the	O
container	B-Application
is	O
empty	O
size	O
size	O
size	O
size	O
Returns	O
the	O
number	O
of	O
elements	O
in	O
the	O
container	B-Application
.	O
</s>
<s>
max_size	O
max_size	O
max_size	O
max_size	O
max_size	O
Returns	O
the	O
maximum	O
possible	O
number	O
of	O
elements	O
in	O
the	O
container	B-Application
.	O
</s>
<s>
There	O
are	O
other	O
operations	O
that	O
are	O
available	O
as	O
a	O
part	O
of	O
the	O
list	O
class	O
and	O
there	O
are	O
algorithms	O
that	O
are	O
part	O
of	O
the	O
C++	B-Application
STL	I-Application
(	O
Algorithm	O
(	O
C++	B-Language
)	O
)	O
that	O
can	O
be	O
used	O
with	O
the	O
list	O
and	O
forward_list	O
class	O
:	O
</s>
<s>
The	O
following	O
example	O
demonstrates	O
various	O
techniques	O
involving	O
a	O
vector	O
and	O
C++	B-Language
Standard	I-Language
Library	I-Language
algorithms	O
,	O
notably	O
shuffling	B-Application
,	O
sorting	B-Algorithm
,	O
finding	O
the	O
largest	O
element	O
,	O
and	O
erasing	O
from	O
a	O
vector	O
using	O
the	O
erase-remove	B-Language
idiom	I-Language
.	O
</s>
