You were redirected to cplusplus.com/stl || See search results for: "stl"
library

Containers

Standard Containers
A container is a holder object that stores a collection of other objects (its elements). They are implemented as class templates, which allows a great flexibility in the types supported as elements.

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

Containers replicate structures very commonly used in programming: dynamic arrays (vector), queues (queue), stacks (stack), heaps (priority_queue), linked lists (list), trees (set), associative arrays (map)...

Many containers have several member functions in common, and share functionalities. The decision of which type of container to use for a specific need does not generally depend only on the functionality offered by the container, but also on the efficiency of some of its members (complexity). This is especially true for sequence containers, which offer different trade-offs in complexity between inserting/removing elements and accessing them.

stack, queue and priority_queue are implemented as container adaptors. Container adaptors are not full container classes, but classes that provide a specific interface relying on an object of one of the container classes (such as deque or list) to handle the elements. The underlying container is encapsulated in such a way that its elements are accessed by the members of the container adaptor independently of the underlying container class used.

Container class templates

Sequence containers:

Container adaptors:

Associative containers:

Unordered associative containers:

Other:
Two class templates share certain properties with containers, and are sometimes classified with them: bitset and valarray.

Member map

This is a comparison chart with the different member functions present on each of the different containers:

Legend:
C++98Available since C++98
C++11New in C++11

Sequence containers

Headers<array><vector><deque><forward_list><list>
Membersarrayvectordequeforward_listlist
constructorimplicitvectordequeforward_listlist
destructorimplicit~vector~deque~forward_list~list
operator=implicitoperator=operator=operator=operator=
iteratorsbeginbeginbeginbeginbegin
before_begin
begin
endendendendendend
rbeginrbeginrbeginrbegin rbegin
rendrendrendrend rend
const iteratorscbegincbegincbegincbegincbegin
cbefore_begin
cbegin
cendcendcendcendcendcend
crbegincrbegincrbegincrbegin crbegin
crendcrendcrendcrend crend
capacitysizesizesizesize size
max_sizemax_sizemax_sizemax_sizemax_sizemax_size
emptyemptyemptyemptyemptyempty
resize resizeresizeresizeresize
shrink_to_fit shrink_to_fitshrink_to_fit
capacity capacity
reserve reserve
element accessfrontfrontfrontfrontfrontfront
backbackbackback back
operator[]operator[]operator[]operator[]
atatatat
modifiersassign assignassignassignassign
emplace emplaceemplaceemplace_afteremplace
insert insertinsertinsert_afterinsert
erase eraseeraseerase_aftererase
emplace_back emplace_backemplace_back emplace_back
push_back push_backpush_back push_back
pop_back pop_backpop_back pop_back
emplace_front emplace_frontemplace_frontemplace_front
push_front push_frontpush_frontpush_front
pop_front pop_frontpop_frontpop_front
clear clearclearclearclear
swapswapswapswapswapswap
list operationssplice splice_aftersplice
remove removeremove
remove_if remove_ifremove_if
unique uniqueunique
merge mergemerge
sort sortsort
reverse reversereverse
observersget_allocator get_allocatorget_allocatorget_allocatorget_allocator
datadatadata

Associative containers

Headers<set><map><unordered_set><unordered_map>
Memberssetmultisetmapmultimapunordered_setunordered_multisetunordered_mapunordered_multimap
constructorsetmultisetmapmultimapunordered_setunordered_multisetunordered_mapunordered_multimap
destructor~set~multiset~map~multimap~unordered_set~unordered_multiset~unordered_map~unordered_multimap
assignmentoperator=operator=operator=operator=operator=operator=operator=operator=
iteratorsbeginbeginbeginbeginbeginbeginbeginbeginbegin
endendendendendendendendend
rbeginrbeginrbeginrbeginrbegin
rendrendrendrendrend
const iteratorscbegincbegincbegincbegincbegincbegincbegincbegincbegin
cendcendcendcendcendcendcendcendcend
crbegincrbegincrbegincrbegincrbegin
crendcrendcrendcrendcrend
capacitysizesizesizesizesizesizesizesizesize
max_sizemax_sizemax_sizemax_sizemax_sizemax_sizemax_sizemax_sizemax_size
emptyemptyemptyemptyemptyemptyemptyemptyempty
reserve reservereservereservereserve
element accessat at at
operator[] operator[] operator[]
modifiersemplaceemplaceemplaceemplaceemplaceemplaceemplaceemplaceemplace
emplace_hintemplace_hintemplace_hintemplace_hintemplace_hintemplace_hintemplace_hintemplace_hintemplace_hint
insertinsertinsertinsertinsertinsertinsertinsertinsert
eraseeraseeraseeraseeraseeraseeraseeraseerase
clearclearclearclearclearclearclearclearclear
swapswapswapswapswapswapswapswapswap
operationscountcountcountcountcountcountcountcountcount
findfindfindfindfindfindfindfindfind
equal_rangeequal_rangeequal_rangeequal_rangeequal_rangeequal_rangeequal_rangeequal_rangeequal_range
lower_boundlower_boundlower_boundlower_boundlower_bound
upper_boundupper_boundupper_boundupper_boundupper_bound
observersget_allocatorget_allocatorget_allocatorget_allocatorget_allocatorget_allocatorget_allocatorget_allocatorget_allocator
key_compkey_compkey_compkey_compkey_comp
value_compvalue_compvalue_compvalue_compvalue_comp
key_eq key_eqkey_eqkey_eqkey_eq
hash_function hash_functionhash_functionhash_functionhash_function
bucketsbucket bucketbucketbucketbucket
bucket_count bucket_countbucket_countbucket_countbucket_count
bucket_size bucket_sizebucket_sizebucket_sizebucket_size
max_bucket_count max_bucket_countmax_bucket_countmax_bucket_countmax_bucket_count
hash policyrehash rehashrehashrehashrehash
load_factor load_factorload_factorload_factorload_factor
max_load_factor max_load_factormax_load_factormax_load_factormax_load_factor