Namespaces
Variants
Views
Actions

Containers library

From cppreference.com
< cpp
Revision as of 22:56, 5 June 2013 by P12 (Talk | contribs)

The Containers library is a generic collection of class templates and algorithms that allow programmers to easily implement common data structures like queues, lists and stacks. There are three classes of containers -- sequence containers, associative containers, and unordered associative containers -- each of which is designed to support a different set of operations.

The container manages the storage space that is allocated for its elements and provides member functions to access them, either directly or through iterators (objects with similar properties to pointers).

Most containers have at least several member functions in common, and share functionalities. Which container is the best for the particular application depends not only on the offered functionality, but also on its efficiency for different workloads.

Contents

Sequence containers

Sequence containers implement data structures which can be accessed sequentially.

(since C++11)
static contiguous array
(class template) [edit]
(array TS)
fixed-size contiguous array
(class template) [edit]
dynamic contiguous array
(class template) [edit]
double-ended queue
(class template) [edit]
(since C++11)
singly-linked list
(class template) [edit]
doubly-linked list
(class template) [edit]

Associative containers

Associative containers implement sorted data structures that can be quickly searched (O(log n) complexity).

collection of unique keys, sorted by keys
(class template) [edit]
collection of key-value pairs, sorted by keys, keys are unique
(class template) [edit]
collection of keys, sorted by keys
(class template) [edit]
collection of key-value pairs, sorted by keys
(class template) [edit]

Unordered associative containers

Unordered associative containers implement unsorted (hashed) data structures that can be quickly searched (O(1) amortized, O(n) worst-case complexity).

(since C++11)
collection of unique keys, hashed by keys
(class template) [edit]
(since C++11)
collection of key-value pairs, hashed by keys, keys are unique
(class template) [edit]
(since C++11)
collection of keys, hashed by keys
(class template) [edit]
(since C++11)
collection of key-value pairs, hashed by keys
(class template) [edit]

Container adaptors

Container adaptors provide a different interface for sequential containers.

adapts a container to provide stack (LIFO data structure)
(class template) [edit]
adapts a container to provide queue (FIFO data structure)
(class template) [edit]
adapts a container to provide priority queue
(class template) [edit]

Member function table

- functions present in C++03
- functions present since C++11
Sequence containers Associative containers Unordered associative containers Container adaptors
Header <array> <vector> <deque> <forward_list> <list> <set> <map> <unordered_set> <unordered_map> <stack> <queue>
Container
array
vector
deque
forward_list
list
set
multiset
map
multimap
unordered_set
unordered_multiset
unordered_map
unordered_multimap
stack
queue
priority_queue
(constructor)
(implicit)
vector
deque
forward_list
list
set
multiset
map
multimap
unordered_set
unordered_multiset
unordered_map
unordered_multimap
stack
queue
priority_queue
(destructor)
(implicit)
~vector
~deque
~forward_list
~list
~set
~multiset
~map
~multimap
~unordered_set
~unordered_multiset
~unordered_map
~unordered_multimap
~stack
~queue
~priority_queue
operator=
(implicit)
operator=
operator=
operator=
operator=
operator=
operator=
operator=
operator=
operator=
operator=
operator=
operator=
operator=
operator=
operator=
assign
assign
assign
assign
assign
Iterators
begin
cbegin
begin
cbegin
begin
cbegin
begin
cbegin
begin
cbegin
begin
cbegin
begin
cbegin
begin
cbegin
begin
cbegin
begin
cbegin
begin
cbegin
begin
cbegin
begin
cbegin
begin
cbegin
end
cend
end
cend
end
cend
end
cend
end
cend
end
cend
end
cend
end
cend
end
cend
end
cend
end
cend
end
cend
end
cend
end
cend
rbegin
crbegin
rbegin
crbegin
rbegin
crbegin
rbegin
crbegin
rbegin
crbegin
rbegin
crbegin
rbegin
crbegin
rbegin
crbegin
rbegin
crbegin
rend
crend
rend
crend
rend
crend
rend
crend
rend
crend
rend
crend
rend
crend
rend
crend
rend
crend
Element
access
at
at
at
at
at
at
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
front
front
front
front
front
front
front
top
back
back
back
back
back
top
back
Capacity
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
size
size
size
size
size
size
size
size
size
size
size
size
size
size
size
size
max_size
max_size
max_size
max_size
max_size
max_size
max_size
max_size
max_size
max_size
max_size
max_size
max_size
max_size
resize
resize
resize
resize
resize
capacity
capacity
reserve
reserve
reserve
reserve
reserve
reserve
shrink_to_fit
shrink_to_fit
shrink_to_fit
Modifiers
clear
clear
clear
clear
clear
clear
clear
clear
clear
clear
clear
clear
clear
insert
insert
insert
insert_after
insert
insert
insert
insert
insert
insert
insert
insert
insert
emplace
emplace
emplace
emplace_after
emplace
emplace
emplace
emplace
emplace
emplace
emplace
emplace
emplace
emplace_hint
emplace_hint
emplace_hint
emplace_hint
emplace_hint
emplace_hint
emplace_hint
emplace_hint
emplace_hint
erase
erase
erase
erase_after
erase
erase
erase
erase
erase
erase
erase
erase
erase
push_front
push_front
push_front
push_front
emplace_front
emplace_front
emplace_front
emplace_front
pop_front
pop_front
pop_front
pop_front
pop
push_back
push_back
push_back
push_back
push
push
push
emplace_back
emplace_back
emplace_back
emplace_back
emplace
emplace
emplace
pop_back
pop_back
pop_back
pop_back
pop
pop
swap
swap
swap
swap
swap
swap
swap
swap
swap
swap
swap
swap
swap
swap
swap
swap
swap
List operations
merge
merge
merge
splice
splice_after
splice
remove
remove
remove
remove_if
remove_if
remove_if
reverse
reverse
reverse
unique
unique
unique
sort
sort
sort
Lookup
count
count
count
count
count
count
count
count
count
find
find
find
find
find
find
find
find
find
lower_bound
lower_bound
lower_bound
lower_bound
lower_bound
upper_bound
upper_bound
upper_bound
upper_bound
upper_bound
equal_range
equal_range
equal_range
equal_range
equal_range
equal_range
equal_range
equal_range
equal_range
Observers
key_comp
key_comp
key_comp
key_comp
key_comp
value_comp
value_comp
value_comp
value_comp
value_comp
hash_function
hash_function
hash_function
hash_function
hash_function
key_eq
key_eq
key_eq
key_eq
key_eq
Allocator
get_allocator
get_allocator
get_allocator
get_allocator
get_allocator
get_allocator
get_allocator
get_allocator
get_allocator
get_allocator
get_allocator
get_allocator
get_allocator
Container
array
vector
deque
forward_list
list
set
multiset
map
multimap
unordered_set
unordered_multiset
unordered_map
unordered_multimap
stack
queue
priority_queue
Sequence containers Associative containers Unordered associative containers Container adaptors

(A PDF version of this table is available at File:container-library-overview-2012-12-27.pdf.)