- vector: self-growing array
- Pointers are user-defined types
- Elements are copied into vectors
- Vectors do not throw out-of-range errors on
[]
while they do onat
- Sometimes compilers offer range checking for vectors
std::list
for linked lists- Every stdlib container provices
begin
andend
for iterating list<T>::iterator
(the return value ofbegin
andend
) can be used to refer to positionsinsert
anderase
take as input such iterators
- Standard dictionary
- Implemented as balanced binary tree
[key]
returns value or default value (0
forint
)find
orinsert
can be used to avoid entering default values into the dictionary
map
requires a comparison function,unordered_map
does not- Works using hashing
- The standard library provides hashing for most types
hash<T>(expr)
- To implement your own hash function, overwrite
operator()
. Alternatively,std::hash
can be overloaded
- There are also containers for single linked lists (
forward_list
), sets (set
), multimaps (multimap
) - Many containers accept
push_back
- Design advice:
()
initializer for sizes,{}
initializer for lists of elements