- 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::listfor linked lists- Every stdlib container provices
beginandendfor iterating list<T>::iterator(the return value ofbeginandend) can be used to refer to positionsinsertanderasetake as input such iterators
- Standard dictionary
- Implemented as balanced binary tree
[key]returns value or default value (0forint)findorinsertcan be used to avoid entering default values into the dictionary
maprequires a comparison function,unordered_mapdoes 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::hashcan 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